Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/datadog/w3c_propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
17 changes: 17 additions & 0 deletions test/test_span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,23 @@ 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__,
"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",
{
Expand Down
26 changes: 26 additions & 0 deletions test/test_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,32 @@ TEST_TRACER("span extraction") {
"0000000000000000", // expected_datadog_w3c_parent_id,
},

{
__LINE__,
"dd entry with whitespace-padded keys",
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__,
"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",
Expand Down
Loading