Class: Airbrake::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake/rack.rb

Overview

Middleware for Rack applications. Any errors raised by the upstream application will be delivered to Airbrake and re-raised.

Synopsis:

require 'rack'
require 'airbrake'

Airbrake.configure do |config|
  config.api_key = 'my_api_key'
end

app = Rack::Builder.app do
  use Airbrake::Rack
  run lambda { |env| raise "Rack down" }
end

Use a standard Airbrake.configure call to configure your api key.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



21
22
23
# File 'lib/airbrake/rack.rb', line 21

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/airbrake/rack.rb', line 25

def call(env)
  begin
    response = @app.call(env)
  rescue Exception => raised
    error_id = Airbrake.notify_or_ignore(raised, :rack_env => env)
    env['airbrake.error_id'] = error_id
    raise
  end

  if env['rack.exception']
    error_id = Airbrake.notify_or_ignore(env['rack.exception'], :rack_env => env)
    env['airbrake.error_id'] = error_id
  end

  response
end