Class: Monitorbit::ErrorsNotificationsLayer

Inherits:
Object
  • Object
show all
Defined in:
lib/monitorbit/errors_notifications_layer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ErrorsNotificationsLayer

Returns a new instance of ErrorsNotificationsLayer.



5
6
7
# File 'lib/monitorbit/errors_notifications_layer.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/monitorbit/errors_notifications_layer.rb', line 9

def call(env)
  status, headers, body = @app.call(env)

  if status.between?(400, 600)
    request = Rack::Request.new(env)

    ActiveSupport::Notifications.instrument(
      'monitorbit.4xx_5xx_errors',
      path: request.path,
      ip: request.ip,
      params: request.params,
      method: request.request_method,
      status: status
    )
  end

  [status, headers, body]
end