Skip to content
Open
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
13 changes: 13 additions & 0 deletions linkerd/trace-context/src/propagation/w3c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ fn parse_context(header_value: &str) -> Option<TraceContext> {
let (trace_id, rest) = parse_header_value(rest, 16)?;
let (parent_id, rest) = parse_header_value(rest, 8)?;

if rest.len() != 2 {
debug!(header = %HTTP_TRACEPARENT, flags = %rest, "Tracecontext flags must be exactly one byte");
return None;
}

let flags = match hex::decode(rest) {
// If valid hex, take final bit and AND with 1. W3C only uses one bit
// for flags in version 00, and the bit is used to control sampling
Expand Down Expand Up @@ -123,6 +128,14 @@ mod tests {
let actual = parse_context(input);
assert!(actual.is_none());

let input = "00-94d7f6ec6b95f3e916179cb6cfd01390-55ccfce77f972614-0102";
let actual = parse_context(input);
assert!(actual.is_none());

let input = "00-94d7f6ec6b95f3e916179cb6cfd01390-55ccfce77f972614-";
let actual = parse_context(input);
assert!(actual.is_none());

let input = "00-94d7f6ec6b95f3e916179cb6cfd01390-55ccfce77f972614";
let actual = parse_context(input);
assert!(actual.is_none());
Expand Down