Class: Appsignal::Hooks::SidekiqPlugin

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/appsignal/hooks/sidekiq.rb

Instance Method Summary collapse

Methods included from Helpers

#extract_value, #format_args, #string_or_inspect, #truncate

Instance Method Details

#call(worker, item, queue) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/appsignal/hooks/sidekiq.rb', line 15

def call(worker, item, queue)
  if item['class'] == 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper'
    params = format_args(item['args'].first['arguments'])
  else
    params = format_args(item['args'])
  end

  Appsignal.monitor_transaction(
    'perform_job.sidekiq',
    :class       => item['wrapped'] || item['class'],
    :method      => 'perform',
    :metadata    => (item),
    :params      => params,
    :queue_start => item['enqueued_at'],
    :queue_time  => (Time.now.to_f - item['enqueued_at'].to_f) * 1000
  ) do
    yield
  end
end

#formatted_metadata(item) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/appsignal/hooks/sidekiq.rb', line 35

def (item)
  {}.tap do |hsh|
    item.each do |key, val|
      hsh[key] = truncate(string_or_inspect(val)) unless job_keys.include?(key)
    end
  end
end

#job_keysObject


6
7
8
9
10
11
12
13
# File 'lib/appsignal/hooks/sidekiq.rb', line 6

def job_keys
  @job_keys ||= Set.new(%w(
      class args retried_at failed_at
      error_message error_class backtrace
      error_backtrace enqueued_at retry
      jid retry created_at wrapped
  ))
end