pub struct TraceContext { /* private fields */ }Expand description
The W3C Trace Context a client sent in a request’s _meta.
Obtain one from
RequestContext::trace_context,
or parse a value directly with TraceContext::parse. See the
module documentation for the parsing rules.
Implementations§
Source§impl TraceContext
impl TraceContext
Sourcepub fn parse(traceparent: &str, tracestate: Option<&str>) -> Option<Self>
pub fn parse(traceparent: &str, tracestate: Option<&str>) -> Option<Self>
Parse a traceparent value and an optional tracestate value.
Returns None when traceparent is malformed. An invalid
tracestate is dropped and the traceparent is kept.
Sourcepub fn from_meta(meta: &Value) -> Option<Self>
pub fn from_meta(meta: &Value) -> Option<Self>
Read the trace context from a request’s _meta object.
Returns None when meta is not an object or has no traceparent.
A traceparent that is present but not a well-formed string discards
both keys and emits a debug-level event. A tracestate that is not a
string reads as absent.
Sourcepub fn parent_id(&self) -> &str
pub fn parent_id(&self) -> &str
The caller’s span id (parent-id): 16 lowercase hex digits, never all
zeros. The server’s own span is a child of this one.
Sourcepub fn trace_flags(&self) -> u8
pub fn trace_flags(&self) -> u8
The raw trace-flags byte.
Sourcepub fn tracestate(&self) -> Option<&str>
pub fn tracestate(&self) -> Option<&str>
The raw tracestate string, if one was sent and it passed the length
and member-count limits.
Sourcepub fn traceparent(&self) -> String
pub fn traceparent(&self) -> String
The traceparent value for this context, formatted as
version-trace-id-parent-id-trace-flags.
A context parsed from a later traceparent version formats with that
version and its first four fields only; trailing fields are not kept.
Sourcepub fn entries(&self) -> impl Iterator<Item = (&'static str, String)> + '_
pub fn entries(&self) -> impl Iterator<Item = (&'static str, String)> + '_
The _meta entries that carry this context: traceparent, then
tracestate when there is one.
These are the exact key names the server reads, and the same pairs are
what an OpenTelemetry TextMapPropagator reads from or writes to a
carrier, so they can be collected into a HashMap<String, String> for
extract.
use tower_mcp::TraceContext;
let ctx = TraceContext::parse(
"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
Some("vendor=value"),
)
.unwrap();
let entries: Vec<_> = ctx.entries().collect();
assert_eq!(entries[0].0, "traceparent");
assert_eq!(entries[1], ("tracestate", "vendor=value".to_string()));Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§impl Debug for TraceContext
impl Debug for TraceContext
impl Eq 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.