Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set default Scope._transaction_info value to None #3641

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 14 additions & 5 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,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 @@ -669,7 +669,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 @@ -778,7 +778,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 @@ -811,7 +814,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 @@ -1497,7 +1503,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 @@ -883,3 +883,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
Loading