Skip to content

Commit 00ecf62

Browse files
committed
fix opentelemetry detach
1 parent 825c22a commit 00ecf62

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/service-library/src/servicelib/tracing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ def get_context() -> TracingContext:
2121

2222
@contextmanager
2323
def use_tracing_context(context: TracingContext):
24+
token: object | None = None
2425
if context is not None:
25-
otcontext.attach(context)
26+
token = otcontext.attach(context)
2627
try:
2728
yield
2829
finally:
29-
if context is not None:
30-
otcontext.detach(context)
30+
if token is not None:
31+
otcontext.detach(token)
3132

3233

3334
def setup_log_tracing(tracing_settings: TracingSettings):

0 commit comments

Comments
 (0)