From 460ab7a197c2cd2d0ace34808089173ed43c53b3 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Fri, 22 May 2026 15:41:41 -0600 Subject: [PATCH 1/2] fix(llmobs): propagate parent_id in _current_trace_context --- ddtrace/llmobs/_llmobs.py | 1 + tests/llmobs/test_propagation.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/ddtrace/llmobs/_llmobs.py b/ddtrace/llmobs/_llmobs.py index 0806cae8edf..b05c39ce42e 100644 --- a/ddtrace/llmobs/_llmobs.py +++ b/ddtrace/llmobs/_llmobs.py @@ -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 diff --git a/tests/llmobs/test_propagation.py b/tests/llmobs/test_propagation.py index 004b2222028..350a94406e3 100644 --- a/tests/llmobs/test_propagation.py +++ b/tests/llmobs/test_propagation.py @@ -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: From 5f807965d238e01d1a8a8d28e383dfffd9601e40 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Wed, 27 May 2026 11:50:04 -0600 Subject: [PATCH 2/2] chore(llmobs): add release note for parent_id propagation fix Co-Authored-By: Claude Sonnet 4.6 --- .../notes/llmobs-propagate-parent-id-401cc2c7a9274277.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 releasenotes/notes/llmobs-propagate-parent-id-401cc2c7a9274277.yaml diff --git a/releasenotes/notes/llmobs-propagate-parent-id-401cc2c7a9274277.yaml b/releasenotes/notes/llmobs-propagate-parent-id-401cc2c7a9274277.yaml new file mode 100644 index 00000000000..40d4a359f27 --- /dev/null +++ b/releasenotes/notes/llmobs-propagate-parent-id-401cc2c7a9274277.yaml @@ -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.