Class: Dispatch::Rails::HeartbeatMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatch/rails/heartbeat_middleware.rb

Overview

Counts every request per controller#action into the HeartbeatAggregator, so Dispatch can later tell whether a code path is still being exercised. A 5xx (or a propagating exception) counts as an errored request; everything else is a success. No-ops entirely unless traffic tracking is enabled, and never affects the response — recording failures are swallowed.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ HeartbeatMiddleware

Returns a new instance of HeartbeatMiddleware.



11
12
13
# File 'lib/dispatch/rails/heartbeat_middleware.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/dispatch/rails/heartbeat_middleware.rb', line 15

def call(env)
  status, headers, body = @app.call(env)
  record(env, errored: status.to_i >= 500)
  [status, headers, body]
rescue Exception # rubocop:disable Lint/RescueException
  record(env, errored: true) # the request happened and failed
  raise
end