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
51
52
53
54
55
|
# File 'lib/opentrace/http_tracker.rb', line 7
def request(req, body = nil, &block)
return super unless OpenTrace.enabled?
return super if Fiber[:opentrace_http_tracking_disabled]
inject_trace_context(req) if OpenTrace.config.trace_propagation
collector = Fiber[:opentrace_collector]
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
response = super
duration_ms = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000
host = address
port_str = (port == 443 || port == 80) ? "" : ":#{port}"
scheme = use_ssl? ? "https" : "http"
url = "#{scheme}://#{host}#{port_str}#{req.path}"
if collector
collector.record_http(
method: req.method,
url: url,
host: host,
status: response.code.to_i,
duration_ms: duration_ms
)
end
response
rescue IOError, SystemCallError, OpenSSL::SSL::SSLError, Timeout::Error, Net::ProtocolError => e
duration_ms = start_time ? (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000 : 0
if collector
collector.record_http(
method: req&.method,
url: "#{address}#{req&.path}",
host: address,
status: 0,
duration_ms: duration_ms,
error: e.class.name
)
end
raise end
|