Skip to content

fix(llmobs): prevent duplicate tags in x-datadog-tags on injection - #9832

Open
patrickswedish wants to merge 1 commit into
DataDog:masterfrom
patrickswedish:fix-llmobs-duplicate-tags
Open

fix(llmobs): prevent duplicate tags in x-datadog-tags on injection#9832
patrickswedish wants to merge 1 commit into
DataDog:masterfrom
patrickswedish:fix-llmobs-duplicate-tags

Conversation

@patrickswedish

Copy link
Copy Markdown

What does this PR do?

Fixes a bug where injecting LLMObs trace context into outbound carrier headers (\x-datadog-tags) duplicated _dd.p.llmobs_ml_app\ (and potentially other LLMObs keys) when the carrier or trace context already contained those tags from upstream requests or standard trace tag propagation.

Motivation

When an inbound request carries _dd.p.llmobs_ml_app\ in \x-datadog-tags, standard trace propagation extracts it into _trace.tags. On an outbound request, _injectTags\ writes the existing tags into \x-datadog-tags, and subsequent LLMObs channel injection (\handleLLMObsInjection) unconditionally appended resolved LLMObs keys with a comma separator, resulting in duplicate entries like:
\
x-datadog-tags: _dd.p.tid=6a734d1a00000000,_dd.p.dm=-0,_dd.p.llmobs_ml_app=my-ml-app,_dd.p.llmobs_ml_app=my-ml-app
\\

By utilizing the existing \stripTagsetEntry\ helper before appending each resolved LLMObs key (\PROPAGATED_PARENT_ID_KEY, \PROPAGATED_ML_APP_KEY, \PROPAGATED_SESSION_ID_KEY, \PROPAGATED_SAMPLE_RATE_KEY, \PROPAGATED_SAMPLING_DECISION_KEY, \PROPAGATED_TRACE_ID_KEY), any pre-existing entry for that key is replaced cleanly without duplication.

Fixes #9714.

Additional Notes

Review checklist

  • PR has a meaningful title or PR has the
    o-changelog\ label attached
  • Feature or bugfix has tests
  • Git history is clean
  • If PR impacts documentation, docs team has been notified or an issue has been opened on the documentation repo
  • Backporting labels are added

When injecting LLMObs trace context into outbound carriers, handleLLMObsInjection
previously appended propagated keys without checking whether existing x-datadog-tags
already contained entries for those keys (for example, from standard trace tag
propagation or upstream service headers). This resulted in duplicate entries such
as multiple _dd.p.llmobs_ml_app values in x-datadog-tags.

Use stripTagsetEntry before appending resolved LLMObs keys so existing entries
are cleanly replaced without duplication.

Fixes DataDog#9714
@patrickswedish
patrickswedish requested a review from a team as a code owner August 17, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: LLMObs injection duplicates _dd.p.llmobs_ml_app in x-datadog-tags

1 participant