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 generate() -> TraceCtx
pub fn generate() -> TraceCtx
Create a new trace context with a generated trace ID (UUID v4 hex).
Sourcepub fn from_trace_id(trace_id: impl Into<String>) -> TraceCtx
pub fn from_trace_id(trace_id: impl Into<String>) -> TraceCtx
Create from a raw trace ID string.
Sourcepub fn from_legacy_trace_id(legacy_id: impl Into<String>) -> TraceCtx
pub fn from_legacy_trace_id(legacy_id: impl Into<String>) -> TraceCtx
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>) -> TraceCtx
pub fn with_parent(self, parent_id: impl Into<String>) -> TraceCtx
Set the parent span ID.
Sourcepub fn child(&self, span_id: impl Into<String>) -> TraceCtx
pub fn child(&self, span_id: impl Into<String>) -> TraceCtx
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<TraceCtx, TraceError>
pub fn from_traceparent(header: &str) -> Result<TraceCtx, 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<TraceCtx, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TraceCtx, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for TraceCtx
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 moreSource§impl Serialize for TraceCtx
impl Serialize for TraceCtx
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for TraceCtx
Auto Trait Implementations§
impl Freeze for TraceCtx
impl RefUnwindSafe for TraceCtx
impl Send for TraceCtx
impl Sync for TraceCtx
impl Unpin for TraceCtx
impl UnsafeUnpin for TraceCtx
impl UnwindSafe for TraceCtx
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, D, R> CommandArg<'de, R> for Dwhere
D: Deserialize<'de>,
R: Runtime,
impl<'de, D, R> CommandArg<'de, R> for Dwhere
D: Deserialize<'de>,
R: Runtime,
Source§fn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>
fn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.