Module: ScoutApm::Instruments::Resque

Defined in:
lib/scout_apm/instruments/resque.rb

Instance Method Summary collapse

Instance Method Details

#around_perform_with_scout_instruments(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/scout_apm/instruments/resque.rb', line 13

def around_perform_with_scout_instruments(*args)
  job_name = self.to_s
  queue = find_queue

  if job_name == "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper"
    job_name = args.first["job_class"] rescue job_name
    queue = args.first["queue_name"] rescue queue_name
  end

  req = ScoutApm::RequestManager.lookup

  begin
    req.start_layer(ScoutApm::Layer.new('Queue', queue))
    started_queue = true
    req.start_layer(ScoutApm::Layer.new('Job', job_name))
    started_job = true
    yield
  rescue => e
    req.error!
    raise
  ensure
    req.stop_layer if started_job
    req.stop_layer if started_queue
  end
end

#before_perform_become_client(*args) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/scout_apm/instruments/resque.rb', line 4

def before_perform_become_client(*args)
  # Don't become remote client if explicitly disabled or if forking is disabled to force synchronous recording.
  if config.value('start_resque_server_instrument') && forking?
    ScoutApm::Agent.instance.context.become_remote_client!(bind, port)
  else
    logger.debug("Not becoming remote client due to 'start_resque_server_instrument' setting or 'fork_per_job' setting")
  end
end

#find_queueObject



39
40
41
42
43
# File 'lib/scout_apm/instruments/resque.rb', line 39

def find_queue
  return @queue if @queue
  return queue if self.respond_to?(:queue)
  return "unknown"
end