Sha256: a72b4467844a1d5f9670be4db1c7a10e38a46a7920236fb1c70844e9b1729ef9

Contents?: true

Size: 1.05 KB

Versions: 10

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

10 entries across 10 versions & 1 rubygems

Version Path
plain_apm-0.9.2 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.9.1 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.9.0 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.8.8 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.8.7 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.8.6 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.8.5 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.8.4 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.8.3 lib/plain_apm/hooks/error_reporter.rb
plain_apm-0.8.2 lib/plain_apm/hooks/error_reporter.rb