lib/instana/instrumentation/net-http.rb in instana-0.14.0 vs lib/instana/instrumentation/net-http.rb in instana-0.14.2
- old
+ new
@@ -9,39 +9,51 @@
::Instana.tracer.log_entry(:'net-http')
# Send out the tracing context with the request
request = args[0]
- our_trace_id = ::Instana.tracer.trace_id
- our_span_id = ::Instana.tracer.span_id
# Set request headers; encode IDs as hexadecimal strings
- request['X-Instana-T'] = ::Instana.tracer.id_to_header(our_trace_id)
- request['X-Instana-S'] = ::Instana.tracer.id_to_header(our_span_id)
+ request['X-Instana-T'] = ::Instana.tracer.trace_id_header
+ request['X-Instana-S'] = ::Instana.tracer.span_id_header
+ # Collect up KV info now in case any exception is raised
+ kv_payload = { :http => {} }
+ kv_payload[:http][:method] = request.method
+
+ if request.uri
+ kv_payload[:http][:url] = request.uri.to_s
+ else
+ if use_ssl?
+ kv_payload[:http][:url] = "https://#{@address}:#{@port}#{request.path}"
+ else
+ kv_payload[:http][:url] = "http://#{@address}:#{@port}#{request.path}"
+ end
+ end
+
+ # The core call
response = request_without_instana(*args, &block)
# Pickup response headers; convert back to base 10 integer
- if response.key?('X-Instana-T')
- their_trace_id = ::Instana.tracer.header_to_id(response.header['X-Instana-T'])
-
- if our_trace_id != their_trace_id
- ::Instana.logger.debug "#{Thread.current}: Trace ID mismatch on net/http response! ours: #{our_trace_id} theirs: #{their_trace_id}"
+ if ::Instana.debug? && response.key?('X-Instana-T')
+ if ::Instana.tracer.trace_id != ::Instana.tracer.header_to_id(response.header['X-Instana-T'])
+ ::Instana.logger.debug "#{Thread.current}: Trace ID mismatch on net/http response! ours: #{::Instana.tracer.trace_id} theirs: #{their_trace_id}"
end
end
- kv_payload = { :http => {} }
kv_payload[:http][:status] = response.code
- kv_payload[:http][:url] = request.uri.to_s
- kv_payload[:http][:method] = request.method
- ::Instana.tracer.log_info(kv_payload)
+ if response.code.to_i.between?(500, 511)
+ # Because of the 5xx response, we flag this span as errored but
+ # without a backtrace (no exception)
+ add_error(nil)
+ end
response
rescue => e
::Instana.tracer.log_error(e)
raise
ensure
- ::Instana.tracer.log_exit(:'net-http')
+ ::Instana.tracer.log_exit(:'net-http', kv_payload)
end
Instana.logger.warn "Instrumenting Net::HTTP"
alias request_without_instana request