in lib/aws-xray-sdk/facets/rack.rb [17:62]
def call(env)
header = construct_header(headers: env)
req = ::Rack::Request.new(env)
host = req.host
url_path = req.path
method = req.request_method
seg_name = @recorder.segment_naming.provide_name(host: req.host)
sampled = should_sample?(
header_obj: header, recorder: @recorder, sampling_req:
{ host: host, http_method: method, url_path: url_path, service: seg_name }
)
segment = @recorder.begin_segment seg_name, trace_id: header.root, parent_id: header.parent_id,
sampled: sampled
req_meta = extract_request_meta(req)
segment.merge_http_request request: req_meta unless req_meta.empty?
begin
status, headers, body = @app.call env
resp_meta = {}
resp_meta[:status] = status
resp_obj = ::Rack::Response.new body: body, status: status, headers: headers
if len = resp_obj.content_length
resp_meta[:content_length] = len
end
segment.merge_http_response response: resp_meta
trace_header = {TRACE_HEADER => TraceHeader.from_entity(entity: segment).root_string}
headers.merge!(trace_header)
[status, headers, body]
rescue Exception => e
segment.apply_status_code status: 500
segment.add_exception exception: e
raise e
ensure
@recorder.end_segment
end
end