module OpenTelemetry::Instrumentation::HttpClient::Patches::Client
Module to prepend to HTTPClient for instrumentation
Private Instance Methods
annotate_span_with_response!(span, response)
click to toggle source
# File lib/opentelemetry/instrumentation/http_client/patches/client.rb, line 38 def annotate_span_with_response!(span, response) return unless response&.status_code status_code = response.status_code.to_i span.set_attribute('http.status_code', status_code) span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(status_code.to_i) end
do_get_block(req, proxy, conn, &block)
click to toggle source
Calls superclass method
# File lib/opentelemetry/instrumentation/http_client/patches/client.rb, line 15 def do_get_block(req, proxy, conn, &block) # rubocop:disable Metrics/AbcSize uri = req.header.request_uri url = "#{uri.scheme}://#{uri.host}" request_method = req.header.request_method attributes = { 'http.method' => request_method, 'http.scheme' => uri.scheme, 'http.target' => uri.path, 'http.url' => url, 'peer.hostname' => uri.host, '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.header) super.tap do response = conn.pop annotate_span_with_response!(span, response) conn.push response end end end
tracer()
click to toggle source
# File lib/opentelemetry/instrumentation/http_client/patches/client.rb, line 47 def tracer HttpClient::Instrumentation.instance.tracer end