context
Basic trace context foundation for observability core
Provides W3C trace context implementation and basic context management ports. Domain-specific implementations (LLM, A2A, etc.) are provided by higher-level crates.
Structs
Section titled “Structs”W3CTraceContext
Section titled “W3CTraceContext”W3C Trace Context implementation for distributed tracing
Fields
| Field | Type | Description |
|---|---|---|
trace_id | String | W3C trace ID (32 hex characters) |
parent_id | String | W3C span ID (16 hex characters) |
trace_flags | String | Trace flags (2 hex characters) |
trace_state | Option<String> | Additional trace state |
Methods
new_root
Section titled “new_root”fn new_root() -> SelfCreate a new root trace context
new_child
Section titled “new_child”fn new_child(&self) -> SelfCreate a child span context
from_traceparent
Section titled “from_traceparent”fn from_traceparent(header: &str) -> ObservabilityResult<Self>Create from W3C traceparent header
from_headers
Section titled “from_headers”fn from_headers(headers: &HashMap<String, String>) -> ObservabilityResult<Option<Self>>Create from W3C headers
to_traceparent
Section titled “to_traceparent”fn to_traceparent(&self) -> StringGenerate W3C traceparent header value
to_headers
Section titled “to_headers”fn to_headers(&self) -> HashMap<String, String>Generate W3C headers for propagation
is_sampled
Section titled “is_sampled”fn is_sampled(&self) -> boolCheck if the trace is sampled
set_sampled
Section titled “set_sampled”fn set_sampled(&mut self, sampled: bool)Set sampling flag
add_trace_state
Section titled “add_trace_state”fn add_trace_state(&mut self, key: &str, value: &str)Add or update trace state
get_trace_state
Section titled “get_trace_state”fn get_trace_state(&self, key: &str) -> Option<String>Get value from trace state
TraceContext
Section titled “TraceContext”Simplified trace context for internal use
Fields
| Field | Type | Description |
|---|---|---|
trace_id | String | |
span_id | String | |
parent_span_id | Option<String> | |
sampled | bool |
Methods
new_root
Section titled “new_root”fn new_root() -> SelfCreate a new root trace context
new_child
Section titled “new_child”fn new_child(&self) -> SelfCreate a child span
to_w3c
Section titled “to_w3c”fn to_w3c(&self) -> W3CTraceContextConvert to W3C trace context
from_w3c
Section titled “from_w3c”fn from_w3c(w3c: &W3CTraceContext) -> SelfCreate from W3C trace context
ContextFuture
Section titled “ContextFuture”Future wrapper that restores trace context across async poll boundaries.
HeaderInjector
Section titled “HeaderInjector”Header injector for W3C trace context propagation
Methods
inject
Section titled “inject”fn inject(&mut self, context: &W3CTraceContext)HeaderExtractor
Section titled “HeaderExtractor”Header extractor for W3C trace context propagation
Methods
extract
Section titled “extract”fn extract(&self) -> ObservabilityResult<Option<W3CTraceContext>>Functions
Section titled “Functions”set_current_context
Section titled “set_current_context”fn set_current_context(context: TraceContext)Set the current trace context for this thread
get_current_context
Section titled “get_current_context”fn get_current_context() -> Option<TraceContext>Get the current trace context for this thread
clear_current_context
Section titled “clear_current_context”fn clear_current_context()Clear the current trace context
with_context
Section titled “with_context”fn with_context<F, R>(context: TraceContext, f: F) -> Rwhere F: FnOnceExecute a function with a specific trace context
with_context_future
Section titled “with_context_future”fn with_context_future<F>(context: TraceContext, future: F) -> ContextFuture<F>where F: FutureExecute a future with a specific trace context re-applied on every poll.