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
|
# File 'lib/hypertrace/instrumentation/sinatra.rb', line 5
def call env
= OpenTelemetry.propagation.(
env,
getter: OpenTelemetry::Common::Propagation.rack_env_getter
)
OpenTelemetry::Context.with_current() do
attrs = Hypertrace::Instrumentation::RackCompatible.(env, 'http.request.header')
if Hypertrace::Instrumentation::RackCompatible.should_record_env?(env)
body_cap = Hypertrace::Instrumentation::DataCapture.capturable_body(env['rack.input'])
attrs['http.request.body'] = body_cap if body_cap
end
tracer.in_span(
env['PATH_INFO'],
attributes: request_span_attributes(env: env).merge!(attrs),
kind: :server
) do |span|
@app.call(env).tap do |resp|
response_attributes = Hypertrace::Instrumentation::RackCompatible.(resp, 'http.response.header')
if Hypertrace::Instrumentation::RackCompatible.should_record_rack_array?(resp)
cap_body = Hypertrace::Instrumentation::RackCompatible.extract_response_body(resp)
response_attributes['http.response.body'] = cap_body if cap_body
end
span.add_attributes(response_attributes)
trace_response(span, env, resp)
end
end
end
end
|