fix(sentry): isolate sentry runtime context per request - #1089
Conversation
|
Warning Review limit reached
Next review available in: 51 minutes Limit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?Wait for the limit to reset, then comment An organization admin can change what happens after included review limits in Billing. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84d47127dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // when the tracing listener already started one, and is ended via defer once the | ||
| // request coroutine exits. | ||
| SentrySdk::startContext(); | ||
| defer(fn () => SentrySdk::endContext()); |
There was a problem hiding this comment.
Avoid scheduling a second context teardown
When both request handling and request tracing are enabled (the defaults), ConfigProvider invokes the tracing listener first and this base listener second. Although this listener's startContext() is a no-op for the already-active context, it still registers another LIFO endContext() defer; that defer runs before the tracing listener's transaction-finishing defer, removing and flushing the request context before the transaction is finished. Consequently, transaction telemetry is produced after the request's final flush and may be lost by transports that require flushing. Only the listener that creates the context should schedule its teardown, or context ownership should be centralized.
Useful? React with 👍 / 👎.
问题
HTTP/RPC 请求协程由引擎(Hyperf\Engine\Coroutine::create)创建,不走 Hyperf\Coroutine\Coroutine::create,Aspect\CoroutineAspect 不会为其 startContext,导致并发请求共享全局 Hub/Scope(面包屑/tag/user 跨请求串扰、scope 栈错位、请求级日志/指标无法按请求 flush)。
修改
测试
php /tmp/pest-runner-r4.php --group=sentry → 47 passed(80 assertions);CI/主 checkout 直接 vendor/bin/pest --group=sentry
验证
php-cs-fixer 0 修复;git diff --check 通过