Skip to content

Clear scope transaction name when span is cleared - #7846

Open
Hashim1999164 wants to merge 1 commit into
getsentry:masterfrom
Hashim1999164:fix/scope-clear-transaction-on-span-none
Open

Hashim1999164 wants to merge 1 commit into
getsentry:masterfrom
Hashim1999164:fix/scope-clear-transaction-on-span-none

Conversation

@Hashim1999164

Copy link
Copy Markdown

Summary

When a transaction context exits it restores scope.span to None but scope._transaction kept the finished transaction name. Unrelated errors captured later could still pick up that stale name.

This clears scope._transaction and scope._transaction_info when span is set to None. Child spans still restore a live parent span so the name stays while a transaction is active.

Fixes #7774

Test plan

Ran pytest tests/tracing/test_misc.py::test_start_transaction_updates_scope_name_source with addopts disabled locally.

Restoring scope.span to None after a transaction ends left a stale
_transaction value on the scope, so later errors could inherit the old
transaction name. Clear it when span is set to None.

Fixes getsentry#7774
@Hashim1999164
Hashim1999164 requested a review from a team as a code owner October 3, 2026 22:16

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f282e26. Configure here.

Comment thread sentry_sdk/scope.py
if span is None:
self._transaction = None
self._transaction_info = {}
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orphan spans clear transaction names

Medium Severity

Setting span to None now always clears _transaction and _transaction_info. A name stored by set_transaction_name with no active transaction is then dropped when any later span exits and restores None, so later errors lose that name.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f282e26. Configure here.

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