Skip to content

fix(tracing): Skip child span creation in streaming path when no current span (databases)#6808

Open
sentrivana wants to merge 4 commits into
masterfrom
ivana/streaming-child-spans-databases
Open

fix(tracing): Skip child span creation in streaming path when no current span (databases)#6808
sentrivana wants to merge 4 commits into
masterfrom
ivana/streaming-child-spans-databases

Conversation

@sentrivana

@sentrivana sentrivana commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When span streaming is enabled and there is no current span, database integrations should not create new root segments for child-span operations
  • Adds a sentry_sdk.traces.get_current_span() is None guard before creating spans in the streaming path
  • Affected integrations: aiomysql, asyncpg, clickhouse_driver, pymongo, redis

Part of #6819

…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>
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

91744 passed | ⏭️ 6302 skipped | Total: 98046 | Pass Rate: 93.57% | Execution Time: 316m 15s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -41
Passed Tests 📉 -41
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 93.48%. Project has 2433 uncovered lines.
✅ Project coverage is 89.83%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
sentry_sdk/integrations/asyncpg.py 89.47% ⚠️ 2 Missing and 1 partials
sentry_sdk/integrations/aiomysql.py 90.91% ⚠️ 1 Missing and 1 partials
sentry_sdk/integrations/clickhouse_driver.py 100.00% ⚠️ 2 partials
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        +3

Generated by Codecov Action

sentrivana and others added 2 commits July 13, 2026 16:20
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>
@sentrivana sentrivana marked this pull request as ready for review July 13, 2026 14:59
@sentrivana sentrivana requested a review from a team as a code owner July 13, 2026 14:59

@ericapisani ericapisani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

Comment thread sentry_sdk/integrations/aiomysql.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ericapisani ericapisani enabled auto-merge (squash) July 14, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants