-
Notifications
You must be signed in to change notification settings - Fork 369
/
statistics.rb
43 lines (38 loc) · 1.23 KB
/
statistics.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
require 'ddtrace/transport/statistics'
module Datadog
module Transport
module HTTP
# Tracks statistics for HTTP transports
module Statistics
def self.included(base)
base.send(:include, Datadog::Transport::Statistics)
base.send(:include, InstanceMethods)
end
# Instance methods for HTTP statistics
module InstanceMethods
# Decorate metrics for HTTP responses
def metrics_for_response(response)
super.tap do |metrics|
# Add status code tag to api.responses metric
if metrics.key?(:api_responses)
(metrics[:api_responses].options[:tags] ||= []).tap do |tags|
tags << metrics_tag_value(response.code)
end
end
end
end
private
# The most common status code on a healthy tracer
STATUS_CODE_200 = 'status_code:200'.freeze
def metrics_tag_value(status_code)
if status_code == 200
STATUS_CODE_200 # DEV Saves string concatenation/creation for common case
else
"status_code:#{status_code}"
end
end
end
end
end
end
end