Skip to main content

request_context_layer

Function request_context_layer 

Source
pub fn request_context_layer() -> RequestContextLayer
Expand description

Creates a Tower layer that enriches RequestContext request extensions.

Use this with crate::middleware::validated_request_id_layer so handlers can extract RequestContext. The request ID layer chooses and stores the final ID; this layer rebuilds the context from request parts so correlation, trace, route, and client-kind fields reflect the current request boundary. crate::middleware::ApiDefaults::production installs both layers.

If no prior context or x-request-id header exists, the context uses "unknown" as the request ID. Prefer validated request IDs for production APIs.