Skip to content

Commit

Permalink
fix: default Scope._transaction_info of the scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Андрей Сапаров committed Oct 10, 2024
1 parent ce604f9 commit f94c605
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 14 additions & 5 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def __copy__(self):
rv._name = self._name
rv._fingerprint = self._fingerprint
rv._transaction = self._transaction
rv._transaction_info = dict(self._transaction_info)
rv._transaction_info = copy(self._transaction_info)
rv._user = self._user

rv._tags = dict(self._tags)
Expand Down Expand Up @@ -664,7 +664,7 @@ def clear(self):
self._level = None # type: Optional[LogLevelStr]
self._fingerprint = None # type: Optional[List[str]]
self._transaction = None # type: Optional[str]
self._transaction_info = {} # type: MutableMapping[str, str]
self._transaction_info = None # type: Optional[MutableMapping[str, str]]
self._user = None # type: Optional[Dict[str, Any]]

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

if source:
self._transaction_info["source"] = source
if self._transaction_info is None:
self._transaction_info = {"source": source}
else:
self._transaction_info["source"] = source

@_attr_setter
def user(self, value):
Expand Down Expand Up @@ -805,7 +808,10 @@ def span(self, span):
if transaction.name:
self._transaction = transaction.name
if transaction.source:
self._transaction_info["source"] = transaction.source
if self._transaction_info is None:
self._transaction_info = {"source": transaction.source}
else:
self._transaction_info["source"] = transaction.source

@property
def profile(self):
Expand Down Expand Up @@ -1491,7 +1497,10 @@ def update_from_scope(self, scope):
if scope._transaction is not None:
self._transaction = scope._transaction
if scope._transaction_info is not None:
self._transaction_info.update(scope._transaction_info)
if self._transaction_info is None:
self._transaction_info = scope._transaction_info
else:
self._transaction_info.update(scope._transaction_info)
if scope._user is not None:
self._user = scope._user
if scope._tags:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,3 +869,11 @@ def test_last_event_id_cleared(sentry_init):
Scope.get_isolation_scope().clear()

assert Scope.last_event_id() is None, "last_event_id should be cleared"


def test_transaction_info_default_is_none(sentry_init):
sentry_init(traces_sample_rate=1.0)

scope = sentry_sdk.get_current_scope()

assert scope._transaction_info is None

0 comments on commit f94c605

Please sign in to comment.