pino-http
pino-http copied to clipboard
Docs: `req.id`
This module reads from req.id
:
https://github.com/pinojs/pino-http/blob/ef7b7e4fdfad2d914597b622a428b375ed15b563/logger.js#L98
However this property doesn't seem to be documented anywhere. It's not something provided by Express, for example.
Could we add some docs to specify what this is for and how to use it along with this module? I suspect it can be used like this:
app.use((req, _res, next) => {
req.id = req.get('x-request-id');
next();
});
app.use(expressPinoLogger);
Then Pino will infer the request ID from the req.id
we defined.
The same thing can be achieved with the genReqId
option, however this also overrides the fallback for when x-request-id
/req.id
is not defined, which is not always desired. (For context, we want to use x-request-id
when it's defined, otherwise use Pino's own request IDs.)
Feel free to send a PR with the docs, it would be handy!