Sha256: c2057e77eb5334f681144cdb45a01817348b55216577923d6b51044fc54cb446

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

require 'rollbar/scrubbers/params'

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

    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

6 entries across 6 versions & 1 rubygems

Version Path
rollbar-2.19.2 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.19.1 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.19.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.18.2 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.18.0 lib/rollbar/plugins/sidekiq/plugin.rb
rollbar-2.17.0 lib/rollbar/plugins/sidekiq/plugin.rb