Skip to content

Commit 5f2adcf

Browse files
authored
Wrap span restoration in __exit__ in capture_internal_exceptions (#4719)
Ref #4718 Does not solve the underlying issue and might leave things in an inconsistent state, but it's still preferable to letting an error bubble up to the user.
1 parent f702ec9 commit 5f2adcf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sentry_sdk/tracing.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA, SPANTEMPLATE
99
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
1010
from sentry_sdk.utils import (
11+
capture_internal_exceptions,
1112
get_current_thread_meta,
1213
is_valid_sample_rate,
1314
logger,
@@ -418,10 +419,11 @@ def __exit__(self, ty, value, tb):
418419
if value is not None and should_be_treated_as_error(ty, value):
419420
self.set_status(SPANSTATUS.INTERNAL_ERROR)
420421

421-
scope, old_span = self._context_manager_state
422-
del self._context_manager_state
423-
self.finish(scope)
424-
scope.span = old_span
422+
with capture_internal_exceptions():
423+
scope, old_span = self._context_manager_state
424+
del self._context_manager_state
425+
self.finish(scope)
426+
scope.span = old_span
425427

426428
@property
427429
def containing_transaction(self):

0 commit comments

Comments
 (0)