Repository navigation
fix(tracing): keep W3C tracestate dd= member within 256 chars - #20820
Open
julinvictus wants to merge 3 commits into
Open
julinvictus wants to merge 3 commits into
julinvictus wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
julinvictus
requested review from
florentinl and
rachelyangdog
and removed request for
a team
October 6, 2026 16:25
Yun-Kim
approved these changes
Oct 6, 2026
Yun-Kim
left a comment
Contributor
There was a problem hiding this comment.
Small nits but LGTM otherwise!
|
|
||
| _W3C_DD_LIST_MEMBER_MAX_CHARS = 256 | ||
| # len("dd=") + len("p:0000000000000000;") | ||
| _W3C_DD_LIST_MEMBER_RESERVED_LEN = 3 + len(W3C_TRACESTATE_PARENT_ID_KEY) + 1 + 16 + 1 |
Contributor
There was a problem hiding this comment.
Might be more clear and not require the comment if we change to this:
Suggested change
| _W3C_DD_LIST_MEMBER_RESERVED_LEN = 3 + len(W3C_TRACESTATE_PARENT_ID_KEY) + 1 + 16 + 1 | |
| _W3C_DD_LIST_MEMBER_RESERVED_LEN = len("dd=") + len(f"{W3C_TRACESTATE_PARENT_ID_KEY}:{0:016x};") |
Comment on lines
+203
to
+204
| # The 256 char limit applies to the whole "dd=" list-member as it goes on the wire, so count the | ||
| # "dd=" prefix, the ";" separators, and the "p:<16 hex>;" field prepended at injection time. |
Contributor
There was a problem hiding this comment.
Comments are unnecessary here
Suggested change
| # The 256 char limit applies to the whole "dd=" list-member as it goes on the wire, so count the | |
| # "dd=" prefix, the ";" separators, and the "p:<16 hex>;" field prepended at injection time. |
| # we need to keep the total length under 256 char | ||
| potential_current_tags_len = current_tags_len + len(next_tag) | ||
| if not potential_current_tags_len > 256: | ||
| next_tag_len = len(next_tag) + (1 if tags else 0) |
Contributor
There was a problem hiding this comment.
Suggested change
| next_tag_len = len(next_tag) + (1 if tags else 0) | |
| # account for ; before next tag entry | |
| next_tag_len = len(next_tag) + (1 if tags else 0) |
Comment on lines
+7
to
+8
| header, which broke LLM Observability trace linking across services. Propagated tags that do not fit | ||
| are now dropped whole. |
Contributor
There was a problem hiding this comment.
Suggested change
| header, which broke LLM Observability trace linking across services. Propagated tags that do not fit | |
| are now dropped whole. | |
| header. Propagated tags that do not fit are now dropped whole. |
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.
Description
w3c_get_dd_list_memberkeeps thedd=list-member of the W3Ctracestateheader under 256 characters, but it only counted the tag text. Three things that end up in the header were not counted:;separators between tags (1 char each)p:<16 hex>;parent id field, prepended at injection time byw3c_tracestate_add_p/ the nativebuild_tracestate(19 chars)dd=prefix (3 chars)So the injected member could exceed the limit by roughly 30 characters. This now shows up in practice because LLM Observability propagates more
_dd.p.llmobs_*tags (llmobs_sid,llmobs_pagent_span_id,llmobs_pagent_name). With a typical set of those tags, the injecteddd=member was 285 characters. Proxies that enforce the W3C limit drop the wholetracestateheader, which breaks LLM Observability trace linking across services.The fix:
dd=andp:<16 hex>;up front (_W3C_DD_LIST_MEMBER_RESERVED_LEN).s:,o:,t.dm:,t.usr.id:) as they are written, separators included.;before each optional_dd.p.*tag.As before, tags that don't fit are dropped whole and never truncated.
Before (285 chars):
After (240 chars,
t.llmobs_pagent_span_iddropped because it no longer fits):Testing
w3c_get_dd_list_member/ tracecontext / inject tests fromtests/tracer/test_utils.pyandtests/tracer/test_propagation.pywith and without the patch. The patch introduced no new failures.Risks
p:space is reserved even when nop:field is added (no active Datadog span and no known last parent id). In that case up to 19 fewer characters are used for propagated tags than strictly allowed.llmobs_pagent_span_idis the one most likely to be dropped.Additional Notes
Opened from a fork, so some required CI can't run here and will need a maintainer to mirror the branch.
🤖 Generated with Claude Code