class Raven::SidekiqErrorHandler

Constants

ACTIVEJOB_RESERVED_PREFIX
HAS_GLOBALID

Public Instance Methods

call(ex, context) click to toggle source
# File lib/raven/integrations/sidekiq.rb, line 19
def call(ex, context)
  context = filter_context(context)
  Raven.context.transaction.push transaction_from_context(context)
  Raven.capture_exception(
    ex,
    :message => ex.message,
    :extra => { :sidekiq => context }
  )
  Context.clear!
  BreadcrumbBuffer.clear!
end

Private Instance Methods

filter_context(context) click to toggle source

Once an ActiveJob is queued, ActiveRecord references get serialized into some internal reserved keys, such as _aj_globalid.

The problem is, if this job in turn gets queued back into ActiveJob with these magic reserved keys, ActiveJob will throw up and error. We want to capture these and mutate the keys so we can sanely report it.

# File lib/raven/integrations/sidekiq.rb, line 39
def filter_context(context)
  case context
  when Array
    context.map { |arg| filter_context(arg) }
  when Hash
    Hash[context.map { |key, value| filter_context_hash(key, value) }]
  else
    format_globalid(context)
  end
end
filter_context_hash(key, value) click to toggle source
# File lib/raven/integrations/sidekiq.rb, line 50
def filter_context_hash(key, value)
  (key = key[3..-1]) if key [0..3] == ACTIVEJOB_RESERVED_PREFIX
  [key, filter_context(value)]
end
format_globalid(context) click to toggle source
# File lib/raven/integrations/sidekiq.rb, line 70
def format_globalid(context)
  if HAS_GLOBALID && context.is_a?(GlobalID)
    context.to_s
  else
    context
  end
end
transaction_from_context(context) click to toggle source

this will change in the future: github.com/mperham/sidekiq/pull/3161

# File lib/raven/integrations/sidekiq.rb, line 57
def transaction_from_context(context)
  classname = (context["wrapped"] || context["class"] ||
                (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
              )
  if classname
    "Sidekiq/#{classname}"
  elsif context[:event]
    "Sidekiq/#{context[:event]}"
  else
    "Sidekiq"
  end
end