pub struct SpanCtxt { /* private fields */ }Expand description
The trace id, span id, and parent span id of a span.
These ids can be used to identify the distributed trace a span belongs to, and to identify the span itself within that trace.
The SpanCtxt for the currently executing span can be pulled from the ambient context with SpanCtxt::current. Once a SpanCtxt is constructed, a new child context can be generated by SpanCtxt::new_child.
SpanCtxt should be pushed onto the ambient context with SpanCtxt::push so any events emitted during its execution are correlated to it.
Implementations§
Source§impl SpanCtxt
impl SpanCtxt
Sourcepub const fn new(
trace_id: Option<TraceId>,
span_parent: Option<SpanId>,
span_id: Option<SpanId>,
) -> Self
pub const fn new( trace_id: Option<TraceId>, span_parent: Option<SpanId>, span_id: Option<SpanId>, ) -> Self
Create the context from a set of identifiers.
The trace_id and span_id should both be Some, but span_parent may be None if the span is at the root of the distributed trace.
If trace_id or span_id are None then the context is invalid, but can still be used.
Sourcepub fn current(ctxt: impl Ctxt) -> Self
pub fn current(ctxt: impl Ctxt) -> Self
Read the current context from an ambient Ctxt.
This method will pull the TraceId from KEY_TRACE_ID, the SpanId from KEY_SPAN_ID, and the parent SpanId from KEY_SPAN_PARENT.
Sourcepub fn new_child(&self, rng: impl Rng) -> Self
pub fn new_child(&self, rng: impl Rng) -> Self
Generate a new context that is a child of self.
The new context will share the same trace id as self, use the span id of self as its parent span id, and generate a new random span id as its own through SpanId::random.
If Self::trace_id is None then a new trace id will be generated through TraceId::random.
Sourcepub fn span_parent(&self) -> Option<&SpanId>
pub fn span_parent(&self) -> Option<&SpanId>
Get the parent of the span.
Trait Implementations§
Source§impl Props for SpanCtxt
impl Props for SpanCtxt
Source§fn for_each<'kv, F: FnMut(Str<'kv>, Value<'kv>) -> ControlFlow<()>>(
&'kv self,
for_each: F,
) -> ControlFlow<()>
fn for_each<'kv, F: FnMut(Str<'kv>, Value<'kv>) -> ControlFlow<()>>( &'kv self, for_each: F, ) -> ControlFlow<()>
Source§fn get<'v, K>(&'v self, key: K) -> Option<Value<'v>>where
K: ToStr,
fn get<'v, K>(&'v self, key: K) -> Option<Value<'v>>where
K: ToStr,
Source§fn pull<'kv, V, K>(&'kv self, key: K) -> Option<V>
fn pull<'kv, V, K>(&'kv self, key: K) -> Option<V>
V. Read more