From 55f1838ab2b43bf0bac218f615bde50f37fcd83c Mon Sep 17 00:00:00 2001 From: Brian Marks Date: Wed, 4 Nov 2026 10:07:55 -0500 Subject: [PATCH 1/2] Skip whitespace-padded entries in W3C tracestate dd value An entry such as " t.x:y" in the dd value did not match a known key, so it was kept as an unknown entry and injected downstream as-is. Skip padded entries instead, like other malformed entries. The rest of the dd value is still used. APMS-20291 --- src/datadog/w3c_propagation.cpp | 2 +- test/test_span.cpp | 9 +++++++++ test/test_tracer.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/datadog/w3c_propagation.cpp b/src/datadog/w3c_propagation.cpp index cd504184..26ee556f 100644 --- a/src/datadog/w3c_propagation.cpp +++ b/src/datadog/w3c_propagation.cpp @@ -245,7 +245,7 @@ void parse_datadog_trace_state(ExtractedData& result, const auto pair = datadog_trace_state.substr(pair_begin, pair_end - pair_begin); pair_begin = (pair_end == StringView::npos) ? end : pair_end + 1; - if (pair.empty()) { + if (pair.empty() || trim(pair).size() != pair.size()) { continue; } diff --git a/test/test_span.cpp b/test/test_span.cpp index 6b6f0d40..8cff8749 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -815,6 +815,15 @@ TEST_SPAN("injecting W3C tracestate header") { // The "s:0" comes from the sampling decision in `traceparent_drop`. "dd=s:0;p:$parent_id;foo:bar;boing:boing"}, + {__LINE__, + "drop whitespace-padded fields", + { + {"traceparent", traceparent_drop}, + {"tracestate", "dd=foo:bar; boing:boing; t.x:y"}, + }, + // The "s:0" comes from the sampling decision in `traceparent_drop`. + "dd=s:0;p:$parent_id;foo:bar"}, + {__LINE__, "all of the above", { diff --git a/test/test_tracer.cpp b/test/test_tracer.cpp index 4ab69071..3b10bf99 100644 --- a/test/test_tracer.cpp +++ b/test/test_tracer.cpp @@ -997,6 +997,19 @@ TEST_TRACER("span extraction") { "0000000000000000", // expected_datadog_w3c_parent_id, }, + { + __LINE__, + "dd entry with whitespace-padded subentries", + traceparent_drop, // traceparent + "dd=foo:bar; t.x:y; ;baz:bam ;o:France", // tracestate + 0, // expected_sampling_priority + "France", // expected_origin + {}, // expected_trace_tags + nullopt, // expected_additional_w3c_tracestate + "foo:bar", // expected_additional_datadog_w3c_tracestate + "0000000000000000", // expected_datadog_w3c_parent_id, + }, + { __LINE__, "origin, trace tags, parent, and extra fields", From d91a1b05a43087c352ed473e18ce2ea0022d9e5a Mon Sep 17 00:00:00 2001 From: Brian Marks Date: Thu, 5 Nov 2026 09:37:48 -0500 Subject: [PATCH 2/2] Only skip dd tracestate entries with padded keys The encoder keeps spaces in origin and trace tag values, so an entry such as "t.foo:bar ;" is valid output of this library. Checking the whole entry for padding dropped such tags on extraction. Check the key only, so values keep their spaces. --- src/datadog/w3c_propagation.cpp | 6 +++++- test/test_span.cpp | 8 ++++++++ test/test_tracer.cpp | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/datadog/w3c_propagation.cpp b/src/datadog/w3c_propagation.cpp index 26ee556f..ae8290be 100644 --- a/src/datadog/w3c_propagation.cpp +++ b/src/datadog/w3c_propagation.cpp @@ -245,7 +245,7 @@ void parse_datadog_trace_state(ExtractedData& result, const auto pair = datadog_trace_state.substr(pair_begin, pair_end - pair_begin); pair_begin = (pair_end == StringView::npos) ? end : pair_end + 1; - if (pair.empty() || trim(pair).size() != pair.size()) { + if (pair.empty()) { continue; } @@ -255,6 +255,10 @@ void parse_datadog_trace_state(ExtractedData& result, } const auto key = pair.substr(0, kv_separator); + const bool has_padding = trim(key).size() != key.size(); + if (has_padding) { + continue; + } const auto value = pair.substr(kv_separator + 1); if (key == "o") { result.origin = std::string{value}; diff --git a/test/test_span.cpp b/test/test_span.cpp index 8cff8749..b9e6db1a 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -824,6 +824,14 @@ TEST_SPAN("injecting W3C tracestate header") { // The "s:0" comes from the sampling decision in `traceparent_drop`. "dd=s:0;p:$parent_id;foo:bar"}, + {__LINE__, + "keep spaces at the end of values", + { + {"traceparent", traceparent_drop}, + {"tracestate", "dd=o:France ;t.foo:x ;foo:bar ;boing:boing"}, + }, + "dd=s:0;p:$parent_id;o:France ;t.foo:x ;foo:bar ;boing:boing"}, + {__LINE__, "all of the above", { diff --git a/test/test_tracer.cpp b/test/test_tracer.cpp index 3b10bf99..066a9781 100644 --- a/test/test_tracer.cpp +++ b/test/test_tracer.cpp @@ -999,9 +999,9 @@ TEST_TRACER("span extraction") { { __LINE__, - "dd entry with whitespace-padded subentries", + "dd entry with whitespace-padded keys", traceparent_drop, // traceparent - "dd=foo:bar; t.x:y; ;baz:bam ;o:France", // tracestate + "dd=foo:bar; t.x:y; ;baz :bam;o:France", // tracestate 0, // expected_sampling_priority "France", // expected_origin {}, // expected_trace_tags @@ -1010,6 +1010,19 @@ TEST_TRACER("span extraction") { "0000000000000000", // expected_datadog_w3c_parent_id, }, + { + __LINE__, + "dd entry with spaces at the end of values", + traceparent_drop, // traceparent + "dd=t.foo:bar ;o:France ;qux:quux", // tracestate + 0, // expected_sampling_priority + "France ", // expected_origin + {{"_dd.p.foo", "bar "}}, // expected_trace_tags + nullopt, // expected_additional_w3c_tracestate + "qux:quux", // expected_additional_datadog_w3c_tracestate + "0000000000000000", // expected_datadog_w3c_parent_id, + }, + { __LINE__, "origin, trace tags, parent, and extra fields",