Skip to main content

trace_context_middleware

Function trace_context_middleware 

Source
pub async fn trace_context_middleware(req: Request, next: Next) -> Response
Expand description

Middleware that extracts W3C Trace Context from incoming HTTP headers.

When the otel-tracing feature is enabled, this extracts traceparent and tracestate headers and sets the OpenTelemetry context on the current tracing span, enabling distributed tracing across service boundaries.

This middleware should be applied early in the middleware stack (after TraceLayer) so that the extracted context is available for all subsequent handlers.