Module: OpenTelemetry::Instrumentation::Net::HTTP::Patches::Old::Instrumentation

Defined in:
lib/opentelemetry/instrumentation/net/http/patches/old/instrumentation.rb

Overview

Module to prepend to Net::HTTP for instrumentation

Constant Summary collapse

USE_SSL_TO_SCHEME =
{ false => 'http', true => 'https' }.freeze
HTTP_STATUS_SUCCESS_RANGE =

Constant for the HTTP status range

(100..399)

Instance Method Summary collapse

Instance Method Details

#request(req, body = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/opentelemetry/instrumentation/net/http/patches/old/instrumentation.rb', line 20

def request(req, body = nil, &)
  # Do not trace recursive call for starting the connection
  return super unless started?

  return super if untraced?

  span_data = HttpHelper.span_attrs_for_old(req.method)

  attributes = { OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => USE_SSL_TO_SCHEME[use_ssl?],
                 OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => req.path,
                 OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => @address,
                 OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => @port }.merge!(span_data.attributes)

  tracer.in_span(
    span_data.span_name,
    attributes: attributes,
    kind: :client
  ) do |span|
    OpenTelemetry.propagation.inject(req)

    super.tap do |response|
      annotate_span_with_response!(span, response)
    end
  end
end