Skip to content

Commit

Permalink
Typing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Kim committed Jan 6, 2025
1 parent 2f04735 commit 8565dd8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/futures/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _wrap_submit(func, args, kwargs):
if config._llmobs_enabled:
from ddtrace.llmobs import LLMObs

llmobs_ctx = LLMObs._instance.current_trace_context()
llmobs_ctx = LLMObs._instance._current_trace_context()

# The target function can be provided as a kwarg argument "fn" or the first positional argument
self = args[0]
Expand Down
19 changes: 7 additions & 12 deletions ddtrace/llmobs/_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,10 @@ def export_span(cls, span: Optional[Span] = None) -> Optional[ExportedLLMObsSpan
If no span is provided, the current active LLMObs-type span will be used.
"""
if span is None:
span = cls._instance.current_span()
span = cls._instance._current_span()
if span is None:
log.warning("No span provided and no active LLMObs-generated span found.")
return None
return ExportedLLMObsSpan(span_id=str(span.span_id), trace_id="{:x}".format(span.trace_id))
try:
if span.span_type != SpanTypes.LLM:
log.warning("Span must be an LLMObs-generated span.")
Expand All @@ -384,15 +383,15 @@ def export_span(cls, span: Optional[Span] = None) -> Optional[ExportedLLMObsSpan
log.warning("Failed to export span. Span must be a valid Span object.")
return None

def current_span(self) -> Optional[Span]:
def _current_span(self) -> Optional[Span]:
"""Returns the currently active LLMObs-generated span.
Note that there may be an active span represented by a context object
(i.e. a distributed trace) which will not be returned by this method.
"""
active = self._llmobs_context_provider.active()
return active if isinstance(active, Span) else None

def current_trace_context(self) -> Optional[Context]:
def _current_trace_context(self) -> Optional[Context]:
"""Returns the context for the current LLMObs trace."""
active = self._llmobs_context_provider.active()
if isinstance(active, Context):
Expand Down Expand Up @@ -640,7 +639,7 @@ def annotate(
such as `{prompt,completion,total}_tokens`.
"""
if span is None:
span = cls._instance.current_span()
span = cls._instance._current_span()
if span is None:
log.warning("No span provided and no active LLMObs-generated span found.")
return
Expand Down Expand Up @@ -928,7 +927,7 @@ def submit_evaluation(

@classmethod
def _inject_llmobs_context(cls, request_headers: Dict[str, str]) -> Dict[str, str]:
active_ctx = cls._instance.current_trace_context()
active_ctx = cls._instance._current_trace_context()
if active_ctx is None:
parent_id = ROOT_PARENT_ID
else:
Expand All @@ -949,7 +948,7 @@ def inject_distributed_headers(cls, request_headers: Dict[str, str], span: Optio
log.warning("request_headers must be a dictionary of string key-value pairs.")
return request_headers
if span is None:
span = cls._instance.current_span()
span = cls._instance._current_span()
if span is None:
log.warning("No span provided and no currently active span found.")
return request_headers
Expand All @@ -961,11 +960,7 @@ def inject_distributed_headers(cls, request_headers: Dict[str, str], span: Optio
return request_headers

@classmethod
def _activate_llmobs_distributed_headers(
cls, request_headers: Dict[str, str], context: Optional[Context] = None
) -> None:
if not context:
context = HTTPPropagator.extract(request_headers)
def _activate_llmobs_distributed_headers(cls, request_headers: Dict[str, str], context: Context) -> None:
if not context.trace_id or not context.span_id:
log.warning("Failed to extract trace/span ID from request headers.")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
features:
- |
LLM Observability: Introduces an improved automated context management system for LLM Observability-specific spans.
Also introduces ``LLMObs.current_span()`` and ``LLMObs.current_trace_context()`` which return the currently active LLM Observability-specific ``Span`` and ``Context`` objects, respectively.
Also modifies ``LLMObs.export_span()``, ``LLMObs.inject_distributed_headers()``, ``LLMObs.annotate()`` to default to the current active LLM Observability-specific span if ``span`` is not provided.
- |
LLM Observability: Introduces automated distributed tracing support for LLM Observability traces involving the ``concurrent.futures.thread`` module.

0 comments on commit 8565dd8

Please sign in to comment.