Class: Datadog::Tracing::Contrib::Faraday::Middleware

Inherits:
Faraday::Middleware
  • Object
show all
Includes:
HttpAnnotationHelper
Defined in:
lib/datadog/tracing/contrib/faraday/middleware.rb

Overview

Middleware implements a faraday-middleware for datadog instrumentation

Instance Method Summary collapse

Methods included from HttpAnnotationHelper

#service_name

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



20
21
22
23
# File 'lib/datadog/tracing/contrib/faraday/middleware.rb', line 20

def initialize(app, options = {})
  super(app)
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datadog/tracing/contrib/faraday/middleware.rb', line 25

def call(env)
  # Resolve configuration settings to use for this request.
  # Do this once to reduce expensive regex calls.
  request_options = build_request_options!(env)

  Tracing.trace(Ext::SPAN_REQUEST, on_error: request_options[:on_error]) do |span, trace|
    annotate!(span, env, request_options)
    if Datadog::AppSec::Utils::TraceOperation.appsec_standalone_reject?(trace)
      trace.sampling_priority = Tracing::Sampling::Ext::Priority::AUTO_REJECT
    end
    propagate!(trace, span, env) if request_options[:distributed_tracing] && Tracing.enabled?
    app.call(env).on_complete { |resp| handle_response(span, resp, request_options) }
  end
end