Class: Bugsnag::Rack
- Inherits:
-
Object
- Object
- Bugsnag::Rack
- Defined in:
- lib/bugsnag/rack.rb
Constant Summary collapse
- SEVERITY_REASON =
{ :type => Bugsnag::Notification::UNHANDLED_EXCEPTION_MIDDLEWARE, :attributes => { :framework => "Rack" } }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bugsnag/rack.rb', line 11 def initialize(app) @app = app # Configure bugsnag rack defaults Bugsnag.configure do |config| # Try to set the release_stage automatically if it hasn't already been set config.release_stage ||= release_stage # Try to set the project_root if it hasn't already been set, or show a warning if we can't unless config.project_root && !config.project_root.to_s.empty? if defined?(settings) config.project_root = settings.root else Bugsnag.warn("You should set your app's project_root (see https://bugsnag.com/docs/notifiers/ruby#project_root).") end end # Hook up rack-based notification middlewares config.middleware.insert_before([Bugsnag::Middleware::Rails3Request,Bugsnag::Middleware::Callbacks], Bugsnag::Middleware::RackRequest) if defined?(::Rack) config.middleware.insert_before(Bugsnag::Middleware::Callbacks, Bugsnag::Middleware::WardenUser) if defined?(Warden) config.middleware.insert_before(Bugsnag::Middleware::Callbacks, Bugsnag::Middleware::ClearanceUser) if defined?(Clearance) Bugsnag.configuration.app_type ||= "rack" end end |
Instance Method Details
#call(env) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bugsnag/rack.rb', line 37 def call(env) # Set the request data for bugsnag middleware to use Bugsnag.set_request_data(:rack_env, env) begin response = @app.call(env) rescue Exception => raised # Notify bugsnag of rack exceptions Bugsnag.auto_notify(raised, { :severity_reason => SEVERITY_REASON }) # Re-raise the exception raise end # Notify bugsnag of rack exceptions if env["rack.exception"] Bugsnag.auto_notify(env["rack.exception"], { :severity_reason => SEVERITY_REASON }) end response ensure # Clear per-request data after processing the each request Bugsnag.clear_request_data end |