Class: RailsSpotlight::Middlewares::RequestCompleted

Inherits:
Object
  • Object
show all
Includes:
SkipRequestPaths
Defined in:
lib/rails_spotlight/middlewares/request_completed.rb

Constant Summary

Constants included from SkipRequestPaths

SkipRequestPaths::PATHS_TO_SKIP

Instance Method Summary collapse

Constructor Details

#initialize(app, app_config) ⇒ RequestCompleted

Returns a new instance of RequestCompleted.



11
12
13
14
# File 'lib/rails_spotlight/middlewares/request_completed.rb', line 11

def initialize(app, app_config)
  @app = app
  @app_config = app_config
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_spotlight/middlewares/request_completed.rb', line 16

def call(env)
  return app.call(env) unless ::RailsSpotlight.config.request_completed_broadcast_enabled?

  if skip?(env['PATH_INFO']) || (env['HTTP_CONNECTION'] == 'Upgrade' && env['HTTP_UPGRADE'] == 'websocket')
    app.call(env)
  else
    status, headers, body = app.call(env)
    publish_event(status, headers, env)
    [status, headers, body]
  end
rescue => e # rubocop:disable Style/RescueStandardError
  ::RailsSpotlight.config.logger.error "Error in RailsSpotlight::Middlewares::RequestCompletedHandler instrumentation: #{e.message}"
  app.call(env)
end