class ElasticAPM::Middleware

def call(env)

rubocop:disable Metrics/MethodLength
def call(env)
  begin
    if running? && !path_ignored?(env)
      transaction = start_transaction(env)
    end
    resp = @app.call env
  rescue InternalError
    raise # Don't report ElasticAPM errors
  rescue ::Exception => e
    ElasticAPM.report(e, handled: false)
    raise
  ensure
    if resp && transaction
      status, headers, _body = resp
      transaction.add_response(status, headers: headers)
    end
    ElasticAPM.end_transaction http_result(status)
  end
  resp
end