Less Annoying Sidekiq Bugsnag Errors

Curated ago by @pelargir

Description

This middleware makes Bugsnag ignore network connection errors raised from Sidekiq jobs. Instead of reporting errors to Bugsnag every time the job retries, we only report these errors if/when the job finally dies. The goal is to eliminate extra noise caused by transient network errors.

1
2
3
4
5
6
7
8
9
10
class BugsnagSidekiqDeathHandler
  def self.handler
    ->(_job, exception) do
      # The <= operator returns true if the class on the left is the same as OR a subclass of the class on the right
      if BugsnagSidekiqMiddleware::IGNORED_EXCEPTIONS.any? { |e| exception.class <= e }
        Bugsnag.notify(exception)
      end
    end
  end
end

This is what actually triggers the report to Bugsnag when a Sidekiq job dies. If the exception was previously ignored by the middleware, we notify Bugsnag at this point.