Class: InfluxReporter::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/influx_reporter/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



5
6
7
# File 'lib/influx_reporter/middleware.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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