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
impl TraceContext
Sourcepub fn propagate(
incoming_traceparent: Option<&str>,
incoming_tracestate: Option<&str>,
request: &RequestId,
) -> Self
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.
Sourcepub fn propagate_with_b3(
incoming_traceparent: Option<&str>,
incoming_tracestate: Option<&str>,
incoming_b3: Option<&str>,
request: &RequestId,
) -> Self
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.
Sourcepub fn parse_b3(value: &str) -> Option<Self>
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.
Sourcepub fn parse(value: &str) -> Option<Self>
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.
Sourcepub fn to_traceparent(&self) -> String
pub fn to_traceparent(&self) -> String
The traceparent header value to send to the upstream.
Sourcepub fn trace_id_hex(&self) -> String
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.
Sourcepub fn span_id_hex(&self) -> String
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.
Sourcepub fn parent_span_id_hex(&self) -> Option<String>
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).
Sourcepub fn to_tracestate(&self) -> Option<&str>
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).
Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§fn clone(&self) -> TraceContext
fn clone(&self) -> TraceContext
1.0.0 (const: unstable) · 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
impl Eq for TraceContext
Source§impl PartialEq for TraceContext
impl PartialEq for TraceContext
Source§fn eq(&self, other: &TraceContext) -> bool
fn eq(&self, other: &TraceContext) -> bool
self and other values to be equal, and is used by ==.