Clear scope transaction name when span is cleared - #7846
Hashim1999164 wants to merge 1 commit into
Conversation
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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| if span is None: | ||
| self._transaction = None | ||
| self._transaction_info = {} | ||
| return |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit f282e26. Configure here.


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.