Sha256: b9251194390e6a9a4e8bc0e1371272591c3fb68260a663cfb95dd6dbf5f4bcc8

Contents?: true

Size: 1.59 KB

Versions: 23

Compression:

Stored size: 1.59 KB

Contents

require 'rollbar/scrubbers/params'

module Rollbar
  class Sidekiq
    PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class].freeze

    class ClearScope
      def call(_worker, _msg, _queue)
        Rollbar.reset_notifier!

        yield
      end
    end

    def self.handle_exception(ctx_hash, e)
      job_hash = ctx_hash && (ctx_hash[:job] || ctx_hash)
      return if skip_report?(job_hash, e)

      scope = {
        :framework => "Sidekiq: #{::Sidekiq::VERSION}"
      }
      unless job_hash.nil?
        params = job_hash.reject { |k| PARAM_BLACKLIST.include?(k) }
        scope[:request] = { :params => scrub_params(params) }
        scope[:context] = params['class']
        scope[:queue] = params['queue']
      end

      Rollbar.scope(scope).error(e, :use_exception_level_filters => true)
    end

    def self.scrub_params(params)
      options = {
        :params => params,
        :config => Rollbar.configuration.scrub_fields
      }

      Rollbar::Scrubbers::Params.call(options)
    end

    def self.skip_report?(job_hash, _e)
      return false if job_hash.nil?

      # when rollbar middleware catches, sidekiq's retry_job processor hasn't set
      # the retry_count for the current job yet, so adding 1 gives the actual retry count
      actual_retry_count = job_hash.fetch('retry_count', -1) + 1
      job_hash['retry'] && actual_retry_count < ::Rollbar.configuration.sidekiq_threshold
    end

    def call(_worker, msg, _queue)
      Rollbar.reset_notifier!

      yield
    rescue Exception => e
      Rollbar::Sidekiq.handle_exception(msg, e)
      raise
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rollbar-3.1.2 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-3.1.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-3.1.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-3.0.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-3.0.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.27.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.27.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.26.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.26.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.25.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.25.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.24.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.23.2 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.23.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.23.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.22.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.22.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.21.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.20.2 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.20.1 lib/rollbar/plugins/sidekiq/plugin.rb