Module: ScoutApm::BackgroundJobIntegrations::LegacySneakers

Defined in:
lib/scout_apm/background_job_integrations/legacy_sneakers.rb

Constant Summary collapse

UNKNOWN_QUEUE_PLACEHOLDER =
'default'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



16
17
18
# File 'lib/scout_apm/background_job_integrations/legacy_sneakers.rb', line 16

def self.prepended(base)
  ScoutApm::Agent.instance.logger.info("Prepended LegacySneakers in #{base}")
end

Instance Method Details

#initialize(*args) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/scout_apm/background_job_integrations/legacy_sneakers.rb', line 20

def initialize(*args)
  super

  # Save off the existing value to call the correct existing work
  # function in the instrumentation. But then override Sneakers to always
  # use the extra-argument version, which has data Scout needs
  @call_work = respond_to?(:work)
end

#work_with_params(msg, delivery_info, metadata) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/scout_apm/background_job_integrations/legacy_sneakers.rb', line 29

def work_with_params(msg, delivery_info, )
  queue = delivery_info[:routing_key] || UNKNOWN_QUEUE_PLACEHOLDER
  job_class = self.class.name
  req = ScoutApm::RequestManager.lookup

  begin
    req.start_layer(ScoutApm::Layer.new('Queue', queue))
    started_queue = true
    req.start_layer(ScoutApm::Layer.new('Job', job_class))
    started_job = true

    if @call_work
      work(msg)
    else
      super
    end
  rescue Exception => exception
    req.error!
    env = {
      :custom_controller => job_class,
      :custom_action => queue
    }
    context = ScoutApm::Agent.instance.context
    context.error_buffer.capture(exception, env)
    raise
  ensure
    req.stop_layer if started_job
    req.stop_layer if started_queue
  end
end