Node.js Logging Made Right

Node.js Logging Made Right

Within this article we’ll overview how we can create these trace IDs (meaning we’re going to briefly examine how continuation local storage a.k.a CLS works) and dig deep into how we can utilize Proxy to make it work with ANY logger. It removes the context from our map of contexts by its async ID (it’s the same as current execution ID of our first callback). So the idea is to generate a random trace ID for each request and create a child pino logger with the trace ID and put it in CLS.

Source: itnext.io