Repository navigation
fix: clear Scope._transaction when the span is unset - #7851
Closed
intertermux-code wants to merge 2 commits into
Closed
intertermux-code wants to merge 2 commits into
intertermux-code wants to merge 2 commits into
Conversation
The span setter copied a Transaction's name into _transaction but never cleared it, so after a top-level transaction finished (span restored to None) later events on the same scope kept the stale transaction name. The clear only happens on None: a finishing child span restores the transaction itself, so a live transaction's name is preserved. 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 fe91a89. Configure here.
Follow-up to the transaction-clearing change: unsetting the span reset _transaction but left _transaction_info behind, so events captured later on the same scope still received the finished transaction's source via _apply_transaction_info_to_event. Reset it alongside, matching Scope.clear().
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.

Description
Scope.span's setter copies aTransaction's name intoscope._transaction, but nothing ever cleared it: when a top-level transaction finishes,Span.__exit__restoresscope.spanto the previous span (None), and the stale name stayed on the scope. Any event captured later on that scope then inherited the finished transaction's name (e.g. an unrelated error showing up under the wrong transaction name).The fix adds an
elif span is Nonebranch to the setter that resets_transaction. It deliberately does not clear on plain child spans: a finishing child span restores the transaction itself (notNone), so a live transaction's name is preserved — covered by the nested test below.Added:
test_transaction_name_cleared_when_span_unset: Transaction -> child span -> Nonetest_transaction_name_survives_nested_span_exit: nested spans keep the live transaction's name, which is cleared once the transaction itself exitsIssues
Reminders
uv run ruff.feat:,fix:,meta:)