Skip to main content

correlation_middleware

Function correlation_middleware 

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

Bind the request’s correlation id for the writes it makes, so the events they stage (and the logs and audit rows of the request) share one id.

A composing service that already attributes the request (its guard binds a RequestAuditContext carrying the correlation id, which it echoes on the response) is left alone: that id is the one the hooks read, so events, audit rows and the response header agree. Otherwise the id is the request’s x-correlation-id header when it carries a usable one (printable ASCII, at most 128 characters), else a fresh uuid. The generic write routes and the generated transition routes carry this layer; a hand-written route that writes through the service can add it with axum::middleware::from_fn.