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(scope): Clear last_event_id on scope clear #3124

Merged
merged 2 commits into from
Jun 6, 2024
Merged
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
6 changes: 3 additions & 3 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ def __init__(self, ty=None, client=None):
incoming_trace_information = self._load_trace_data_from_env()
self.generate_propagation_context(incoming_data=incoming_trace_information)

# self._last_event_id is only applicable to isolation scopes
self._last_event_id = None # type: Optional[str]

def __copy__(self):
# type: () -> Scope
"""
Expand Down Expand Up @@ -680,6 +677,9 @@ def clear(self):

self._propagation_context = None

# self._last_event_id is only applicable to isolation scopes
self._last_event_id = None # type: Optional[str]

@_attr_setter
def level(self, value):
# type: (LogLevelStr) -> None
Expand Down
13 changes: 13 additions & 0 deletions tests/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,16 @@ def test_last_event_id_transaction(sentry_init):
pass

assert Scope.last_event_id() is None, "Transaction should not set last_event_id"


def test_last_event_id_cleared(sentry_init):
sentry_init(enable_tracing=True)

# Make sure last_event_id is set
sentry_sdk.capture_exception(Exception("test"))
assert Scope.last_event_id() is not None

# Clearing the isolation scope should clear the last_event_id
Scope.get_isolation_scope().clear()

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