#w3c #tracing #traceparent #tracestate

trace-context

Extract and inject W3C TraceContext headers

1 unstable release

0.1.0 Jun 2, 2019

#29 in #w3c

Download history 3/week @ 2024-02-21 15/week @ 2024-02-28 6/week @ 2024-03-06 1/week @ 2024-03-13 1/week @ 2024-03-20 8/week @ 2024-03-27 20/week @ 2024-04-03 4/week @ 2024-04-10 8/week @ 2024-04-17 17/week @ 2024-04-24

55 downloads per month

MIT/Apache

10KB
125 lines

trace-context

Extract and inject W3C TraceContext headers.

Installation

cargo add trace-context

Example usage

let mut headers = http::HeaderMap::new();
headers.insert("traceparent", "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01".parse().unwrap());

let context = trace_context::TraceContext::extract(&headers).unwrap();

assert_eq!(context.trace_id(), u128::from_str_radix("0af7651916cd43dd8448eb211c80319c", 16).unwrap());
assert_eq!(context.parent_id(), u64::from_str_radix("00f067aa0ba902b7", 16).ok());
assert_eq!(context.sampled(), true);

Safety

This crate uses #![deny(unsafe_code)] to ensure everything is implemented in 100% Safe Rust.

License

MIT OR Apache-2.0


lib.rs:

Extract and inject W3C TraceContext headers.

Examples

let mut headers = http::HeaderMap::new();
headers.insert(
    "traceparent",
    "00-0af7651916cd43dd8448eb211c80319c-00f067aa0ba902b7-01".parse().unwrap()
);

let context = trace_context::TraceContext::extract(&headers).unwrap();

assert_eq!(context.trace_id(), u128::from_str_radix("0af7651916cd43dd8448eb211c80319c", 16).unwrap());
assert_eq!(context.parent_id(), u64::from_str_radix("00f067aa0ba902b7", 16).ok());
assert_eq!(context.sampled(), true);

Dependencies

~1.5MB
~23K SLoC