class InfluxReporter::Middleware

Public Class Methods

new(app) click to toggle source
# File lib/influx_reporter/middleware.rb, line 5
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/influx_reporter/middleware.rb, line 9
def call(env)
  begin
    transaction = InfluxReporter.transaction 'Rack', 'app.rack.request'
    resp = @app.call env
    resp[2] = BodyProxy.new(resp[2]) { transaction.submit(resp[0]) } if transaction
  rescue Error
    raise # Don't report InfluxReporter errors
  rescue Exception => e
    InfluxReporter.report e, rack_env: env
    transaction&.submit(500)
    raise
  ensure
    transaction&.release
  end

  if error = env['rack.exception'] || env['sinatra.error']
    InfluxReporter.report error, rack_env: env
  end

  resp
end