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.
class BugsnagSidekiqMiddleware IGNORED_EXCEPTIONS = ActiveUtils::NetworkConnectionRetries::DEFAULT_CONNECTION_ERRORS.keys def initialize(bugsnag) @bugsnag = bugsnag end def call(report) # The <= operator returns true if the class on the left equals OR is a subclass of the class on the right if report.meta_data[:sidekiq] && IGNORED_EXCEPTIONS.any? { |e| report.original_error.class <= e } report.ignore! end @bugsnag.call(report) end end
This middleware ignores certain network exceptions generated from Sidekiq jobs.