Skip to content

Commit f94c605

Browse files
author
Андрей Сапаров
committed
fix: default Scope._transaction_info of the scope
1 parent ce604f9 commit f94c605

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

sentry_sdk/scope.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def __copy__(self):
227227
rv._name = self._name
228228
rv._fingerprint = self._fingerprint
229229
rv._transaction = self._transaction
230-
rv._transaction_info = dict(self._transaction_info)
230+
rv._transaction_info = copy(self._transaction_info)
231231
rv._user = self._user
232232

233233
rv._tags = dict(self._tags)
@@ -664,7 +664,7 @@ def clear(self):
664664
self._level = None # type: Optional[LogLevelStr]
665665
self._fingerprint = None # type: Optional[List[str]]
666666
self._transaction = None # type: Optional[str]
667-
self._transaction_info = {} # type: MutableMapping[str, str]
667+
self._transaction_info = None # type: Optional[MutableMapping[str, str]]
668668
self._user = None # type: Optional[Dict[str, Any]]
669669

670670
self._tags = {} # type: Dict[str, Any]
@@ -772,7 +772,10 @@ def set_transaction_name(self, name, source=None):
772772
self._span.containing_transaction.source = source
773773

774774
if source:
775-
self._transaction_info["source"] = source
775+
if self._transaction_info is None:
776+
self._transaction_info = {"source": source}
777+
else:
778+
self._transaction_info["source"] = source
776779

777780
@_attr_setter
778781
def user(self, value):
@@ -805,7 +808,10 @@ def span(self, span):
805808
if transaction.name:
806809
self._transaction = transaction.name
807810
if transaction.source:
808-
self._transaction_info["source"] = transaction.source
811+
if self._transaction_info is None:
812+
self._transaction_info = {"source": transaction.source}
813+
else:
814+
self._transaction_info["source"] = transaction.source
809815

810816
@property
811817
def profile(self):
@@ -1491,7 +1497,10 @@ def update_from_scope(self, scope):
14911497
if scope._transaction is not None:
14921498
self._transaction = scope._transaction
14931499
if scope._transaction_info is not None:
1494-
self._transaction_info.update(scope._transaction_info)
1500+
if self._transaction_info is None:
1501+
self._transaction_info = scope._transaction_info
1502+
else:
1503+
self._transaction_info.update(scope._transaction_info)
14951504
if scope._user is not None:
14961505
self._user = scope._user
14971506
if scope._tags:

tests/test_scope.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,3 +869,11 @@ def test_last_event_id_cleared(sentry_init):
869869
Scope.get_isolation_scope().clear()
870870

871871
assert Scope.last_event_id() is None, "last_event_id should be cleared"
872+
873+
874+
def test_transaction_info_default_is_none(sentry_init):
875+
sentry_init(traces_sample_rate=1.0)
876+
877+
scope = sentry_sdk.get_current_scope()
878+
879+
assert scope._transaction_info is None

0 commit comments

Comments
 (0)