[−][src]Struct trace_context::TraceContext
A TraceContext object
Methods
impl TraceContext
[src]
pub fn extract(headers: &HeaderMap) -> Result<Self, ParseIntError>
[src]
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
[src]
pub fn inject(&self, headers: &mut HeaderMap)
[src]
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
[src]
pub fn id(&self) -> u64
[src]
pub fn version(&self) -> u8
[src]
pub fn trace_id(&self) -> u128
[src]
pub fn parent_id(&self) -> Option<u64>
[src]
pub fn flags(&self) -> u8
[src]
pub fn sampled(&self) -> bool
[src]
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);
pub fn set_sampled(&mut self, sampled: bool)
[src]
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
impl Debug for TraceContext
[src]
impl Display for TraceContext
[src]
Auto Trait Implementations
impl Send for TraceContext
impl Sync for TraceContext
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,