lib/hypertrace/instrumentation/rack.rb in hypertrace-agent-0.1.0 vs lib/hypertrace/instrumentation/rack.rb in hypertrace-agent-0.1.1
- old
+ new
@@ -1,8 +1,10 @@
# frozen_string_literal: true
class OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware
+ include Hypertrace::Logging
+
def call(env)
if untraced_request?(env)
OpenTelemetry::Common::Utilities.untraced do
return @app.call(env)
end
@@ -39,16 +41,20 @@
Hypertrace::Instrumentation::DataCapture.headers_to_attribute_keys(response_headers, Hypertrace::Instrumentation::DataCapture::TYPE_RESPONSE)
response_headers.each do |h_k, h_v|
request_span.set_attribute("http.response.header.#{h_k.downcase}", h_v)
end
content_type_arr = response_headers.find{|x|x[0].downcase == "content-type"}
- if Hypertrace::Instrumentation::DataCapture.can_capture?(content_type_arr&.join(''),
- Hypertrace::Instrumentation::DataCapture::TYPE_RESPONSE)
- cap_body = Hypertrace::Instrumentation::RackCompatible.extract_response_body(response)
- request_span.set_attribute('http.response.body', cap_body) if cap_body
- end
+ begin
+ if Hypertrace::Instrumentation::DataCapture.can_capture?(content_type_arr&.join(''),
+ Hypertrace::Instrumentation::DataCapture::TYPE_RESPONSE)
+ cap_body = Hypertrace::Instrumentation::RackCompatible.extract_response_body(response)
+ request_span.set_attribute('http.response.body', cap_body) if cap_body
+ end
- set_attributes_after_request(request_span, status, headers, response)
+ set_attributes_after_request(request_span, status, headers, response)
+ rescue => e
+ log.error("Error in Hypertrace response capture" + e.backtrace&.join("\n"))
+ end
end
end
end
end
ensure
\ No newline at end of file