Expand description
W3C Trace Context (traceparent) propagation
A request that crosses several services is only debuggable when every service
logs the same trace id. TraceLayer reads the incoming traceparent
header (or starts a new trace), gives the request its own span, and makes the
ids available to handlers, the access log and outgoing calls:
use ullun::client::HttpClient;
use ullun::prelude::*;
use ullun::trace::TraceLayer;
App::new()
.middleware(TraceLayer::new())
.get("/orders", |req: Request| async move {
// the call below carries the same trace id; the callee's parent is this span
let upstream = HttpClient::new()
.get("http://inventory.internal/stock")
.trace(&req)
.send()
.await?;
Ok(Response::text(upstream.text()?))
})
.run("127.0.0.1:3000")
.await
.unwrap();AccessLog adds trace=<id> (text) or
trace_id (JSON) to its lines when the layer is installed. This is the
propagation half of distributed tracing, without an exporter: ship the ids
with your logs, or read Request::trace from your own OpenTelemetry glue.
Facing the internet, use TraceLayer::ignore_incoming so callers cannot
choose your trace ids.
Structsยง
- Trace
Context - Trace identity of the current request, stored in
Request::extensions - Trace
Layer - Middleware that continues or starts a W3C trace