Sha256: 4ebb9c3a751f740944f2f2dfbc3e1b65608d551ca564fc4ab08e63585737cefd

Contents?: true

Size: 765 Bytes

Versions: 7

Compression:

Stored size: 765 Bytes

Contents

# frozen_string_literal: true

module ElasticAPM
  # @api private
  class Middleware
    def initialize(app)
      @app = app
    end

    # rubocop:disable Metrics/MethodLength
    def call(env)
      begin
        transaction = ElasticAPM.transaction 'Rack', 'app',
          context: ElasticAPM.build_context(env)

        resp = @app.call env

        transaction.submit(resp[0], headers: resp[1]) if transaction
      rescue InternalError
        raise # Don't report ElasticAPM errors
      rescue ::Exception => e
        ElasticAPM.report(e, handled: false)
        transaction.submit(500) if transaction
        raise
      ensure
        transaction.release if transaction
      end

      resp
    end
    # rubocop:enable Metrics/MethodLength
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
elastic-apm-0.4.5 lib/elastic_apm/middleware.rb
elastic-apm-0.4.4 lib/elastic_apm/middleware.rb
elastic-apm-0.4.3 lib/elastic_apm/middleware.rb
elastic-apm-0.4.2 lib/elastic_apm/middleware.rb
elastic-apm-0.4.1 lib/elastic_apm/middleware.rb
elastic-apm-0.4.0 lib/elastic_apm/middleware.rb
elastic-apm-0.3.0 lib/elastic_apm/middleware.rb