fastify-sentry icon indicating copy to clipboard operation
fastify-sentry copied to clipboard

Add e custom hook to allow to add custom data

Open dnlup opened this issue 3 years ago • 7 comments

I think it would be nice to expose an option to pass a custom function that can be used to enrich the event with custom data.

dnlup avatar Nov 18 '22 10:11 dnlup

@dnlup would that be something like the previous version that could allow us to run scope.setTag in a custom error handler?

gabrielfernandes-codes avatar Nov 18 '22 13:11 gabrielfernandes-codes

@fernandesGabriel Yes, I imagined the function could be useful to add more info, like the tags you are mentioning. The only difference with the previous version of the plugin would be that you don't need to implement a custom handler.

dnlup avatar Nov 21 '22 09:11 dnlup

That would be perfect @dnlup, I just upgraded to the new version of the plugin, and just noticed that we also have the use case you mention here.

gabrielfernandes-codes avatar Nov 21 '22 09:11 gabrielfernandes-codes

@fernandesGabriel I was thinking, wouldn't the beforeSend (the SDK one) option be enough for this use case?

dnlup avatar Dec 16 '22 08:12 dnlup

Chiming in that this would be great to have as well! Either a way to expose beforeSend, or a way to expose adding custom context to errors

noahsark769 avatar Jan 21 '23 16:01 noahsark769

The workaround for now is to use beforeSend as mentioned above:

void app.register(fastifySentryPlugin, {
  dsn: "...",
  ...,
  beforeSend(event, hint) {
    // Can do custom processing based on `hint.originalException`
    return {
      ...event,
      extra: {
        ...event.extra,
        hello: "world"
      },
    };
  },

That hello: "world" will show up under "Additional Data" in Sentry 👍

noahsark769 avatar Jan 21 '23 16:01 noahsark769

Thanks @noahsark769 for the feedback. So maybe something that allows us to use the scope api instead of manipulating the raw event should be what we are looking for.

dnlup avatar Jan 24 '23 10:01 dnlup