Class: PlainApm::Hooks::ErrorReporter

Inherits:
Object
  • Object
show all
Includes:
EventAttributes
Defined in:
lib/plain_apm/hooks/error_reporter.rb

Overview

Rails 7 error notification mechanism

Constant Summary

Constants included from EventAttributes

EventAttributes::IGNORED_EXCEPTIONS, EventAttributes::SOURCES_WITH_EXTRA_ATTRIBUTES

Instance Method Summary collapse

Methods included from EventAttributes

#attributes_from_exception, #attributes_from_notification

Instance Method Details

#collect(e, handled:, severity:, context: {}, source: nil) ⇒ Object Also known as: report



25
26
27
28
29
30
31
32
33
34
# File 'lib/plain_apm/hooks/error_reporter.rb', line 25

def collect(e, handled:, severity:, context: {}, source: nil)
  name, event = attributes_from_exception(e, context, source)

  return if event.nil?

  event[:source] = "error_reporter"
  event[:name] = name

  ::PlainApm.agent.collect(event)
end

#installObject



7
8
9
10
11
12
13
14
15
# File 'lib/plain_apm/hooks/error_reporter.rb', line 7

def install
  return unless defined?(Rails) && Rails.respond_to?(:error)

  # Install the hook when the app is up. This might miss errors that
  # happen before that, but that's OK.
  ::ActiveSupport.on_load(:after_initialize, yield: self, run_once: true) do
    ::Rails.error.subscribe(self)
  end
end

#uninstallObject



17
18
19
20
21
22
23
# File 'lib/plain_apm/hooks/error_reporter.rb', line 17

def uninstall
  return unless defined?(Rails) && Rails.respond_to?(:error)

  # There's no unsubscribe
  subscribers = Rails.error.instance_variable_get(:@subscribers)
  subscribers&.delete(self)
end