-
-
Notifications
You must be signed in to change notification settings - Fork 27
refactor(sentry): optimize hub management and listener priorities #936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Simplify SentrySdk::setCurrentHub() by removing unnecessary tap usage - Add explicit priorities to event listeners for deterministic execution order - Optimize EventHandleListener by removing redundant hub context management - Improve Tracer initialization to use existing hub instead of creating new ones - Clear breadcrumbs on new transaction scope to prevent cross-request pollution
Walkthrough调整 Sentry SDK 与监听器相关实现: Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App
participant Listener as EventHandleListener
participant Sdk as SentrySdk
participant Context as Hyperf\Context
Note over Listener: 监听器按优先级被触发
App->>Listener: onEvent(...)
activate Listener
Note right of Listener: 不再调用 setupSentrySdk()
Listener->>Sdk: SentrySdk::getCurrentHub() 或直接使用 Hub 接口
Sdk->>Context: get/set Current Hub (setCurrentHub 直接返回 Context::set)
Context-->>Listener: Hub 实例或 null
Listener-->>App: 处理完成
deactivate Listener
sequenceDiagram
autonumber
actor App
participant Tracer
participant Sdk as SentrySdk
participant Hub as CurrentHub
participant Scope
App->>Tracer: startTransaction(...)
activate Tracer
Tracer->>Sdk: getCurrentHub()
Sdk-->>Tracer: Hub
Tracer->>Hub: pushScope()
Hub->>Scope: new Scope
Tracer->>Scope: configureScope(clear breadcrumbs)
Tracer->>Hub: startTransaction(context)
Note right of Tracer: defer popScope() at method end
Hub-->>Tracer: Transaction
Tracer-->>App: return Transaction
deactivate Tracer
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Path-based instructions (2){src,tests}/**/*.php📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
src/*/**📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
⏰ 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). (12)
🔇 Additional comments (1)
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.28)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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/sentry/class_map/SentrySdk.php(1 hunks)src/sentry/src/ConfigProvider.php(1 hunks)src/sentry/src/Listener/EventHandleListener.php(7 hunks)src/sentry/src/Tracing/Tracer.php(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/*/src/**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use the namespace pattern FriendsOfHyperf{ComponentName} in all component PHP source files
Files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Listener/EventHandleListener.phpsrc/sentry/src/Tracing/Tracer.php
src/*/src/ConfigProvider.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Each component must include a ConfigProvider class (FriendsOfHyperf{ComponentName}\ConfigProvider) with __invoke() returning dependencies, commands, listeners, and annotations scan paths
Files:
src/sentry/src/ConfigProvider.php
{src,tests}/**/*.php
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Adhere to PSR-12 coding standards across PHP code
Files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Listener/EventHandleListener.phpsrc/sentry/src/Tracing/Tracer.phpsrc/sentry/class_map/SentrySdk.php
src/*/**
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
New components must follow the standard component structure under src/{component-name}/ including .gitattributes, .github, LICENSE, README.md, composer.json, and a src/ subdirectory
Files:
src/sentry/src/ConfigProvider.phpsrc/sentry/src/Listener/EventHandleListener.phpsrc/sentry/src/Tracing/Tracer.phpsrc/sentry/class_map/SentrySdk.php
🧠 Learnings (1)
📚 Learning: 2025-09-28T00:20:28.922Z
Learnt from: CR
PR: friendsofhyperf/components#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-28T00:20:28.922Z
Learning: Applies to src/*/src/ConfigProvider.php : Each component must include a ConfigProvider class (FriendsOfHyperf\{ComponentName}\ConfigProvider) with __invoke() returning dependencies, commands, listeners, and annotations scan paths
Applied to files:
src/sentry/src/ConfigProvider.php
🧬 Code graph analysis (2)
src/sentry/src/ConfigProvider.php (3)
src/sentry/src/Listener/EventHandleListener.php (1)
EventHandleListener(44-620)src/sentry/src/Crons/Listener/EventHandleListener.php (1)
EventHandleListener(24-156)src/sentry/src/Tracing/Listener/EventHandleListener.php (1)
EventHandleListener(61-810)
src/sentry/src/Tracing/Tracer.php (2)
src/sentry/class_map/SentrySdk.php (2)
SentrySdk(24-65)getCurrentHub(51-54)src/sentry/src/Integration.php (1)
configureScope(79-88)
⏰ 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). (12)
- GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
- 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.1 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
- 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.3 with Swoole 5.1.7
🔇 Additional comments (1)
src/sentry/src/Listener/EventHandleListener.php (1)
356-357: 确认是否仍需保留 setupSentryCurrentHub 调用
当前在多个生命周期阶段(请求/命令/队列/定时/AMQP/Kafka)均调用此方法,但默认实现为空。未在 Tracer 或其他位置检索到pushScope()与clearBreadcrumbs()的替代逻辑,请手动核实是否已通过其它途径创建新 Scope 并清理 breadcrumbs:
- 若仅保留扩展点,需在方法及调用处添加注释说明目的;
- 若已无必要,建议移除所有此类调用以降噪。
* refactor(sentry): optimize hub management and listener priorities - Simplify SentrySdk::setCurrentHub() by removing unnecessary tap usage - Add explicit priorities to event listeners for deterministic execution order - Optimize EventHandleListener by removing redundant hub context management - Improve Tracer initialization to use existing hub instead of creating new ones - Clear breadcrumbs on new transaction scope to prevent cross-request pollution * 删除未使用的 HttpClient 依赖项 * fix(tracer): use getCurrentHub instead of init for hub management * refactor(listener): 移除未使用的 setupSentryCurrentHub 方法 * feat(sentry): 添加 sentry:test 命令到配置 * fix(tracer): 修复事务范围管理,确保在事务结束时正确弹出范围 * fix(ConfigProvider): 确保 Tracing\EventHandleListener 是第一个处理事件的监听器 * fix(tracer): 使用 getCurrentHub 替代 init 进行 Hub 管理 --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Summary
This PR optimizes Sentry hub management and improves event listener execution order for better performance and reliability.
Key Changes
tapusage for cleaner, more direct hub assignmentgetCurrentHub()) instead of creating new instances for better resource utilizationBenefits
Test Plan
Summary by CodeRabbit
新功能
Bug 修复
重构
配置