Module: OpenTelemetry::Instrumentation::Net::HTTP::Patches::Stable::Instrumentation

Defined in:
lib/opentelemetry/instrumentation/net/http/patches/stable/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
45
46
47
48
49
# File 'lib/opentelemetry/instrumentation/net/http/patches/stable/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?

  attributes = {
    'http.request.method' => req.method,
    'url.scheme' => USE_SSL_TO_SCHEME[use_ssl?],
    'server.address' => @address,
    'server.port' => @port
  }
  path, query = split_path_and_query(req.path)
  attributes['url.path'] = path
  attributes['url.query'] = query if query

  attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)

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

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