Skip to content

Commit 14fabd8

Browse files
committed
linting
1 parent 0b48ad3 commit 14fabd8

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

ddtrace/_trace/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _has_active_context(self) -> bool:
3535
pass
3636

3737
@abc.abstractmethod
38-
def activate(self, ctx: Optional[ActiveTrace]) -> None:
38+
def activate(self, ctx: Optional[ActiveTrace]):
3939
core.dispatch("ddtrace.context_provider.activate", (ctx,))
4040

4141
@abc.abstractmethod

ddtrace/internal/ci_visibility/context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ def _has_active_context(self):
3333
ctx = _DD_CI_CONTEXTVAR.get()
3434
return ctx is not None
3535

36-
def activate(self, ctx: ContextTypeValue) -> None:
36+
def activate(self, ctx: ContextTypeValue) -> contextvars.Token:
3737
"""Makes the given context active in the current execution."""
38-
_DD_CI_CONTEXTVAR.set(ctx)
38+
token = _DD_CI_CONTEXTVAR.set(ctx)
3939
super(DefaultContextProvider, self).activate(ctx)
40+
return token
4041

4142
def active(self) -> ContextTypeValue:
4243
"""Returns the active span or context for the current execution."""
4344
item = _DD_CI_CONTEXTVAR.get()
4445
if isinstance(item, Span):
4546
return self._update_active(item)
4647
return item
48+
49+
def _deactivate(self, token: contextvars.Token) -> None:
50+
_DD_CI_CONTEXTVAR.reset(token)

ddtrace/internal/opentelemetry/context.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ def detach(self, token):
9191
"""
9292
Resets the datadog contextvar to the previous active context.
9393
"""
94-
self._ddcontext_provider._deactivate(token)
94+
if hasattr(self._ddcontext_provider, "_deactivate"):
95+
self._ddcontext_provider._deactivate(token)
96+
else:
97+
log.debug(
98+
"Context provider does not support deactivation. " "Active Context: %s, Token: %s",
99+
self._ddcontext_provider.active(),
100+
token,
101+
)
95102

96103
@property
97104
def _ddcontext_provider(self):
98105
"""
99106
Get the ddtrace context provider from the global Datadog tracer.
100-
This can reterive a default, gevent, or asyncio context provider.
101107
"""
102108
return ddtracer.context_provider

ddtrace/llmobs/_context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ def _update_active(self, span: Span) -> Optional[Span]:
4747
self.activate(None)
4848
return None
4949

50-
def activate(self, ctx: ContextTypeValue) -> None:
50+
def activate(self, ctx: ContextTypeValue) -> contextvars.Token:
5151
"""Makes the given context active in the current execution."""
52-
_DD_LLMOBS_CONTEXTVAR.set(ctx)
52+
token = _DD_LLMOBS_CONTEXTVAR.set(ctx)
5353
super(DefaultContextProvider, self).activate(ctx)
54+
return token
5455

5556
def active(self) -> ContextTypeValue:
5657
"""Returns the active span or context for the current execution."""
5758
item = _DD_LLMOBS_CONTEXTVAR.get()
5859
if isinstance(item, Span):
5960
return self._update_active(item)
6061
return item
62+
63+
def _deactivate(self, token: contextvars.Token) -> None:
64+
_DD_LLMOBS_CONTEXTVAR.reset(token)

0 commit comments

Comments
 (0)