module OpenTelemetry::Adapters::Net::HTTP::Patches::Instrumentation
Module to prepend to Net::HTTP
for instrumentation
Constants
- HTTP_METHODS_TO_SPAN_NAMES
- USE_SSL_TO_SCHEME
Public Instance Methods
request(req, body = nil, &block)
click to toggle source
Calls superclass method
# File lib/opentelemetry/adapters/net/http/patches/instrumentation.rb, line 17 def request(req, body = nil, &block) # Do not trace recursive call for starting the connection return super(req, body, &block) unless started? tracer.in_span( HTTP_METHODS_TO_SPAN_NAMES[req.method], attributes: { 'component' => 'http', 'http.method' => req.method, 'http.scheme' => USE_SSL_TO_SCHEME[use_ssl?], 'http.target' => req.path, 'peer.hostname' => @address, 'peer.port' => @port }, kind: :client ) do |span| OpenTelemetry.propagation.http.inject(req) super(req, body, &block).tap do |response| annotate_span_with_response!(span, response) end end end
Private Instance Methods
annotate_span_with_response!(span, response)
click to toggle source
# File lib/opentelemetry/adapters/net/http/patches/instrumentation.rb, line 43 def annotate_span_with_response!(span, response) return unless response&.code status_code = response.code.to_i span.set_attribute('http.status_code', status_code) span.status = OpenTelemetry::Trace::Status.http_to_status( status_code ) end
tracer()
click to toggle source
# File lib/opentelemetry/adapters/net/http/patches/instrumentation.rb, line 54 def tracer Net::HTTP::Adapter.instance.tracer end