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
11
12
13
14
15
16
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.