Eomm / mercurius-logging

Log the GraphQL details
MIT License
15 stars 2 forks source link

Response Time not displaying in Logs #28

Closed flowjo-isaach closed 1 year ago

flowjo-isaach commented 1 year ago

I'm hoping to display the response time for resolved fields and the requests from graphQL. I don't see this information in this module. Is there a configuration I'm missing or does it not exist?

Eomm commented 1 year ago

It doesn't exist: this plugin shows what comes in the server and does not count the time each resolver takes.

This plugin's scope is to understand:

so you can drop API or support your customer better and proactively.

For time tracking I suggest:

  1. take a look at this plugin instead: https://github.com/nearform/mercurius-explain
  2. Group the log data by reqId: you have already multiple log lines for a single request. Merging the logline from this plugin and the default fastify response log with the reqId, you can get the total request time
EDjur commented 6 months ago

Just want to add perhaps a simpler approach,

You can utilize the logMessage function and Fastifys built-in elapsedTime like so:

fastify.register(mercuriusLogging, {
    logMessage: function (context) {
        return `RequestDuration: ${context.reply.elapsedTime}`;
    }
});

Unfortunately it'll put the duration under the message key in the request, but is great for its simplicity 👍