Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Dec 24, 2025

Summary

  • Adjusts the event flush order in Integration::flushEvents()
  • Moves SentrySdk::getCurrentHub()->getClient()?->flush() to execute after Logs and TraceMetrics flush
  • Ensures proper event ordering during shutdown sequence

Test plan

  • Unit tests pass
  • Code style checks pass

Summary by CodeRabbit

发布说明

  • 优化
    • 调整事件刷新顺序:先提交日志与追踪指标,再触发客户端刷新,以提升处理一致性与可靠性。
  • 行为变更
    • 将 IntegrationRegistry 的公开单例引用移除并以注释形式保留(伴随明显警告),暂不启用此单例以避免潜在问题。

✏️ Tip: You can customize this high-level summary in your review settings.

Move SentrySdk client flush to after Logs and TraceMetrics flush
to ensure proper event ordering during shutdown sequence.
Copilot AI review requested due to automatic review settings December 24, 2025 01:08
@coderabbitai
Copy link

coderabbitai bot commented Dec 24, 2025

Walkthrough

调整 Sentry 事件刷新顺序:将对 Sentry 客户端的 flush 调用从先行移动到在 Logs 与 TraceMetrics flush 之后;在单例切面文件中移除并注释了对 IntegrationRegistry 的单例注册/匹配引用(附带警告注释),未改动对外签名或其它逻辑。

Changes

内聚 / 文件 变更摘要
事件刷新顺序
src/sentry/src/Integration.php
Integration::flushEvents 中调整调用顺序:先调用 Logs::getInstance()->flush()TraceMetrics::getInstance()->flush(),随后(若客户端非 null)调用 Sentry 客户端的 flush();未改动异常处理或公开签名。
单例切面注释化 IntegrationRegistry
src/sentry/src/Aspect/SingletonAspect.php
从公开单例列表与 match 分支中移除了 \Sentry\Integration\IntegrationRegistry::class . '::getInstance' 的可用路径,并新增了以注释形式保留的引用及显著警告注释(“不要启用”);未引入新的公共 API 或其它行为改变。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 我在键盘间轻轻跳,
日志先行,指标随到,
最后 Sentry 守好城堡,
注释一行,谨慎把关,
嗅着变更的薄荷味 ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确反映了主要变更:在 Integration::flushEvents 中调整事件刷新顺序,将 Sentry 客户端刷新移至日志和跟踪指标刷新之后。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/sentry-adjust-event-flush-order

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 40dc81f and 0a7d65e.

📒 Files selected for processing (1)
  • src/sentry/src/Aspect/SingletonAspect.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/sentry/src/Aspect/SingletonAspect.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.33)

At least one path must be specified to analyse.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the event flush order in the Sentry Integration's flushEvents() method to ensure proper event ordering during shutdown sequences. The change moves the Sentry client flush to execute after the Logs and TraceMetrics flush operations.

Key changes:

  • Reorders flush operations in Integration::flushEvents() to call SentrySdk::getCurrentHub()->getClient()?->flush() last instead of first

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/sentry/src/Aspect/SingletonAspect.php (1)

57-58: 建议:将 // !!! 注释替换为有意义的说明。

当前的 // !!! 注释不够清晰,无法说明为什么 IntegrationRegistry 需要与其他单例类(如 HubAdapterLogsTraceMetrics)区别对待。其他单例使用 Context::getOrSet() 进行协程安全的缓存,而 IntegrationRegistry 直接透传到原始方法。

建议添加解释性注释,说明为什么跳过单例缓存(例如与事件刷新顺序相关的原因)。

🔎 建议的改进
-            // !!!
-            \Sentry\Integration\IntegrationRegistry::class => $proceedingJoinPoint->process(),
+            // IntegrationRegistry 不需要协程上下文缓存,直接使用原始单例以确保事件刷新顺序正确
+            \Sentry\Integration\IntegrationRegistry::class => $proceedingJoinPoint->process(),
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1516604 and 40dc81f.

📒 Files selected for processing (1)
  • src/sentry/src/Aspect/SingletonAspect.php
🧰 Additional context used
📓 Path-based instructions (4)
**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.php: All PHP files must include declare(strict_types=1) at the top
Use PSR-12 coding standards for PHP code formatting
Use 4-space indentation with short array syntax in PHP code
Use .php-cs-fixer.php configuration for PHP code formatting

All PHP files must include a strict_types declaration at the top

**/*.php: Follow project PHP coding standard enforced by php-cs-fixer with PSR-12 style, 4-space indentation, and short array syntax
Maintain type coverage by updating or adding tests when public APIs change; ensure composer test:types stays green before pushing

Files:

  • src/sentry/src/Aspect/SingletonAspect.php
src/**/src/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use namespace pattern FriendsOfHyperf\{ComponentName} for all component classes

Files:

  • src/sentry/src/Aspect/SingletonAspect.php
src/*/src/**/*.php

📄 CodeRabbit inference engine (CLAUDE.md)

src/*/src/**/*.php: Namespace convention for components must follow FriendsOfHyperf{ComponentName}
All code must be coroutine-safe and avoid global state without proper context management, blocking I/O operations, and non-coroutine-safe third-party libraries without wrappers
Use Hyperf's Context API for request-scoped data instead of global state
Follows PSR-12 coding standards and use PHP-CS-Fixer for automatic formatting
Use PHPStan at maximum level for static analysis
Ensure component namespace doesn't conflict with existing Hyperf components or other packages in the ecosystem
Integrate deeply with Hyperf's Dependency Injection container for service registration
Leverage Hyperf's AOP (Aspect-Oriented Programming) for cross-cutting concerns via aspects defined in ConfigProvider
Use Hyperf's Event System to register listeners for framework events in components
All code must support coroutine-based concurrency using Swoole/Swow compatibility

Files:

  • src/sentry/src/Aspect/SingletonAspect.php
src/**/*.php

📄 CodeRabbit inference engine (AGENTS.md)

Each component lives in its own subdirectory with PSR-4 namespaces matching FriendsOfHyperf\*

Files:

  • src/sentry/src/Aspect/SingletonAspect.php
🧠 Learnings (1)
📚 Learning: 2025-12-12T05:33:43.947Z
Learnt from: CR
Repo: friendsofhyperf/components PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-12T05:33:43.947Z
Learning: Applies to src/*/src/**/*.php : Leverage Hyperf's AOP (Aspect-Oriented Programming) for cross-cutting concerns via aspects defined in ConfigProvider

Applied to files:

  • src/sentry/src/Aspect/SingletonAspect.php
🧬 Code graph analysis (1)
src/sentry/src/Aspect/SingletonAspect.php (3)
src/sentry/src/Aspect/CoroutineAspect.php (1)
  • process (40-49)
src/sentry/src/Metrics/Listener/OnWorkerStart.php (1)
  • process (50-124)
src/sentry/src/Aspect/RedisAspect.php (1)
  • process (37-62)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.3
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
🔇 Additional comments (1)
src/sentry/src/Aspect/SingletonAspect.php (1)

21-27: 确认:IntegrationRegistry 是否仍需保留在 $classes 数组中?

IntegrationRegistry::class 仍然在第 24 行的 $classes 数组中注册,但第 58 行的处理逻辑与 default 分支(第 69 行)完全相同,都是直接调用 $proceedingJoinPoint->process()

如果 IntegrationRegistry 不需要任何特殊的 AOP 处理,可以考虑将其从 $classes 数组中移除,这样代码会更简洁。如果保留是为了文档目的或未来可能的修改,建议添加注释说明。

Also applies to: 47-70

@huangdijia huangdijia merged commit ba4f3df into main Dec 24, 2025
23 checks passed
@huangdijia huangdijia deleted the fix/sentry-adjust-event-flush-order branch December 24, 2025 01:40
huangdijia added a commit that referenced this pull request Dec 24, 2025
* fix(sentry): adjust event flush order in Integration

Move SentrySdk client flush to after Logs and TraceMetrics flush
to ensure proper event ordering during shutdown sequence.

* fix(sentry): adjust event flush order for IntegrationRegistry in SingletonAspect

* fix(sentry): disable IntegrationRegistry instance creation to prevent unexpected issues

---------

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants