module PlainApm module Hooks # Rails 7 error notification mechanism class ErrorReporter include EventAttributes def install begin require "active_support/error_reporter" require "active_support/lazy_load_hooks" rescue LoadError return end # 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 def collect(e, handled:, severity:, context: {}) source, event = attributes_from_exception(e, context) return if event.nil? event["source"] = source event["name"] = "error_reporter" PlainApm::Agent.collect(event) end alias_method :report, :collect end end end