Sha256: 10e3adace8cd904891a629488e6b252900e21f352d568fd3f9a0ff8d5a50363a

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module PlainApm
  module Hooks
    # Rails 7 error notification mechanism
    class ErrorReporter
      include EventAttributes

      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

      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

      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

      alias_method :report, :collect
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
plain_apm-0.10.2 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.10.0 lib/plain_apm/hooks/error_reporter.rb