Sha256: 6b3ffb7685ab150fb12f6a9cef741f0a632252978af25bbbf56d95ea7f96afb4

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module PlainApm
  module Extensions
    module Exceptions
      class Rack
        # FIXME: This is duplicated for ErrorReporter
        IGNORED_EXCEPTIONS = [
          "Sidekiq::JobRetry::Skip",          # Sidekiq uses exceptions for control flow.
          "ActionController::RoutingError"    # Rails unmapped route, raised before the request hits the app.
        ].freeze

        def initialize(app)
          @app = app
        end

        def call(env)
          response = @app.call(env)

          e = env["action_dispatch.exception"]
          report_exception(e, env) unless e.nil?

          response
        rescue Exception => e # standard:disable Lint/RescueException
          report_exception(e, env)
          raise
        end

        private

        def report_exception(e, env)
          return if IGNORED_EXCEPTIONS.include?(e.class.name)

          event = {
            "source" => "exception",
            "name" => "rack_middleware",
            "class" => e.class.name,
            "message" => e.message,
            "backtrace" => e.backtrace,
            "params" => env["action_dispatch.request.parameters"]
          }

          if e.cause
            event.merge!({
              "cause_class" => e.cause.class.name,
              "cause_message" => e.cause.message,
              "cause_backtrace" => e.cause.backtrace
            })
          end

          PlainApm::Agent.collect(event)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
plain_apm-0.6.7 lib/plain_apm/extensions/exceptions/rack.rb
plain_apm-0.6.6 lib/plain_apm/extensions/exceptions/rack.rb
plain_apm-0.6.5 lib/plain_apm/extensions/exceptions/rack.rb