class ElasticAPM::Middleware

@api private

def call(env)

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

def initialize(app)

def initialize(app)
  @app = app
end