Class: NewRelic::Agent::Instrumentation::ActiveJobSubscriber

Inherits:
NotificationsSubscriber show all
Defined in:
lib/new_relic/agent/instrumentation/active_job_subscriber.rb

Constant Summary collapse

PAYLOAD_KEYS =
%i[adapter db_runtime error job wait]
PATTERN =
/\A([^\.]+)\.active_job\z/
METHOD_NAME_MAPPING =
Hash.new do |h, k|
  if PATTERN =~ k
    h[k] = $1
  else
    h[k] = NewRelic::UNKNOWN
  end
end

Instance Method Summary collapse

Methods inherited from NotificationsSubscriber

#define_exception_method, find_all_subscribers, #finish, #finish_segment, #initialize, #log_notification_error, #pop_segment, #push_segment, #segment_stack, #start, #start_segment, #state, subscribe, subscribed?

Constructor Details

This class inherits a constructor from NewRelic::Agent::Instrumentation::NotificationsSubscriber

Instance Method Details

#add_segment_params(segment, payload) ⇒ Object



13
14
15
16
17
# File 'lib/new_relic/agent/instrumentation/active_job_subscriber.rb', line 13

def add_segment_params(segment, payload)
  PAYLOAD_KEYS.each do |key|
    segment.params[key] = payload[key] if payload.key?(key)
  end
end

#method_from_name(name) ⇒ Object



35
36
37
# File 'lib/new_relic/agent/instrumentation/active_job_subscriber.rb', line 35

def method_from_name(name)
  METHOD_NAME_MAPPING[name]
end

#metric_name(name, payload) ⇒ Object



19
20
21
22
23
# File 'lib/new_relic/agent/instrumentation/active_job_subscriber.rb', line 19

def metric_name(name, payload)
  queue = payload[:job].queue_name
  method = method_from_name(name)
  "Ruby/ActiveJob/#{queue}/#{method}"
end