Description
Feature Request:
Pass back the original Fastify request when invoking the callback.
Details:
I'd like to use a single default onRequestClosed
callback to handle all aborted requests. When this callback is invoked, I'd like to have access to the underlying Fastify request object if possible.
Alternatively, maybe there is a way to use this plugin in combination with Fastify's built-in request lifecycle hooks to achieve a similar result. (If this works, maybe a quick example in the docs would be helpful to others heading down a similar path)
Background
Fastify provides separate request/response logging out-of-the-box. In our environment, we found by combining the request / response logs - troubleshooting issues based on log data was much easier. Overall this approach works well, but I recently discovered that our current approach will not log request information during a client abort. (This is how I eventually discovered fastify-racing plugin....thanks!)
Our current logging setup:
fastifyInstance.addHook("onRequest", (req, reply, done) => {
// track overall response time
reply.startTime = Date.now();
done();
});
// use hook based logging instead of internal logger to provide a single
// combined log message per-request, instead of the default request/reply
// logging
fastifyInstance.addHook('onResponse', (req: FastifyRequest, res: FastifyReply) => {
if (req.url === healthEndpoint) {
logger.info({
req,
res
});
} else {
logger.info({
req,
res
});
}
});