Context: I'm interested in request and response timings.
The first approach to know when a request is managed by Fastify is to add a hook like:
fastify.addHook('onRequest', (request, reply, done) => {
request.onRequestTimestamp = Date.now();
done();
});
But the information is already there: enabling Fastify logs
fastify = fastify({ logger: true });
We can see for example
{
"level": 30,
"time": 1620659712059,
"pid": 5673,
"hostname": "myhostname",
"reqId": "req-1",
"res": { "statusCode": 200 },
"responseTime": 14.528815001249313,
"msg": "request completed"
}
So I suppose Fastify itself stores at least the information of when the request reached the HTTP server somewhere, but I can't find where.
Questions:
1- How does Fastify calculate the responseTime?
2- Does Fastify store (probably in the request object) the request timestamp?