class Rollbar::Sidekiq

Constants

PARAM_BLACKLIST

Public Class Methods

handle_exception(msg, e) click to toggle source
# File lib/rollbar/plugins/sidekiq/plugin.rb, line 17
def self.handle_exception(msg, e)
  return if skip_report?(msg, e)

  Rollbar.scope(job_scope(msg)).error(e, :use_exception_level_filters => true)
end
job_scope(msg) click to toggle source
# File lib/rollbar/plugins/sidekiq/plugin.rb, line 34
def self.job_scope(msg)
  scope = {
    :framework => "Sidekiq: #{::Sidekiq::VERSION}"
  }
  job_hash = job_hash_from_msg(msg)

  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

  scope
end
scrub_params(params) click to toggle source
# File lib/rollbar/plugins/sidekiq/plugin.rb, line 50
def self.scrub_params(params)
  options = {
    :params => params,
    :config => Rollbar.configuration.scrub_fields,
    :whitelist => Rollbar.configuration.scrub_whitelist
  }

  Rollbar::Scrubbers::Params.call(options)
end
skip_report?(msg, _e) click to toggle source
# File lib/rollbar/plugins/sidekiq/plugin.rb, line 23
def self.skip_report?(msg, _e)
  job_hash = job_hash_from_msg(msg)

  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

Private Class Methods

job_hash_from_msg(msg) click to toggle source
# File lib/rollbar/plugins/sidekiq/plugin.rb, line 72
def self.job_hash_from_msg(msg)
  msg && (msg[:job] || msg)
end

Public Instance Methods

call(_worker, msg, _queue) { || ... } click to toggle source

see github.com/mperham/sidekiq/wiki/Middleware#server-middleware

# File lib/rollbar/plugins/sidekiq/plugin.rb, line 61
def call(_worker, msg, _queue, &block)
  Rollbar.reset_notifier! # clears scope

  return yield unless Rollbar.configuration.sidekiq_use_scoped_block

  Rollbar.scoped(Rollbar::Sidekiq.job_scope(msg), &block)
rescue Exception => e # rubocop:disable Lint/RescueException
  Rollbar::Sidekiq.handle_exception(msg, e)
  raise
end