immobiliare/fastify-sentry

How to prevent filtered log output to the console?

meotimdihia opened this issue · 6 comments

  fastify.register(fastifySentry, {
    shouldHandleError(error, request, reply) {
      if (error.name == 'NotFoundError') { 
        return false
      }
      return true
    }
)

I want to filter these logs in the console as well:

image

dnlup commented

Hi @meotimdihia ! The shouldHandle function should filter error events that the Sentry SDK sends to your Sentry instance, it doesn't have nothing to do with the errors logged on stdout. You can prevent something logged on stdout maybe using the log level configuration of the fastify logger.

dnlup commented

Looking at what we do in the plugin here, we log the error anyway. This is consistent to what the default error handler in fastify does. As far as I know though, it doesn't log 404 with an error level, I suspect that this might be caused by the use of @fastify/sensible? Are you able to try the same thing without using the plugin error handler and see if the error is logged anyway?

dnlup commented

I am not sure how I feel about making the plugin filter error logs , I don't think it can be done via logger setting either, see https://getpino.io/#/docs/help?id=log-filtering.

@dnlup thanks, I'll investigate the problem further.
I guess it is not related to this plugin :)

dnlup commented

One last thing, you can use a custom error handler instead of the one provided by the plugin and filter the logs however it's needed by your application.

dnlup commented

@dnlup thanks, I'll investigate the problem further. I guess it is not related to this plugin :)

No problem 😉