class Sentry::Sidekiq::ContextFilter

Constants

ACTIVEJOB_RESERVED_PREFIX_REGEX
SIDEKIQ_NAME

Attributes

context[R]

Public Class Methods

new(context) click to toggle source
# File lib/sentry/sidekiq/context_filter.rb, line 9
def initialize(context)
  @context = context
  @has_global_id = defined?(GlobalID)
end

Public Instance Methods

filtered() 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/sentry/sidekiq/context_filter.rb, line 20
def filtered
  filtered_context = filter_context(context)

  if job_entry = filtered_context.delete(:job)
    job_entry.each do |k, v|
      filtered_context[k] = v
    end
  end

  filtered_context
end
transaction_name() click to toggle source
# File lib/sentry/sidekiq/context_filter.rb, line 32
def transaction_name
  class_name = (context["wrapped"] || context["class"] ||
                (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
              )

  if class_name
    "#{SIDEKIQ_NAME}/#{class_name}"
  elsif context[:event]
    "#{SIDEKIQ_NAME}/#{context[:event]}"
  else
    SIDEKIQ_NAME
  end
end

Private Instance Methods

filter_context(hash) click to toggle source
# File lib/sentry/sidekiq/context_filter.rb, line 48
def filter_context(hash)
  case hash
  when Array
    hash.map { |arg| filter_context(arg) }
  when Hash
    Hash[hash.map { |key, value| filter_context_hash(key, value) }]
  else
    if has_global_id? && hash.is_a?(GlobalID)
      hash.to_s
    else
      hash
    end
  end
end
filter_context_hash(key, value) click to toggle source
# File lib/sentry/sidekiq/context_filter.rb, line 63
def filter_context_hash(key, value)
  key = key.to_s.sub(ACTIVEJOB_RESERVED_PREFIX_REGEX, "") if key.match(ACTIVEJOB_RESERVED_PREFIX_REGEX)
  [key, filter_context(value)]
end
has_global_id?() click to toggle source
# File lib/sentry/sidekiq/context_filter.rb, line 68
def has_global_id?
  @has_global_id
end