-
-
Notifications
You must be signed in to change notification settings - Fork 27
feat(sentry): improve transaction handling in coroutine contexts #922
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
- Use defer functions to ensure proper transaction cleanup in coroutines - Separate transaction handling for coroutine and non-coroutine contexts - Simplify transaction finishing logic by removing try-finally blocks - Apply consistent pattern across command, crontab, AMQP, Kafka, and async queue handlers
Walkthrough在 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Source as Event Source
participant L as EventHandleListener
participant T as Tracing SDK
Source->>L: onEvent(...)
L->>T: startTransaction(ctx)
T-->>L: transaction
Note over L,T: 保存为局部变量;设置 active span
alt Coroutine
Note over L: 使用 defer 注册收尾
L->>L: process handler
alt Error occurs
L->>T: attach exception tags/data
end
Note over L,T: defer 内调用 finish()
else Non-Coroutine
L->>L: try { process handler } finally { finish() }
alt Error occurs
L->>T: attach exception tags/data
end
end
Note right of L: 非采样时尽早返回(短路)
Estimated code review effort🎯 4 (复杂) | ⏱️ ~45–60 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
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 (1)
src/sentry/src/Tracing/Listener/EventHandleListener.php(10 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/sentry/src/Tracing/Listener/EventHandleListener.php (6)
src/sentry/src/Tracing/Tracer.php (1)
startTransaction(38-63)src/sentry/src/Function.php (1)
startTransaction(24-29)src/sentry/src/Tracing/SpanStarter.php (2)
startTransaction(39-44)continueTrace(114-143)src/sentry/class_map/SentrySdk.php (2)
SentrySdk(24-65)getCurrentHub(51-54)src/sentry/src/Switcher.php (1)
isTracingExtraTagEnabled(85-88)src/sentry/src/Util/Carrier.php (4)
getSentryTrace(100-103)getBaggage(105-108)get(120-123)has(115-118)
⏰ 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). (9)
- GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
- GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.2 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 5.1.7
- 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.2 with Swoole 5.1.7
- GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
- Use defer functions to ensure proper transaction cleanup in coroutines - Separate transaction handling for coroutine and non-coroutine contexts - Simplify transaction finishing logic by removing try-finally blocks - Apply consistent pattern across command, crontab, AMQP, Kafka, and async queue handlers Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Summary
Changes Made
This PR improves Sentry transaction handling in the EventHandleListener by:
defer()functions to ensure transactions are properly finished in coroutine contextsfinallyblocks, while coroutine contexts use deferred cleanuptry-finallyblocks and moving transaction data setting outside of these blocksBenefits
Test Plan
Summary by CodeRabbit
Bug Fixes
Refactor