fix: Clear Scope._transaction when span is unset - #7773
Draft
thegunslingers wants to merge 1 commit into
Draft
thegunslingers wants to merge 1 commit into
thegunslingers wants to merge 1 commit into
Conversation
When scope.span is set to None after a transaction ends, clear the stale _transaction name. Child Span assignments keep the parent name.
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.
When scope.span is set to None (e.g. after a transaction ends), Scope._transaction was not being cleared, leaving stale transaction names on the scope. Add an elif branch in the span setter to set _transaction to None when span is None.
Child Span assignments (which happen during Span.enter) do not clear _transaction, preserving the parent Transaction's name.
Description
When a
Transactionis assigned toScope.span, the setter copiestransaction.nameintoScope._transaction. On transaction exit,spanis restored toNone, but_transactionwas left set. Later events (e.g. via LoggingIntegration) then inherited that stale name through_apply_transaction_name_to_event— commonly showing up asresponses {model}from OpenAIIntegration on unrelated errors.The setter clears _transaction only when span is None. Clearing on every non-Transaction would be wrong: child spans set scope.span = self while a transaction is still live.
Added
test_transaction_name_cleared_when_span_unsetcovering Transaction → child Span → None. Lint:uv run ruff check --fix/uv run ruff format.Issues
Reminders
uv run ruff.feat:,fix:,ref:,meta:)