-
Notifications
You must be signed in to change notification settings - Fork 390
/
action_controller_notify_subscriber.rb
50 lines (42 loc) · 1.14 KB
/
action_controller_notify_subscriber.rb
1
2
3
4
5
6
7
8
9
10
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module Airbrake
module Rails
# ActionControllerNotifySubscriber sends route stat information, including
# performance data.
#
# @since v8.0.0
class ActionControllerNotifySubscriber
def initialize(notifier, routes)
@notifier = notifier
@routes = routes
end
def call(*args)
return if @routes.none?
event = ActiveSupport::Notifications::Event.new(*args)
payload = event.payload
@routes.each do |route, method|
@notifier.notify(
Airbrake::Request.new(
method: method,
route: route,
status_code: find_status_code(payload),
start_time: event.time,
end_time: Time.new
)
)
end
end
private
def find_status_code(payload)
return payload[:status] if payload[:status]
if payload[:exception]
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(
payload[:exception].first
)
status = 500 if status == 0
return status
end
0
end
end
end
end