Class: Sentry::Sidekiq::ContextFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/sidekiq/context_filter.rb

Constant Summary collapse

ACTIVEJOB_RESERVED_PREFIX_REGEX =
/^_aj_/
SIDEKIQ_NAME =
"Sidekiq"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ContextFilter

Returns a new instance of ContextFilter.



11
12
13
14
# File 'lib/sentry/sidekiq/context_filter.rb', line 11

def initialize(context)
  @context = context
  @has_global_id = defined?(GlobalID)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/sentry/sidekiq/context_filter.rb', line 9

def context
  @context
end

Instance Method Details

#filteredObject

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.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sentry/sidekiq/context_filter.rb', line 22

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

  # Sidekiq 7.0 started adding `_config` to the context, which is not easily serialisable
  # And it's presence could be confusing so it's better to remove it until we decided to add it for a reason
  filtered_context.delete(:_config)
  filtered_context
end

#transaction_nameObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sentry/sidekiq/context_filter.rb', line 37

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