puzpuzpuz / cls-rtracer

Request Tracer - CLS-based request id generation for Express, Fastify, Koa and Hapi, batteries included
MIT License
311 stars 24 forks source link

Fastify Pino logger integration sample #46

Closed YuriGal closed 3 years ago

YuriGal commented 3 years ago

Not an issue, but rather request. Fastify already uses Pino under the hood as de facto logger. I am struggling to integrate cls-tracer with Pino in Fastify, so far without success. Would it be possible to provide an example of using cls-traces with Pino in fastify?

crccheck commented 3 years ago

I don't know Fastify, but maybe something like this in your Pino config:

  mixin() {
    return { request_id: rTracer.id() };
  },

https://github.com/pinojs/pino/blob/master/docs/api.md#mixin-function

puzpuzpuz commented 3 years ago

Thanks for creating this issue. I was thinking of adding a sample for Pino, but didn't find the time to do this yet. Not sure if I find the time in the nearest future, so contributions are welcome (as always).