Module: Datadog::Tracing::Contrib::Httpclient::Instrumentation::InstanceMethods

Includes:
Datadog::Tracing::Contrib::HttpAnnotationHelper
Defined in:
lib/datadog/tracing/contrib/httpclient/instrumentation.rb

Overview

Instance methods for configuration

Instance Method Summary collapse

Methods included from Datadog::Tracing::Contrib::HttpAnnotationHelper

#service_name

Instance Method Details

#do_get_block(req, proxy, conn, &block) ⇒ 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
# File 'lib/datadog/tracing/contrib/httpclient/instrumentation.rb', line 20

def do_get_block(req, proxy, conn, &block)
  host = req.header.request_uri.host
  request_options = datadog_configuration(host)
  client_config = Datadog.configuration_for(self)

  Tracing.trace(Ext::SPAN_REQUEST, on_error: method(:annotate_span_with_error!)) do |span, trace|
    begin
      span.service = service_name(host, request_options, client_config)
      span.span_type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND

      if Tracing.enabled? && !should_skip_distributed_tracing?(client_config)
        Tracing::Propagation::HTTP.inject!(trace, req.header)
      end

      # Add additional request specific tags to the span.
      annotate_span_with_request!(span, req, request_options)
    rescue StandardError => e
      logger.error("error preparing span for httpclient request: #{e}, Source: #{e.backtrace}")
    ensure
      res = super
    end

    # Add additional response specific tags to the span.
    annotate_span_with_response!(span, res, request_options)

    res
  end
end