Skip to content

ref: Flush trace bucket when segment span finishes - #7170

Open
alexander-alderman-webb wants to merge 22 commits into
masterfrom
webb/flush-segment-buckets
Open

ref: Flush trace bucket when segment span finishes#7170
alexander-alderman-webb wants to merge 22 commits into
masterfrom
webb/flush-segment-buckets

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

Mark the corresponding bucket as pending in the span buffer when a segment span is added.

This aims to keep memory pressure low. Segment spans typically finish after their children. There may be multiple segments in a trace, and flushing more frequently leads to more outbound network requests in these cases.

Adapt span batcher tests by adding an outer segment in most tests. As a result, the various flush conditions are still exercised as the assertions run before the segment span has finished (finishing the segment span otherwise flushes the buffer as well).

The tests that exercise multiple buckets are changed to use traces.new_trace() in combination with a segment span that's left open

Without changes to the sentry_init fixture, tests fail on free-threading. This is because the background flusher collects pending items before sentry_sdk.flush() can synchronously flush all everything. The background flush is asynchronous and creates a race conditions.

Issues

Reminders

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

105016 passed | ⏭️ 6677 skipped | Total: 111693 | Pass Rate: 94.02% | Execution Time: 367m 48s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +6292
Passed Tests 📈 +6094
Failed Tests
Skipped Tests 📈 +198

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2484 uncovered lines.
✅ Project coverage is 90.15%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    90.15%    90.15%        —%
==========================================
  Files          193       193         —
  Lines        25215     25215         —
  Branches      9224      9224         —
==========================================
+ Hits         22730     22731        +1
- Misses        2485      2484        -1
- Partials      1433      1431        -2

Generated by Codecov Action

@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review August 11, 2026 14:46
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner August 11, 2026 14:46
Comment thread sentry_sdk/_span_batcher.py Outdated
Comment thread sentry_sdk/_span_batcher.py Outdated
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as draft August 11, 2026 15:08
Base automatically changed from webb/batcher/remove-global-limits to master August 12, 2026 11:34
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review August 12, 2026 11:45

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 54334a3. Configure here.

Comment thread tests/conftest.py
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