Class: Raygun::SidekiqReporter

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

Class Method Summary collapse

Class Method Details

.affected_user(context_hash) ⇒ Object

Extracts affected user information out of a Sidekiq worker class



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/raygun/sidekiq.rb', line 38

def self.affected_user(context_hash)
  job = context_hash[:job]

  return if job.nil? || job['class'].nil? || !Module.const_defined?(job['class'])

  worker_class = Module.const_get(job['class'])
  affected_user_method = Raygun.configuration.affected_user_method

  return if worker_class.nil? || !worker_class.respond_to?(affected_user_method)

  worker_class.send(affected_user_method, job['args'])
rescue => e
  return unless Raygun.configuration.failsafe_logger

  failsafe_log("Problem in sidekiq affected user tracking: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")

  nil
end

.call(exception, context_hash = {}, config = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/raygun/sidekiq.rb', line 9

def self.call(exception, context_hash = {}, config = nil)
  user = affected_user(context_hash)
  data =  {
    custom_data: {
      sidekiq_context: context_hash
    },
    tags: ['sidekiq']
  }

  if exception.is_a?(Sidekiq::JobRetry::Handled) && exception.cause
    if Raygun.configuration.track_retried_sidekiq_jobs
      data.merge!(sidekiq_retried: true)
      exception = exception.cause
    else
      return false
    end
  end

  if exception.instance_variable_defined?(:@__raygun_correlation_id) && correlation_id = exception.instance_variable_get(:@__raygun_correlation_id)
    data.merge!(correlation_id: correlation_id)
  end
  ::Raygun.track_exception(
      exception,
      data,
      user
    )
end