fix(llmobs): prevent duplicate tags in x-datadog-tags on injection - #9832
Open
patrickswedish wants to merge 1 commit into
Open
fix(llmobs): prevent duplicate tags in x-datadog-tags on injection#9832patrickswedish wants to merge 1 commit into
patrickswedish wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
o-changelog\ label attached