Skip to content

Commit f282e26

Browse files
committed
Clear scope transaction name when span is cleared
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 #7774
1 parent 8afefe8 commit f282e26

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎sentry_sdk/scope.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,10 @@ def span(self) -> "Optional[Span]":
904904
@span.setter
905905
def span(self, span: "Optional[Span]") -> None:
906906
self._span = span
907+
if span is None:
908+
self._transaction = None
909+
self._transaction_info = {}
910+
return
907911
# XXX: this differs from the implementation in JS, there Scope.setSpan
908912
# does not set Scope._transactionName.
909913
if isinstance(span, Transaction):

‎tests/tracing/test_misc.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ def test_start_transaction_updates_scope_name_source(sentry_init):
428428
assert scope._transaction == "foobar"
429429
assert scope._transaction_info == {"source": "route"}
430430

431+
assert scope._transaction is None
432+
assert scope._transaction_info == {}
433+
431434

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

0 commit comments

Comments
 (0)