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
|
# File 'lib/hypertrace/instrumentation/faraday_patch.rb', line 4
def call(env)
http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
attributes = span_creation_attributes(
http_method: http_method, url: env.url
)
= env..to_h
= Hypertrace::Instrumentation::DataCapture.(,
Hypertrace::Instrumentation::DataCapture::TYPE_REQUEST)
content_type = .find{|k, v| k.downcase == "content-type"}&.last
if Hypertrace::Instrumentation::DataCapture.can_capture?(content_type, Hypertrace::Instrumentation::DataCapture::TYPE_REQUEST)
begin
body_cap = Hypertrace::Instrumentation::DataCapture.capturable_body(env.body.to_s) if env.respond_to?(:body) && env.body.respond_to?(:to_s)
attributes['http.request.body'] = body_cap if body_cap
rescue => e
log.error("error attempting to read faraday request body #{e}")
end
end
attributes.merge!()
tracer.in_span(
"HTTP #{http_method}", attributes: attributes, kind: :client
) do |span|
OpenTelemetry.propagation.inject(env.)
app.call(env).on_complete do |resp|
resp = Faraday::Response.new(resp)
= resp..to_h
Hypertrace::Instrumentation::DataCapture.(,
Hypertrace::Instrumentation::DataCapture::TYPE_RESPONSE) do |k, v|
span.set_attribute(k, v)
end
content_type = .find{|k, v| k.downcase == "content-type"}&.last
if Hypertrace::Instrumentation::DataCapture.can_capture?(content_type, Hypertrace::Instrumentation::DataCapture::TYPE_RESPONSE)
begin
body_cap = Hypertrace::Instrumentation::DataCapture.capturable_body(resp.body)
span.set_attribute('http.response.body', body_cap) if body_cap
rescue => e
log.error("error attempting to read faraday response body #{e}")
end
end
trace_response(span, resp)
end
end
end
|