pub struct TraceContext { /* private fields */ }
Expand description
A TraceContext object
Implementations§
Source§impl TraceContext
impl TraceContext
Sourcepub fn extract(headers: &HeaderMap) -> Result<Self, ParseIntError>
pub fn extract(headers: &HeaderMap) -> Result<Self, ParseIntError>
Create and return TraceContext object based on traceparent
HTTP header.
§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);
pub fn new_root() -> Self
Sourcepub fn inject(&self, headers: &mut HeaderMap)
pub fn inject(&self, headers: &mut HeaderMap)
Add the traceparent header to the http headers
§Examples
let mut input_headers = http::HeaderMap::new();
input_headers.insert("traceparent", "00-00000000000000000000000000000001-0000000000000002-01".parse().unwrap());
let parent = trace_context::TraceContext::extract(&input_headers).unwrap();
let mut output_headers = http::HeaderMap::new();
parent.inject(&mut output_headers);
let child = trace_context::TraceContext::extract(&output_headers).unwrap();
assert_eq!(child.version(), parent.version());
assert_eq!(child.trace_id(), parent.trace_id());
assert_eq!(child.parent_id(), Some(parent.id()));
assert_eq!(child.flags(), parent.flags());
pub fn child(&self) -> Self
pub fn id(&self) -> u64
pub fn version(&self) -> u8
pub fn trace_id(&self) -> u128
pub fn parent_id(&self) -> Option<u64>
pub fn flags(&self) -> u8
Sourcepub fn sampled(&self) -> bool
pub fn sampled(&self) -> bool
Returns true if the trace is sampled
§Examples
let mut headers = http::HeaderMap::new();
headers.insert("traceparent", "00-00000000000000000000000000000001-0000000000000002-01".parse().unwrap());
let context = trace_context::TraceContext::extract(&headers).unwrap();
assert_eq!(context.sampled(), true);
Sourcepub fn set_sampled(&mut self, sampled: bool)
pub fn set_sampled(&mut self, sampled: bool)
Change sampled flag
§Examples
let mut context = trace_context::TraceContext::new_root();
assert_eq!(context.sampled(), true);
context.set_sampled(false);
assert_eq!(context.sampled(), false);
Trait Implementations§
Source§impl Debug for TraceContext
impl Debug for TraceContext
Auto Trait Implementations§
impl Freeze for TraceContext
impl RefUnwindSafe for TraceContext
impl Send for TraceContext
impl Sync for TraceContext
impl Unpin for TraceContext
impl UnwindSafe for TraceContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more