Skip to main content

TraceContext

Struct TraceContext 

Source
pub struct TraceContext { /* private fields */ }
Expand description

A W3C trace context: the distributed-trace identity the proxy propagates downstream. Continued from an incoming traceparent when present (preserving the trace_id so the trace stays connected end-to-end), or minted as a new root when absent. Either way a fresh span_id identifies this hop, so the upstream call is recorded as a child of the proxy’s span.

It also retains the incoming parent’s span id (when continuing a trace), so the proxy’s own emitted span can be recorded as a child of the caller’s span; a freshly minted root has no parent.

Not Copy: it carries an optional owned tracestate (the vendor list the proxy forwards verbatim), so it is cloned where a batch fans one context across many ops.

Implementations§

Source§

impl TraceContext

Source

pub fn propagate( incoming_traceparent: Option<&str>, incoming_tracestate: Option<&str>, request: &RequestId, ) -> Self

Continues incoming_traceparent if it is present and well-formed, else mints a new root trace. A fresh span_id for this hop is always derived from request, so the downstream call chains under the proxy’s span.

incoming_tracestate (the W3C vendor list) is forwarded verbatim, but only when continuing a trace and only when within spec bounds, a tracestate without a valid traceparent is meaningless and is dropped.

Source

pub fn propagate_with_b3( incoming_traceparent: Option<&str>, incoming_tracestate: Option<&str>, incoming_b3: Option<&str>, request: &RequestId, ) -> Self

Like propagate, but also continues a caller that arrived with a B3 context (Zipkin/Istio, b3 single-header form) when no W3C traceparent is present. W3C wins when both are supplied. This keeps the trace connected end to end for a B3-native client even though the proxy itself speaks W3C downstream: the caller’s trace_id is preserved, so the proxy’s exported span shares the client’s trace rather than starting a new root. B3 carries no tracestate, so a B3-continued context forwards none.

Source

pub fn parse_b3(value: &str) -> Option<Self>

Parses a B3 single-header value ({trace}-{span}[-{sampled}[-{parent}]], the Zipkin/Istio form). The trace id is 128- or 64-bit (32 or 16 hex, the 64-bit form right-aligned into 128 bits, per the B3 spec); the span id is 64-bit (16 hex). A sampling-only b3 (0/1/d with no ids) carries no trace to continue and returns None, as does any malformed or all-zero id.

Source

pub fn parse(value: &str) -> Option<Self>

Parses a W3C traceparent value (00-<32hex>-<16hex>-<2hex>). Returns None if it is malformed, an unsupported version, or has an all-zero trace/span id (which the spec forbids), the caller then mints a root.

Source

pub fn to_traceparent(&self) -> String

The traceparent header value to send to the upstream.

Source

pub fn trace_id_hex(&self) -> String

The 32-hex trace id, for correlating this request’s logs / /debug/explain with the distributed trace. An identifier, never a value.

Source

pub fn span_id_hex(&self) -> String

The 16-hex span id of the proxy’s hop, the id presented as the parent to downstream calls, and therefore the id of the span the proxy must emit so the upstream’s spans nest under it.

Source

pub fn parent_span_id_hex(&self) -> Option<String>

The 16-hex span id of the caller’s span, the parent the proxy’s own span nests under, or None when this context is a freshly minted root (no incoming traceparent).

Source

pub fn to_tracestate(&self) -> Option<&str>

The W3C tracestate value to forward to the upstream, if the request carried a valid one, passed through verbatim (the proxy adds no entry).

Source

pub fn sampled(&self) -> bool

Whether the trace is sampled (the W3C sampled flag).

Trait Implementations§

Source§

impl Clone for TraceContext

Source§

fn clone(&self) -> TraceContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TraceContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for TraceContext

Source§

impl PartialEq for TraceContext

Source§

fn eq(&self, other: &TraceContext) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TraceContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.