Class: Airbrake::Rack::Middleware
- Inherits:
-
Object
- Object
- Airbrake::Rack::Middleware
- Defined in:
- lib/airbrake/rack/middleware.rb
Overview
Airbrake Rack middleware for Rails and Sinatra applications (or any other Rack-compliant app). Any errors raised by the upstream application will be delivered to Airbrake and re-raised.
The middleware automatically sends information about the framework that uses it (name and version).
For Rails apps the middleware collects route performance statistics.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Thread-safe #call!.
-
#call!(env) ⇒ Object
Rescues any exceptions, sends them to Airbrake and re-raises the exception.
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
14 15 16 |
# File 'lib/airbrake/rack/middleware.rb', line 14 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Thread-safe #call!.
22 23 24 |
# File 'lib/airbrake/rack/middleware.rb', line 22 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
Rescues any exceptions, sends them to Airbrake and re-raises the exception. We also duplicate middleware to guarantee thread-safety.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/airbrake/rack/middleware.rb', line 30 def call!(env) before_call(env) begin response = @app.call(env) rescue Exception => ex # rubocop:disable Lint/RescueException notify_airbrake(ex) raise ex end exception = framework_exception(env) notify_airbrake(exception) if exception response ensure # Clear routes for the next request. RequestStore.clear end |