class Rollbar::Sidekiq

Attributes

error[R]
job_hash[R]

Public Class Methods

handle_exception(ctx_hash, error) click to toggle source
# File lib/rollkiq/plugin.rb, line 13
def self.handle_exception(ctx_hash, error)
  new(ctx_hash, error).handle_exception
end
new(ctx_hash, error) click to toggle source
# File lib/rollkiq/plugin.rb, line 7
def initialize(ctx_hash, error)
  @ctx_hash = ctx_hash
  @job_hash = ctx_hash.fetch(:job, nil)
  @error = error
end

Public Instance Methods

handle_exception() click to toggle source
# File lib/rollkiq/plugin.rb, line 17
def handle_exception
  return if skip_report?

  Rollbar.scope(scope).error(error, use_exception_level_filters: true)
end

Private Instance Methods

global_threshold() click to toggle source
# File lib/rollkiq/plugin.rb, line 110
def global_threshold
  Rollbar.configuration.sidekiq_threshold.to_i
end
non_blacklisted_params() click to toggle source
# File lib/rollkiq/plugin.rb, line 61
def non_blacklisted_params
  job_hash&.reject { |key| PARAM_BLACKLIST.include?(key) }
end
notify_on_failure_number() click to toggle source
# File lib/rollkiq/plugin.rb, line 102
def notify_on_failure_number
  @notify_on_failure_number ||= worker_instance.notify_on_failure_number rescue nil
end
person() click to toggle source
# File lib/rollkiq/plugin.rb, line 85
def person
  worker_instance.person(*job_hash['args']) rescue nil
end
person_email() click to toggle source
# File lib/rollkiq/plugin.rb, line 77
def person_email
  person.email rescue nil
end
person_id() click to toggle source
# File lib/rollkiq/plugin.rb, line 73
def person_id
  person.id rescue nil
end
person_scope() click to toggle source
# File lib/rollkiq/plugin.rb, line 65
def person_scope
  {
    id: person_id,
    email: person_email,
    username: person_username
  }
end
person_username() click to toggle source
# File lib/rollkiq/plugin.rb, line 81
def person_username
  person.username rescue nil
end
request_scope() click to toggle source
# File lib/rollkiq/plugin.rb, line 42
def request_scope
  {
    params: sanitized_params
  }
end
retry_count() click to toggle source
# File lib/rollkiq/plugin.rb, line 114
def retry_count
  # 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
  job_hash.fetch('retry_count', -1).to_i + 1
end
sanitized_params() click to toggle source
# File lib/rollkiq/plugin.rb, line 48
def sanitized_params
  scrub_params(non_blacklisted_params)
end
scope() click to toggle source
# File lib/rollkiq/plugin.rb, line 32
def scope
  {
    framework: "Sidekiq: #{::Sidekiq::VERSION}",
    context: job_hash&.fetch('class', nil),
    queue: job_hash&.fetch('queue', nil),
    request: request_scope,
    person: person_scope
  }
end
scrub_params(params) click to toggle source
# File lib/rollkiq/plugin.rb, line 52
def scrub_params(params)
  options = {
    params: params,
    config: Rollbar.configuration.scrub_fields
  }

  Rollbar::Scrubbers::Params.call(options)
end
skip_globally?() click to toggle source
# File lib/rollkiq/plugin.rb, line 89
def skip_globally?
  retry_count < global_threshold
end
skip_override?() click to toggle source
# File lib/rollkiq/plugin.rb, line 93
def skip_override?
  case
  when notify_on_failure_number.is_a?(Integer)
    notify_on_failure_number != retry_count
  when notify_on_failure_number.is_a?(Array)
    !notify_on_failure_number.include?(retry_count)
  end
end
skip_report?() click to toggle source
# File lib/rollkiq/plugin.rb, line 25
def skip_report?
  return false if job_hash.nil?
  return false unless job_hash['retry']

  notify_on_failure_number.nil? ? skip_globally? : skip_override?
end
worker_instance() click to toggle source
# File lib/rollkiq/plugin.rb, line 106
def worker_instance
  self.class.const_get(job_hash['class']).new rescue nil
end