Skip to content

fix(llmobs): propagate llmobs_parent_id in _current_trace_context#18253

Open
jasonmp85 wants to merge 2 commits into
mainfrom
jmp/llmobs_propagate_parent_id
Open

fix(llmobs): propagate llmobs_parent_id in _current_trace_context#18253
jasonmp85 wants to merge 2 commits into
mainfrom
jmp/llmobs_propagate_parent_id

Conversation

@jasonmp85
Copy link
Copy Markdown

@jasonmp85 jasonmp85 commented May 22, 2026

Summary

_current_trace_context() sets PROPAGATED_LLMOBS_TRACE_ID_KEY (_dd.p.llmobs_trace_id) on the returned context but omits PROPAGATED_PARENT_ID_KEY (_dd.p.llmobs_parent_id). Any consumer that reads context._meta directly — including HTTPPropagator.inject and non-Python clients (Go, Java, etc.) receiving the propagated headers — will see the trace ID but not the parent span ID.

This breaks distributed LLMObs tracing to non-Python services. For example, dd-trace-go's contextWithPropagatedLLMSpan requires both tags to be non-empty before it attaches the propagated LLMObs context:

if propagatedLLMObs.SpanID == "" || propagatedLLMObs.TraceID == "" {
    // falls through to newLLMObsTraceID() — starts a fresh, unrelated trace
}

Without _dd.p.llmobs_parent_id, a downstream Go service starts a new root LLMObs trace instead of inheriting the parent, breaking the distributed trace tree.

Fix

One line in _current_trace_context():

context._meta[PROPAGATED_PARENT_ID_KEY] = str(active.span_id)

PROPAGATED_PARENT_ID_KEY is already defined in _constants.py and imported in _llmobs.py — it was just never set on this code path.

Note: _inject_llmobs_context (the http.span_inject path, used by inject_distributed_headers) already sets this correctly. This fix brings _current_trace_context to parity.

Test

Added test_current_trace_context_includes_parent_id to tests/llmobs/test_propagation.py. Asserts that the context returned by _current_trace_context() has both PROPAGATED_PARENT_ID_KEY and PROPAGATED_LLMOBS_TRACE_ID_KEY set, with parent_id == str(span.span_id).

@jasonmp85 jasonmp85 requested a review from a team as a code owner May 22, 2026 21:42
@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da Bot commented May 22, 2026

Codeowners resolved as

releasenotes/notes/llmobs-propagate-parent-id-401cc2c7a9274277.yaml     @DataDog/apm-python

@datadog-prod-us1-3
Copy link
Copy Markdown

datadog-prod-us1-3 Bot commented May 22, 2026

Pipelines  Tests

Fix all issues with BitsAI

⚠️ Warnings

🚦 8 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v113741238-d2b8243-manylinux2014_x86_64, 1]   View in Datadog   GitLab

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. NotImplementedError: This version of CPython is not supported yet

DataDog/apm-reliability/dd-trace-py | build linux serverless: [amd64, cp315-cp315, v113741491-d2b8243-musllinux_1_2_x86_64, 1]   View in Datadog   GitLab

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. ImportError: NotImplementedError: This version of CPython is not supported yet

DataDog/apm-reliability/dd-trace-py | build linux serverless: [arm64, cp315-cp315, v113741357-d2b8243-manylinux2014_aarch64, 1]   View in Datadog   GitLab

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. NotImplementedError: This version of CPython is not supported yet during wheel testing.

View all 8 failed jobs.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5f80796 | Docs | Datadog PR Page | Give us feedback!

@jasonmp85 jasonmp85 force-pushed the jmp/llmobs_propagate_parent_id branch from a30e33b to 733bf26 Compare May 22, 2026 21:43
@jasonmp85 jasonmp85 force-pushed the jmp/llmobs_propagate_parent_id branch from 733bf26 to 460ab7a Compare May 27, 2026 17:40
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jasonmp85 jasonmp85 requested a review from a team as a code owner May 27, 2026 17:50
@jasonmp85 jasonmp85 requested review from dubloom and sabrenner May 27, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants