Skip to content
Merged
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
10 changes: 6 additions & 4 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA, SPANTEMPLATE
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
from sentry_sdk.utils import (
capture_internal_exceptions,
get_current_thread_meta,
is_valid_sample_rate,
logger,
Expand Down Expand Up @@ -418,10 +419,11 @@ def __exit__(self, ty, value, tb):
if value is not None and should_be_treated_as_error(ty, value):
self.set_status(SPANSTATUS.INTERNAL_ERROR)

scope, old_span = self._context_manager_state
del self._context_manager_state
self.finish(scope)
scope.span = old_span
with capture_internal_exceptions():
scope, old_span = self._context_manager_state
del self._context_manager_state
self.finish(scope)
scope.span = old_span
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Tracing Context Corruption Due to Exception Handling

Wrapping the span's __exit__ cleanup in capture_internal_exceptions() can silently prevent the scope's active span from being restored, leaving the tracing context inconsistent. If an intermediate cleanup step fails, subsequent critical operations are skipped. Additionally, set_status is inconsistently outside this block, allowing its internal errors to surface.

Fix in Cursor Fix in Web


@property
def containing_transaction(self):
Expand Down