pub struct TraceCtx {
pub trace_id: String,
pub parent_id: Option<String>,
pub baggage: Vec<BaggageEntry>,
}Expand description
In-process trace context for cross-crate correlation.
Wraps a W3C-compatible trace ID and optional parent span ID. Additional bounded baggage can be attached for cross-boundary metadata.
Fields§
§trace_id: StringThe trace ID (W3C: 32 hex chars, or any opaque string for legacy compat).
parent_id: Option<String>Optional parent span ID (W3C: 16 hex chars).
baggage: Vec<BaggageEntry>Bounded baggage for cross-boundary metadata. Keys and values must be short ASCII strings. No sensitive data.
Implementations§
Source§impl TraceCtx
impl TraceCtx
Sourcepub fn from_trace_id(trace_id: impl Into<String>) -> Self
pub fn from_trace_id(trace_id: impl Into<String>) -> Self
Create from a raw trace ID string.
Sourcepub fn from_legacy_trace_id(legacy_id: impl Into<String>) -> Self
pub fn from_legacy_trace_id(legacy_id: impl Into<String>) -> Self
Create from a legacy TraceId(String) value for migration compatibility.
Phase status: compatibility / migration-only
Sourcepub fn to_legacy_trace_id(&self) -> &str
pub fn to_legacy_trace_id(&self) -> &str
Extract the trace ID as a string for legacy interop.
Phase status: compatibility / migration-only
Sourcepub fn with_parent(self, parent_id: impl Into<String>) -> Self
pub fn with_parent(self, parent_id: impl Into<String>) -> Self
Set the parent span ID.
Sourcepub fn child(&self, span_id: impl Into<String>) -> Self
pub fn child(&self, span_id: impl Into<String>) -> Self
Create a child context: same trace ID, new parent.
Sourcepub fn add_baggage(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> Result<(), TraceError>
pub fn add_baggage( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> Result<(), TraceError>
Add a baggage entry. Returns Err if limits are exceeded.
Sourcepub fn baggage_value(&self, key: &str) -> Option<&str>
pub fn baggage_value(&self, key: &str) -> Option<&str>
Get a baggage value by key.
Sourcepub fn to_traceparent(&self) -> Result<String, TraceError>
pub fn to_traceparent(&self) -> Result<String, TraceError>
Format as a W3C traceparent header.
Format: 00-{trace_id}-{parent_id}-01
If the trace ID is not exactly 32 hex chars (e.g., a legacy opaque string),
it is converted via deterministic BLAKE3 hash truncation using
hash_to_w3c_trace_id. Padding and truncation are forbidden.
If no parent ID exists, a zero span ID is used. Non-compliant parent IDs (not 16 hex chars) are rejected.
Sourcepub fn from_traceparent(header: &str) -> Result<Self, TraceError>
pub fn from_traceparent(header: &str) -> Result<Self, TraceError>
Parse from a W3C traceparent header.
Format: {version}-{trace_id}-{parent_id}-{flags}
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TraceCtx
impl<'de> Deserialize<'de> for TraceCtx
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for TraceCtx
impl JsonSchema for TraceCtx
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read more