pub struct TraceContext {
pub trace_id: TraceId,
pub span_id: SpanId,
pub flags: SamplingFlags,
}Expand description
A parsed W3C traceparent header value.
Holds a TraceId, a SpanId, and SamplingFlags. Only spec version
00 is accepted; future versions with extra fields will be rejected.
§Parsing
use api_bones::traceparent::{TraceContext, SamplingFlags};
let tc: TraceContext =
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
.parse()
.unwrap();
assert!(tc.flags.is_sampled());§Serialization
Display produces the canonical traceparent string which can be used
directly as an HTTP header value.
Fields§
§trace_id: TraceId128-bit trace identifier.
span_id: SpanId64-bit parent span identifier.
flags: SamplingFlagsSampling and other flags.
Implementations§
Source§impl TraceContext
impl TraceContext
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new TraceContext with fresh random IDs and the sampled flag
set.
use api_bones::traceparent::TraceContext;
let tc = TraceContext::new();
assert!(tc.flags.is_sampled());Sourcepub fn child_span(&self) -> Self
pub fn child_span(&self) -> Self
Create a new child span — same trace_id, new span_id.
use api_bones::traceparent::TraceContext;
let parent = TraceContext::new();
let child = parent.child_span();
assert_eq!(child.trace_id, parent.trace_id);
assert_ne!(child.span_id, parent.span_id);Sourcepub fn header_value(&self) -> String
pub fn header_value(&self) -> String
Produce the canonical traceparent header value string.
Equivalent to self.to_string().
Sourcepub fn header_name(&self) -> &'static str
pub fn header_name(&self) -> &'static str
The canonical HTTP header name: traceparent.
use api_bones::traceparent::TraceContext;
let tc = TraceContext::new();
assert_eq!(tc.header_name(), "traceparent");Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§fn clone(&self) -> TraceContext
fn clone(&self) -> TraceContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TraceContext
impl Debug for TraceContext
Source§impl Default for TraceContext
impl Default for TraceContext
Source§impl<'de> Deserialize<'de> for TraceContext
Available on crate feature serde only.
impl<'de> Deserialize<'de> for TraceContext
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for TraceContext
impl Display for TraceContext
Source§impl FromStr for TraceContext
impl FromStr for TraceContext
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse a traceparent header value.
Only version 00 is accepted. Extra fields beyond the four standard
ones are rejected per spec (future-version compatibility is the
caller’s responsibility).
Source§type Err = TraceContextError
type Err = TraceContextError
Source§impl Hash for TraceContext
impl Hash for TraceContext
Source§impl HeaderId for TraceContext
Available on crate feature std only.
impl HeaderId for TraceContext
std only.Source§impl PartialEq for TraceContext
impl PartialEq for TraceContext
Source§impl Serialize for TraceContext
Available on crate feature serde only.
impl Serialize for TraceContext
serde only.