Sha256: ec42596ce20c4d5abc6b09082ae7300bf7f2cd89f1e2f6a77588e89d2dec460f

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 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)
        event_source, event = attributes_from_exception(e, context, source)

        return if event.nil?

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

        ::PlainApm.agent.collect(event)
      end

      alias_method :report, :collect
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
plain_apm-0.9.8 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.9.7 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.9.6 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.9.5 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.9.4 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.9.3 lib/plain_apm/hooks/error_reporter.rb