fix(tracing): make no-op starts idempotent - #4501
Closed
sylvesterkaczmarek wants to merge 3 commits into
Closed
Conversation
sylvesterkaczmarek
marked this pull request as ready for review
August 17, 2026 21:35
Member
|
I confirmed that explicitly starting the same no-op trace or span twice overwrites its saved context token and leaves the no-op object current after one finish. However, the documented lifecycle is either context-manager use or one balanced manual start()/finish() pair, and I could not find an SDK path that starts the same no-op object twice. Please provide a concrete supported scenario that reaches this repeated-start sequence and shows the resulting context leak affecting later work. Without such a scenario, this currently protects only an unsupported lifecycle composition, so I would close this PR for now. |
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
NoOpTrace.start()calls idempotentNoOpSpan.start()calls idempotentmark_as_current=Truestart from overwriting the original ContextVar tokenNormal trace and span implementations already ignore repeated starts. The no-op implementations did not, so a second start replaced the saved token with one whose previous value was the no-op object itself. A single
finish(reset_current=True)then restored that object as current instead of clearing it, leaking tracing context when tracing is disabled.Test plan
tests/test_noop_tracing_start_idempotent.pyIssue number
N/A