class Opbeat::Middleware

Public Class Methods

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

Public Instance Methods

call(env) click to toggle source
# 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