From 6b923fe90f75b109c0de3bbb03c496d0bd2e5f1f Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Wed, 13 Aug 2025 16:21:56 +0200 Subject: [PATCH] Do not fail if there is no _context_manager_state --- sentry_sdk/profiler/transaction_profiler.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/profiler/transaction_profiler.py b/sentry_sdk/profiler/transaction_profiler.py index 3743b7c905..d228f77de9 100644 --- a/sentry_sdk/profiler/transaction_profiler.py +++ b/sentry_sdk/profiler/transaction_profiler.py @@ -45,6 +45,7 @@ ) from sentry_sdk.utils import ( capture_internal_exception, + capture_internal_exceptions, get_current_thread_meta, is_gevent, is_valid_sample_rate, @@ -369,12 +370,13 @@ def __enter__(self): def __exit__(self, ty, value, tb): # type: (Optional[Any], Optional[Any], Optional[Any]) -> None - self.stop() + with capture_internal_exceptions(): + self.stop() - scope, old_profile = self._context_manager_state - del self._context_manager_state + scope, old_profile = self._context_manager_state + del self._context_manager_state - scope.profile = old_profile + scope.profile = old_profile def write(self, ts, sample): # type: (int, ExtractedSample) -> None