'How to add tracking id for each request in fastify?

Im using fastify as backend of my app. I also using pino logger.

const fastify = require('fastify')({
logger: true
})

I need that every time Im writing fastify.log.info("something") I need to see the log (in my terminal) with some trackingId. Like {message: something, trackingId: 123}. The tracking id should be the same throughout the request.

I tried to find how to do this in fastify logger docs and pino logger without success.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source