fix(tracing): Skip child span creation in streaming path when no current span (databases)#6808
Open
sentrivana wants to merge 4 commits into
Open
fix(tracing): Skip child span creation in streaming path when no current span (databases)#6808sentrivana wants to merge 4 commits into
sentrivana wants to merge 4 commits into
Conversation
…ent span (databases) When span streaming is enabled and there is no current span, database 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: aiomysql, asyncpg, clickhouse_driver, pymongo, redis. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Codecov Results 📊✅ 91744 passed | ⏭️ 6302 skipped | Total: 98046 | Pass Rate: 93.57% | Execution Time: 316m 15s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 93.48%. Project has 2433 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.82% 89.83% +0.01%
==========================================
Files 193 193 —
Lines 23905 23920 +15
Branches 8262 8280 +18
==========================================
+ Hits 21471 21487 +16
- Misses 2434 2433 -1
- Partials 1351 1354 +3Generated by Codecov Action |
The early return for the no-current-span guard was skipping breadcrumb creation in the asyncpg and aiomysql connect wrappers. Move breadcrumb addition before the guard so breadcrumbs are always recorded. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Same issue as asyncpg/aiomysql — the no-current-span guard was skipping breadcrumb creation. Move breadcrumb and data computation before the guard. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ericapisani
approved these changes
Jul 14, 2026
Member
There was a problem hiding this comment.
With the new change below where we may return early, span_attributes may be created unnecessarily.
As a cleanup, could consider moving this below the if sentry_sdk.traces.get_current_span() is None: block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sentry_sdk.traces.get_current_span() is Noneguard before creating spans in the streaming pathPart of #6819