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
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
13 changes: 13 additions & 0 deletions test/test_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,19 @@ TEST_TRACER("span extraction") {
{__LINE__, "invalid: non hex trace tag ID",
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-xy", // traceparent
"malformed_traceflags"}, // expected_error_tag_value

{
__LINE__,
"invalid: non supported character in trace version 1/x",
".0-12345678901234567890123456789012-1234567890123456-01",
"invalid_version",
},
{
__LINE__,
"invalid: non supported character in trace version 2/x",
"0.-12345678901234567890123456789012-1234567890123456-01",
"invalid_version"
},
}));
// clang-format on

Expand Down