
Track Every Request Across Node.js Services with pino-correlation-id
Track Every Request Across Node.js Services with pino-correlation-id You have structured logs. You have pino configured with pretty print in dev and JSON in prod. But when an error fires, you open Grafana Loki and search for the request that caused it — and you're staring at hundreds of log lines from twenty concurrent requests, all mixed together, with zero way to isolate the trace for the one that failed. This is the correlation ID problem. Every distributed system that takes production seriously solves it. Here's the Node.js solution that takes five minutes to wire up. Why Correlation IDs Break in Async Node.js The classic approach — attach a reqId to the request object and pass it around — falls apart the moment you go async. Your route handler calls a service, which calls a repository, which runs a database query. Each layer is a separate function. You either pass req.log as a parameter through every single function signature, or you lose the ID. Neither option is acceptable at sc
Continue reading on Dev.to JavaScript
Opens in a new tab



