Class: Opbeat::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



3
4
5
# File 'lib/opbeat/middleware.rb', line 3

def initialize app
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/opbeat/middleware.rb', line 7

def call env
  begin
    transaction = Opbeat.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 Opbeat errors
  rescue Exception => e
    Opbeat.report e, rack_env: env
    transaction.submit(500) if transaction
    raise
  ensure
    transaction.release if transaction
  end

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

  resp
end