Class: Honeybadger::NotificationSubscriber

Inherits:
Object
  • Object
show all
Includes:
InstrumentationHelper
Defined in:
lib/honeybadger/notification_subscriber.rb

Instance Method Summary collapse

Methods included from InstrumentationHelper

#decrement_counter, #extract_attributes, #extract_callable, #gauge, #histogram, #increment_counter, #metric_agent, #metric_attributes, #metric_instrumentation, #metric_source, #monotonic_timer, #time

Instance Method Details

#finish(name, id, payload) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/honeybadger/notification_subscriber.rb', line 12

def finish(name, id, payload)
  @finish_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)

  return unless process?(name, payload)

  payload = {
    instrumenter_id: id,
    duration: ((@finish_time - @start_time) * 1000).round(2)
  }.merge(format_payload(payload).compact)

  record(name, payload)
end

#format_payload(payload) ⇒ Object



55
56
57
# File 'lib/honeybadger/notification_subscriber.rb', line 55

def format_payload(payload)
  payload
end

#process?(event, payload) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/honeybadger/notification_subscriber.rb', line 51

def process?(event, payload)
  true
end

#record(name, payload) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/honeybadger/notification_subscriber.rb', line 25

def record(name, payload)
  if Honeybadger.config.load_plugin_insights_events?(:rails)
    Honeybadger.event(name, payload)
  end

  if Honeybadger.config.load_plugin_insights_metrics?(:rails)
    metric_source 'rails'
    record_metrics(name, payload)
  end
end

#record_metrics(name, payload) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/honeybadger/notification_subscriber.rb', line 36

def record_metrics(name, payload)
  case name
  when 'sql.active_record'
    gauge('duration.sql.active_record', value: payload[:duration], **payload.slice(:query))
  when 'process_action.action_controller'
    gauge('duration.process_action.action_controller', value: payload[:duration], **payload.slice(:method, :controller, :action, :format, :status))
    gauge('db_runtime.process_action.action_controller', value: payload[:db_runtime], **payload.slice(:method, :controller, :action, :format, :status))
    gauge('view_runtime.process_action.action_controller', value: payload[:view_runtime], **payload.slice(:method, :controller, :action, :format, :status))
  when 'perform.active_job'
    gauge('duration.perform.active_job', value: payload[:duration], **payload.slice(:job_class, :queue_name))
  when /^cache_.*.active_support$/
    gauge("duration.#{name}", value: payload[:duration], **payload.slice(:store, :key))
  end
end

#start(name, id, payload) ⇒ Object



8
9
10
# File 'lib/honeybadger/notification_subscriber.rb', line 8

def start(name, id, payload)
  @start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
end