Skip to content

fix: Clear Scope._transaction when span is unset - #7773

Draft
thegunslingers wants to merge 1 commit into
getsentry:masterfrom
thegunslingers:master
Draft

thegunslingers wants to merge 1 commit into
getsentry:masterfrom
thegunslingers:master

Conversation

@thegunslingers

@thegunslingers thegunslingers commented Sep 29, 2026 •

Copy link
Copy Markdown

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 Transaction is assigned to Scope.span, the setter copies transaction.name into Scope._transaction. On transaction exit, span is restored to None, but _transaction was left set. Later events (e.g. via LoggingIntegration) then inherited that stale name through _apply_transaction_name_to_event — commonly showing up as responses {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_unset covering Transaction → child Span → None. Lint: uv run ruff check --fix / uv run ruff format.

Issues

Reminders

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

No deployments
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.

Scope._transaction not cleared when span is set to None

1 participant