Module: OpenTelemetry::Instrumentation::Net::HTTP::Patches::Instrumentation
- Defined in:
- lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb
Overview
Module to prepend to Net::HTTP for instrumentation
Constant Summary collapse
- HTTP_METHODS_TO_SPAN_NAMES =
Hash.new { |h, k| h[k] = "HTTP #{k}" }
- USE_SSL_TO_SCHEME =
{ false => 'http', true => 'https' }.freeze
Instance Method Summary collapse
Instance Method Details
#request(req, body = nil, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/opentelemetry/instrumentation/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? attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes tracer.in_span( HTTP_METHODS_TO_SPAN_NAMES[req.method], attributes: attributes.merge( '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.inject(req) super(req, body, &block).tap do |response| annotate_span_with_response!(span, response) end end end |