Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ddtrace/llmobs/_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,7 @@ def _current_trace_context(self) -> Optional[Context]:
context = active.context
wire_trace_id = _trace_id_to_wire(get_llmobs_trace_id(active)) or str(active.trace_id)
context._meta[PROPAGATED_LLMOBS_TRACE_ID_KEY] = wire_trace_id
context._meta[PROPAGATED_PARENT_ID_KEY] = str(active.span_id)
return context
return None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
LLM Observability: Fixed an issue where ``_current_trace_context`` did not propagate
``_dd.p.llmobs_parent_id`` into the trace context metadata. Without this value, downstream
consumers (e.g. dd-trace-go) could not locate the active LLMObs parent span and would create
orphaned child traces instead of correctly continuing the parent trace.
13 changes: 13 additions & 0 deletions tests/llmobs/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,19 @@ def _make_upstream_llmobs_context(trace_id_value, parent_id="987654321"):
return ctx


def test_current_trace_context_includes_parent_id(llmobs):
"""_current_trace_context must set PROPAGATED_PARENT_ID_KEY so that HTTPPropagator.inject
(and any other consumer that reads _meta directly) propagates _dd.p.llmobs_parent_id to
subprocess / HTTP consumers. Without this, dd-trace-go's contextWithPropagatedLLMSpan
sees an empty parent_id and falls through to newLLMObsTraceID(), orphaning the child trace.
"""
with llmobs.workflow("w") as span:
ctx = llmobs._instance._current_trace_context()
assert ctx is not None
assert ctx._meta.get(PROPAGATED_PARENT_ID_KEY) == str(span.span_id)
assert ctx._meta.get(PROPAGATED_LLMOBS_TRACE_ID_KEY) is not None


def test_injected_trace_id_is_decimal_on_the_wire(llmobs):
"""Wire must stay decimal so older SDKs that do int(header) keep working."""
with llmobs.workflow("w") as span:
Expand Down
Loading