Module: Datadog::Tracing::Contrib::Httprb::Instrumentation::InstanceMethods

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

Overview

Instance methods for configuration

Instance Method Summary collapse

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

#service_name

Instance Method Details

#perform(req, options) ⇒ Object



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
48
49
50
51
52
53
# File 'lib/datadog/tracing/contrib/httprb/instrumentation.rb', line 23

def perform(req, options)
  host = req.uri.host if req.respond_to?(:uri) && req.uri
  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.type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND

      if Datadog::AppSec::Utils::TraceOperation.appsec_standalone_reject?(trace)
        trace.sampling_priority = Tracing::Sampling::Ext::Priority::AUTO_REJECT
      end

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

      # 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 http.rb request: #{e}, Source: #{e.backtrace}")
      Datadog::Core::Telemetry::Logger.report(e)
    ensure
      res = super(req, options)
    end

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

    res
  end
end