Module: OpenTelemetry::Instrumentation::HTTPX::Stable::RequestTracer

Extended by:
RequestTracer
Included in:
RequestTracer
Defined in:
lib/opentelemetry/instrumentation/httpx/stable/plugin.rb

Overview

Instruments around HTTPX's request/response lifecycle in order to generate an OTEL trace.

Instance Method Summary collapse

Instance Method Details

#call(request) ⇒ Object

initializes tracing on the +request+.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/opentelemetry/instrumentation/httpx/stable/plugin.rb', line 27

def call(request)
  span = nil

  # request objects are reused, when already buffered requests get rerouted to a different
  # connection due to connection issues, or when they already got a response, but need to
  # be retried. In such situations, the original span needs to be extended for the former,
  # while a new is required for the latter.
  request.on(:idle) do
    span = nil
  end
  # the span is initialized when the request is buffered in the parser, which is the closest
  # one gets to actually sending the request.
  request.on(:headers) do
    next if span

    span = initialize_span(request)
  end

  request.on(:response) do |response|
    span = initialize_span(request, request.init_time) if !span && request.init_time

    finish(response, span)
  end
end