lib/hypertrace/instrumentation/data_capture.rb in hypertrace-agent-0.1.0 vs lib/hypertrace/instrumentation/data_capture.rb in hypertrace-agent-0.1.1

- old
+ new

@@ -1,6 +1,7 @@ class Hypertrace::Instrumentation::DataCapture + include Hypertrace::Logging TYPE_REQUEST = 'request' TYPE_RESPONSE = 'response' CONTENT_TYPE_SUBSTRINGS = %w[json x-www-form-urlencoded] def self.headers_to_attribute_keys header_hash, type, &block @@ -19,21 +20,26 @@ return if block_given? return attrs end def self.capturable_body body_object - max_capture = Hypertrace::RubyAgent.config.data_capture.body_max_size_bytes.value - if body_object.is_a?(String) - return body_object.byteslice(0..max_capture) - elsif body_object.is_a?(StringIO) - result = body_object.read(max_capture) - body_object.rewind - return result + begin + max_capture = Hypertrace::RubyAgent.config.data_capture.body_max_size_bytes.value + if body_object.is_a?(String) + return body_object.byteslice(0..max_capture) + elsif body_object.is_a?(StringIO) + result = body_object.read(max_capture) + body_object.rewind + return result + end + rescue => e + log.error("Erroring reading response body" + e.backtrace&.join("\n")) end end def self.can_capture?(content_type, type) + content_type = content_type.join('') if content_type.is_a?(Array) return false unless content_type return false unless body_allowed_by_config?(type) content_type = content_type.downcase CONTENT_TYPE_SUBSTRINGS.each do |substring| @@ -51,7 +57,6 @@ def self.body_allowed_by_config? type return Hypertrace::RubyAgent.config.data_capture.http_body.request.value if type == TYPE_REQUEST Hypertrace::RubyAgent.config.data_capture.http_body.response.value end - end \ No newline at end of file