pub struct TraceContext {
pub trace_id: [u8; 16],
pub span_id: [u8; 8],
pub flags: u8,
}Expand description
A W3C Trace Context traceparent.
Fields§
§trace_id: [u8; 16]16-byte trace identifier; never all zero.
span_id: [u8; 8]8-byte span identifier of the sender’s span; never all zero.
flags: u8Trace flags byte; bit 0 is sampled.
Implementations§
Source§impl TraceContext
impl TraceContext
Sourcepub const fn new(
trace_id: [u8; 16],
span_id: [u8; 8],
flags: u8,
) -> Option<TraceContext>
pub const fn new( trace_id: [u8; 16], span_id: [u8; 8], flags: u8, ) -> Option<TraceContext>
Builds a context from raw identifiers.
Returns None if either identifier is all zero, which the W3C
specification forbids.
Sourcepub fn parse_traceparent(value: &str) -> Result<TraceContext, TraceError>
pub fn parse_traceparent(value: &str) -> Result<TraceContext, TraceError>
Parses a traceparent header value.
Only version 00 layout is accepted: exactly 55 bytes,
vv-<32 hex>-<16 hex>-<2 hex>, lowercase hex, version not ff, neither
identifier all zero.
Sourcepub fn to_traceparent(&self) -> String
pub fn to_traceparent(&self) -> String
Formats the context as a version-00 traceparent value.
Sourcepub fn trace_id_hex(&self) -> String
pub fn trace_id_hex(&self) -> String
The trace id as 32 lowercase hex digits, for log fields.
Sourcepub fn span_id_hex(&self) -> String
pub fn span_id_hex(&self) -> String
The span id as 16 lowercase hex digits, for log fields.
Sourcepub const fn is_sampled(&self) -> bool
pub const fn is_sampled(&self) -> bool
True if the sampled flag is set.
Sourcepub const fn with_span_id(&self, span_id: [u8; 8]) -> Option<TraceContext>
pub const fn with_span_id(&self, span_id: [u8; 8]) -> Option<TraceContext>
Same trace, new span. Returns None for an all-zero span id.
Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
impl Copy for TraceContext
Source§impl Debug for TraceContext
impl Debug for TraceContext
Source§impl Display for TraceContext
impl Display for TraceContext
impl Eq for TraceContext
Source§impl Hash for TraceContext
impl Hash for TraceContext
Source§impl PartialEq for TraceContext
impl PartialEq for TraceContext
impl StructuralPartialEq 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 UnsafeUnpin 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