Repository navigation
fix(tracing): Flush pending span buckets in segment finish order - #8261
Draft
sentry-junior[bot] wants to merge 1 commit into
Draft
sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
SpanBatcher._pending_flush was a set, so when the flusher woke after several segments had finished, it sent their traces in hash order. Use an insertion-ordered dict instead. Fixes #8027
Contributor
Coverage Results 📊✅ 139239 passed | ⏭️ 7861 skipped | Total: 147100 | Pass Rate: 94.66% | Execution Time: 441m 8s All tests are passing successfully. ❌ Patch coverage is 66.67% (2 of 3 changed executable lines covered; target 80%). Changed files with executable lines (1)
Coverage diff@@ Coverage Diff @@
## master #8261 +/-##
==========================================
+ Coverage 90.21% 90.24% +0.03%
==========================================
Files 203 203 —
Tracked lines 27335 27335 —
Branches 10246 10246 —
==========================================
+ Hits 24660 24667 +7
+ Misses 2675 2668 -7
Partials 1559 1559 —Generated by Coverage Action |
This branch has not been deployed
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.
Fixes #8027
Repro: getsentry/repro#61
Cause
In streaming mode, every finished segment adds its trace ID to
SpanBatcher._pending_flush, and that attribute was aset. When the flusher thread wakes after two or more segments have finished,list(self._pending_flush)sends the traces in hash order, not the order the segments finished. That is whytest_cache_spans_item_size[True]andtest_cache_spans_decorator[True]flake on busy CI runners: request 2's spans sometimes arrive first.Fix
Make
_pending_flushan insertion-ordereddict[str, None], so pending traces are sent in the order they became ready. No other behavior changes.Validation
test_pending_traces_flush_in_segment_finish_orderholds the flusher back until 10 segments have finished. It fails onmaster(trace order scrambled) and passes with the fix (3 of 3 runs).tests/tracingonpy3.14-commonpasses.ruff check,ruff format --check, andmypy sentry_sdkpass.sentry-sdk==2.72.0it exits 1 (164 and 154 of 300 iterations out of order with--delay-flusher, 92 of 200 with natural timing). With this branch installed editable it exits 0 (0 out of order in all three runs).tests/integrations/django/test_cache_module.py, because it needs Postgres, which the sandbox doesn't have.via automation
evt_986cce2def3acf1f0c69ed3fe2462a31· Run IDdispatch_b69ae416eae39d09bca4bd53df50133b.--
View Session [Sentry]