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
|
# File 'lib/slack_bot/events/middleware/event_tracer.rb', line 7
def call(type:, socket_event:, schema: nil, parsed_data: nil, **params)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
temp_type = type.dup.to_s
case type
when :close
additional_info = "code: #{socket_event.code} reason:#{socket_event.reason}"
when :message
case parsed_data.dig("type")
when "app_rate_limited"
temp_type += ":#{parsed_data.dig("type")}"
additional_info = "minute_rate_limited:#{parsed_data["minute_rate_limited"]} " \
"team_id:#{parsed_data["team_id"]} " \
"api_app_id:#{parsed_data["api_app_id"]}"
else
accurate_type = parsed_data.dig("payload","event","subtype") || parsed_data.dig("payload","event","type")
p_type = [
parsed_data.dig("type"),
accurate_type
].compact.join(":")
temp_type += ":#{p_type}"
end
end
Events.logger.info { "[Event Received] #{temp_type} #{additional_info}" }
yield
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
Events.logger.info { "[Event Finished] #{temp_type} [#{(elapsed_time * 1000).round(2)}ms]" }
end
|