Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions src/datadog/w3c_propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ auto verboten(int lowest_ascii, int highest_ascii,
};
}

constexpr bool is_hexdiglc(const char c) {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F');
}

// Populate the specified `result` with data extracted from the "traceparent"
// entry of the specified `headers`. Return `nullopt` on success. Return a value
// for the `tags::internal::w3c_extraction_error` tag if an error occurs.
Expand All @@ -59,6 +64,8 @@ Optional<std::string> extract_traceparent(ExtractedData& result,

beg = i + 1;
internal_state = state::trace_id;
} else if (!is_hexdiglc(traceparent[i])) {
return "invalid_version";
}
} break;

Expand Down
26 changes: 25 additions & 1 deletion test/test_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,31 @@ TEST_TRACER("span extraction") {
nullopt,
"0000000000000000", // expected_datadog_w3c_parent_id,
},

{
__LINE__,
"malformed traceparent 1/x",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this test would fit better in a previous test case, where you test error cases and assert that the expected_error_tag_value is malformed_traceparent. However this input would result in invalid_version

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you @zacharycmontoya . Addressed in 071b25b

".0-12345678901234567890123456789012-1234567890123456-01",
nullopt,
nullopt,
nullopt,
{},
nullopt,
nullopt,
nullopt,
},
{
__LINE__,
"malformed traceparent 1/x",
"0.-12345678901234567890123456789012-1234567890123456-01",
nullopt,
nullopt,
nullopt,
{},
nullopt,
nullopt,
nullopt,
},
}));

CAPTURE(test_case.name);
Expand Down Expand Up @@ -1225,7 +1250,6 @@ TEST_TRACER("span extraction") {
test_case.expected_datadog_w3c_parent_id);

REQUIRE(logger.entries.empty());
REQUIRE(span_tags.empty());
}

SECTION("W3C Phase 3 support - Preferring tracecontext") {
Expand Down