From 04b3ce815ffa4b4e3af4aaaf95750b131b0ccfd2 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Wed, 31 Jul 2024 11:49:05 +0200 Subject: [PATCH] fix(potel): Set POTelSpan on current scope --- sentry_sdk/tracing.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 00a6e94678..ba8444001a 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -1277,10 +1277,19 @@ def __enter__(self): # set as the implicit current context self._ctx_token = context.attach(ctx) + self._scope_manager = sentry_sdk.new_scope() + scope = self._scope_manager.__enter__() + scope.span = self + return self def __exit__(self, ty, value, tb): # type: (Optional[Any], Optional[Any], Optional[Any]) -> None + self._scope_manager.__exit__(ty, value, tb) + del ( + self._scope_manager + ) # Eliminate circular reference which could prevent garbage collection + self._otel_span.end() # XXX set status to error if unset and an exception occurred? if self._active: