bugsnag / bugsnag-ruby

BugSnag error monitoring & reporting software for rails, sinatra, rack and ruby
https://docs.bugsnag.com/platforms/ruby
MIT License
246 stars 174 forks source link

skip_bugsnag is not functioning #791

Closed jibiking closed 11 months ago

jibiking commented 12 months ago

Describe the bug

The description in the official documentation states that even when using the "skip_bugsnag" configuration, notifications to Bugsnag are not stopping. Has the bug in this issue not been resolved? https://github.com/bugsnag/bugsnag-ruby/issues/470

Steps to reproduce

sample code↓

    begin
      raise StandardError
    rescue StandardError => exception

      Bugsnag.notify(exception)
      exception.instance_eval { def skip_bugsnag; true; end }

      raise ActionController::RoutingError, 'not_found'
    end

Environment

imjoehaines commented 11 months ago

Hey, @jibiking

skip_bugsnag works on the specific instance of the exception you apply it to. In your example you're applying it to exception but raising a RoutingError afterwards. That means that the RoutingError doesn't have skip_bugsnag applied to it, which results in it being reported to Bugsnag

To make it work you'd need to apply skip_bugsnag to the RoutingError before raising it, like this:

begin
  raise StandardError
rescue StandardError => exception
  Bugsnag.notify(exception)

  routing_error = ActionController::RoutingError.new('not_found')
  routing_error.instance_eval { def skip_bugsnag; true; end }

  raise routing_error
end

If you want to ignore all RoutingError exceptions, take a look at the discard_classes configuration option

Hope that helps!