Module: OpenTelemetry::Instrumentation::HTTP::Patches::Client

Defined in:
lib/opentelemetry/instrumentation/http/patches/client.rb

Overview

Module to prepend to HTTP::Client for instrumentation

Instance Method Summary collapse

Instance Method Details

#perform(req, options) ⇒ Object

rubocop:disable Metrics/AbcSize



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/opentelemetry/instrumentation/http/patches/client.rb', line 13

def perform(req, options) # rubocop:disable Metrics/AbcSize
  uri = req.uri
  request_method = req.verb.to_s.upcase

  attributes = {
    'http.method' => request_method,
    'http.scheme' => uri.scheme,
    'http.target' => uri.path,
    'http.url' => "#{uri.scheme}://#{uri.host}",
    'net.peer.name' => uri.host,
    'net.peer.port' => uri.port
  }.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)

  tracer.in_span("HTTP #{request_method}", attributes: attributes, kind: :client) do |span|
    OpenTelemetry.propagation.inject(req.headers)
    super.tap do |response|
      annotate_span_with_response!(span, response)
    end
  end
end