Class: Airbrake::Rack
- Inherits:
-
Object
- Object
- Airbrake::Rack
- 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'
#can also set the environment over here
config.environment_name = ENV['RACK_ENV'] || "development"
end
app = Rack::Builder.app do
run lambda { |env| raise "Rack down" }
end
use Airbrake::Rack
run app
Use a standard Airbrake.configure call to configure your api key.
Direct Known Subclasses
Instance Method Summary collapse
- #call(env) ⇒ Object
- #framework_exception(env) ⇒ Object
- #ignored_user_agent?(env) ⇒ Boolean
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
- #notify_airbrake(exception, env) ⇒ Object
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
25 26 27 28 |
# File 'lib/airbrake/rack.rb', line 25 def initialize(app) @app = app Airbrake.configuration.framework = "Rack: #{::Rack.release}" end |
Instance Method Details
#call(env) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/airbrake/rack.rb', line 44 def call(env) begin response = @app.call(env) rescue Exception => raised env['airbrake.error_id'] = notify_airbrake(raised, env) raise raised end if framework_exception(env) env['airbrake.error_id'] = notify_airbrake(framework_exception(env), env) end response end |
#framework_exception(env) ⇒ Object
59 60 61 |
# File 'lib/airbrake/rack.rb', line 59 def framework_exception(env) env['rack.exception'] || env['sinatra.error'] end |
#ignored_user_agent?(env) ⇒ Boolean
30 31 32 33 34 35 36 |
# File 'lib/airbrake/rack.rb', line 30 def ignored_user_agent?(env) true if Airbrake. configuration. ignore_user_agent. flatten. any? { |ua| ua === env['HTTP_USER_AGENT'] } end |
#notify_airbrake(exception, env) ⇒ Object
38 39 40 41 42 |
# File 'lib/airbrake/rack.rb', line 38 def notify_airbrake(exception, env) unless ignored_user_agent?(env) Airbrake.notify_or_ignore(exception, :rack_env => env) end end |