How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.68.1
Steps to Reproduce
Start a top-level transaction via OpenAIIntegration (or any path that sets scope.span to a Transaction).
Nest work that restores scope.span to None when the transaction finishes (normal with / start_transaction exit).
Later, on the same Scope (same thread, or a worker that got the Scope via copy_context()), capture an unrelated error with no active transaction.
Expected Result
After scope.span = None, scope._transaction is cleared so later errors are not attributed to the finished transaction (culprit / transaction name should not stick).
sentry-sdk 2.68.1 (deps: certifi, urllib3>=1.26.11)
Actual Result
Scope.span’s setter sets _transaction when given a Transaction, but does not clear _transaction when span is None. Stale _transaction remains; unrelated errors inherit the old transaction name (e.g. responses gpt-5.6-luna) as culprit even when the stack has nothing to do with that LLM call.
Clearing on every non-Transaction would be wrong: child spans set scope.span = self while a transaction is still live. The fix clears _transaction only when span is None.
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.68.1
Steps to Reproduce
Start a top-level transaction via OpenAIIntegration (or any path that sets scope.span to a Transaction).
Nest work that restores scope.span to None when the transaction finishes (normal with / start_transaction exit).
Later, on the same Scope (same thread, or a worker that got the Scope via copy_context()), capture an unrelated error with no active transaction.
Expected Result
After scope.span = None, scope._transaction is cleared so later errors are not attributed to the finished transaction (culprit / transaction name should not stick).
sentry-sdk 2.68.1 (deps: certifi, urllib3>=1.26.11)
Actual Result
Scope.span’s setter sets _transaction when given a Transaction, but does not clear _transaction when span is None. Stale _transaction remains; unrelated errors inherit the old transaction name (e.g. responses gpt-5.6-luna) as culprit even when the stack has nothing to do with that LLM call.
Clearing on every non-Transaction would be wrong: child spans set scope.span = self while a transaction is still live. The fix clears _transaction only when span is None.