Skip to main content

extract_and_set_trace_context

Function extract_and_set_trace_context 

Source
pub fn extract_and_set_trace_context(
    meta: Option<&Meta>,
    client_meta: ClientMetadata,
)
Expand description

Extract W3C Trace Context from MCP request _meta field and set as parent span context.

Attempts to extract traceparent and tracestate from the request’s _meta field. If successful, calls set_parent on the current tracing span so the OTel layer re-parents it to the caller’s trace. This must be called after the #[instrument] span has been entered (i.e., inside the function body) for set_parent to take effect. If extraction fails or _meta is absent, silently proceeds with root context (no panic).