feat: add per-request correlation ID to logs#481
Conversation
6f8304f to
a7ffaef
Compare
Generate (or honor inbound X-Request-ID) a request ID per HTTP request, bind a request-scoped logger carrying it in the context, and echo the ID in the response header. All logs for one request now share a request_id field. Threaded through the build path: the request logger is carried into detached/singleflight build contexts (installer image and asset builder) and into schematic Put, so build and create logs keep the originating request_id even after the request returns. Artifacts fetch helpers (behind singleflight, shared across requests) and background htpasswd watcher logs are intentionally left on the construction-time logger. Signed-off-by: Mateusz Urbanek <mateusz.urbanek@siderolabs.com>
a7ffaef to
805c51c
Compare
|
Just FYI, why I am not using OTel instrumentation (yet). The first step for better observability is just a per-request correlation ID in logs ( Full OTel tracing can be the next step, as it needs a TracerProvider, span instrumentation, a collector (Jaeger/Tempo/OTLP), and sampling decisions. More moving parts and an ops dependency. And a final note - the two aren't competing, and I've kept the design somewhat OTel-compatible. All request-scoped logging goes through a single seam ( (Also evaluated the otelzap wrapper - skipping it: it forces a logger-type migration across the codebase to duplicate what our seam already centralizes, and adds nothing until spans actually exist.) |
|
I would rather skip OTel until we really need it, it's so much heavy on its own. Might be nice though for local development/debugging to understand the request flow. |
|
/m |
Generate (or honor inbound X-Request-ID) a request ID per HTTP
request, bind a request-scoped logger carrying it in the context,
and echo the ID in the response header. All logs for one request
now share a request_id field.
Threaded through the build path: the request logger is carried
into detached/singleflight build contexts (installer image and
asset builder) and into schematic Put, so build and create logs
keep the originating request_id even after the request returns.
Artifacts fetch helpers (behind singleflight, shared across
requests) and background htpasswd watcher logs are intentionally
left on the construction-time logger.
Signed-off-by: Mateusz Urbanek mateusz.urbanek@siderolabs.com