bugsnag-ruby icon indicating copy to clipboard operation
bugsnag-ruby copied to clipboard

Callback that always runs, regardless of whether report should be ignored?

Open stitchfixsam opened this issue 5 years ago • 2 comments

Description

The underlying motivation: I'd like to ignore certain exceptions via discard_classes but nonetheless report information about them to a metrics store (e.g. if I see FooException, we shouldn't report it to Bugsnag but should tell Prometheus, Datadog, or whatever).

In implementing this, I discovered that notify bails out before the add_on_error code runs when that exception is marked to be ignored. This, of course, makes good sense! But also blocks what I was trying to do.

So basically, I'd like to see if we could add a hook that runs, regardless of whether exception is marked to be ignored, whether the release stage is marked to be ignored, and so on.

I'm happy to do the legwork on this one if you all are ok with adding it to the library.

I'd also love to be told that this is possible through other means that I don't know about!

Describe the solution you'd like

Re-institute configuration.before_notify_callbacks or some other hook that lets you run arbitrary code against a report prior to the filtering process.

Describe alternatives you've considered

  • Using add_on_error: doesn't work AFAICT, since notify bails before it hits the callbacks
  • Adding user middleware: doesn't work AFAICT, since notify bails before it hits the callbacks
  • Doing this outside of the bugsnag-ruby library is certainly plausible, but I wanted to see if we might get it in here.

stitchfixsam avatar Dec 07 '20 21:12 stitchfixsam

Hi @stitchfixsam

What we'd recommend for your scenario it to not use discard_classes but instead store your own list of classes to discard. Then in add_on_error once you've run your other code return false if the exception class is in your own list to prevent it being reported to Bugsnag.

Keeping this issue open though as we may be able to support this a better way within bugsnag-ruby in the future.

mattdyoung avatar Dec 11 '20 15:12 mattdyoung

@mattdyoung clever! I'll give it a go. Thanks for the reply, and please do @ me if you need hands to implement the feature in due time.

stitchfixsam avatar Dec 11 '20 18:12 stitchfixsam