Module: Datadog::Tracing::Contrib::HTTPX::Plugin::RequestMethods

Defined in:
lib/httpx/adapters/datadog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#init_timeObject (readonly)

Returns the value of attribute init_time.



183
184
185
# File 'lib/httpx/adapters/datadog.rb', line 183

def init_time
  @init_time
end

Instance Method Details

#initializeObject

intercepts request initialization to inject the tracing logic.



186
187
188
189
190
191
192
193
194
# File 'lib/httpx/adapters/datadog.rb', line 186

def initialize(*)
  super

  @init_time = nil

  return unless Datadog::Tracing.enabled?

  RequestTracer.call(self)
end

#response=(response) ⇒ Object



196
197
198
199
200
201
202
203
204
205
# File 'lib/httpx/adapters/datadog.rb', line 196

def response=(response)
  if response.is_a?(::HTTPX::ErrorResponse) && response.error.respond_to?(:connection)
    # handles the case when the +error+ happened during name resolution, which means
    # that the tracing start point hasn't been triggered yet; in such cases, the approximate
    # initial resolving time is collected from the connection, and used as span start time,
    # and the tracing object in inserted before the on response callback is called.
    @init_time = response.error.connection.init_time
  end
  super
end