Class: XRay::Rails::ExceptionMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-xray-sdk/facets/rails/ex_middleware.rb

Overview

Middleware for capturing unhandled exceptions from views/controller. To properly capture exceptions this middleware needs to be placed after the default exception handling middleware. Otherwise they will be swallowed.

Instance Method Summary collapse

Constructor Details

#initialize(app, recorder: nil) ⇒ ExceptionMiddleware

Returns a new instance of ExceptionMiddleware.



10
11
12
13
# File 'lib/aws-xray-sdk/facets/rails/ex_middleware.rb', line 10

def initialize(app, recorder: nil)
  @app = app
  @recorder = recorder || XRay.recorder
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/aws-xray-sdk/facets/rails/ex_middleware.rb', line 15

def call(env)
  @app.call(env)
rescue Exception => e
  segment = @recorder.current_segment
  segment.add_exception exception: e if segment
  raise e
end