fix(tracing): Skip child span creation in streaming path when no current span (web frameworks)#6810
fix(tracing): Skip child span creation in streaming path when no current span (web frameworks)#6810sentrivana wants to merge 3 commits into
Conversation
…ent span (web frameworks) When span streaming is enabled and there is no current span, web framework integrations should not create new root segments for child-span operations. This adds a guard check using `sentry_sdk.traces.get_current_span()` before creating spans in the streaming path. Affected integrations: starlette, starlite, litestar, graphene, strawberry, aiohttp. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…uards The outgoing http.client span from the test fixture is now suppressed when there is no active span, reducing span counts in tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| # The outgoing http.client span is suppressed because there is no active | ||
| # span when the test client makes the request. | ||
| assert len(items) == 0 | ||
|
|
||
|
|
||
| @pytest.mark.asyncio |
There was a problem hiding this comment.
Outgoing trace header propagation dropped when no active span in streaming mode
This test previously verified that the sentry-trace header was propagated on outgoing requests, but now asserts zero spans and no header assertions; the underlying early-return in aiohttp.py (lines 356-358) skips adding trace headers entirely when there is no current span, which can break distributed trace continuation for outgoing HTTP calls.
Evidence
aiohttp.py:356-358returns early (trace_config_ctx.span = None; return) before the block that attachessentry-trace/baggageheaders whenget_current_span() is None.- The revised test drops the prior assertions on
resp.request_info.headers['sentry-trace']and now only checkslen(items) == 0, removing coverage for outgoing trace-header propagation. - Distributed tracing normally propagates trace context from the propagation context even absent an active span, so suppressing the header can sever the trace chain.
Identified by Warden code-review · DYK-FKT
Codecov Results 📊✅ 91785 passed | ⏭️ 6302 skipped | Total: 98087 | Pass Rate: 93.58% | Execution Time: 317m 41s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 55.17%. Project has 2456 uncovered lines. Files with missing lines (4)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 89.79% 89.75% -0.04%
==========================================
Files 193 193 —
Lines 23929 23958 +29
Branches 8286 8310 +24
==========================================
+ Hits 21485 21502 +17
- Misses 2444 2456 +12
- Partials 1361 1371 +10Generated by Codecov Action |
Summary
sentry_sdk.traces.get_current_span() is Noneguard before creating spans in the streaming pathTest plan
🤖 Generated with Claude Code