fix: flaky test_handler by isolating trace context in log handler tests#114491
Merged
fix: flaky test_handler by isolating trace context in log handler tests#114491
test_handler by isolating trace context in log handler tests#114491Conversation
JoshFerge
approved these changes
Apr 30, 2026
cleptric
pushed a commit
that referenced
this pull request
May 5, 2026
…ests (#114491) fixes flakes like https://github.com/getsentry/sentry/actions/runs/25186909243/job/73846655451?pr=114485 this has been verified on my `shuffle-tests-v5` branch as well `get_trace_id()` reads `sentry_sdk.get_current_scope().span`. When a preceding test leaves an active span on the shared thread-local scope, `test_emit` and `test_gke_emit` receive a real trace ID instead of `None` and fail their assertions. alternative solution doesn't work: `sentry_sdk.isolation_scope()` alone doesn't help — it shallow-copies the current scope and carries the active span over. The new `reset_trace_context()` helper wraps `isolation_scope()` and explicitly zeroes `scope.span`, giving the enclosed call a clean slate. Applied surgically at the two call sites that assert `trace_id=None`.
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 flakes like https://github.com/getsentry/sentry/actions/runs/25186909243/job/73846655451?pr=114485
this has been verified on my
shuffle-tests-v5branch as wellget_trace_id()readssentry_sdk.get_current_scope().span. When a preceding test leaves an active span on the shared thread-local scope,test_emitandtest_gke_emitreceive a real trace ID instead ofNoneand fail their assertions.alternative solution doesn't work:
sentry_sdk.isolation_scope()alone doesn't help — it shallow-copies the current scope and carries the active span over. The newreset_trace_context()helper wrapsisolation_scope()and explicitly zeroesscope.span, giving the enclosed call a clean slate. Applied surgically at the two call sites that asserttrace_id=None.