Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,10 @@ def span(self) -> "Optional[Span]":
@span.setter
def span(self, span: "Optional[Span]") -> None:
self._span = span
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.

# XXX: this differs from the implementation in JS, there Scope.setSpan
# does not set Scope._transactionName.
if isinstance(span, Transaction):
Expand Down
3 changes: 3 additions & 0 deletions tests/tracing/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ def test_start_transaction_updates_scope_name_source(sentry_init):
assert scope._transaction == "foobar"
assert scope._transaction_info == {"source": "route"}

assert scope._transaction is None
assert scope._transaction_info == {}


@pytest.mark.parametrize("sampled", (True, None))
def test_transaction_dropped_debug_not_started(sentry_init, sampled):
Expand Down