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 ddtrace instrumentation

Instance Method Summary collapse

Methods included from HttpAnnotationHelper

#service_name

Constructor Details

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

Returns a new instance of Middleware.



17
18
19
20
# File 'lib/datadog/tracing/contrib/faraday/middleware.rb', line 17

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

Instance Method Details

#call(env) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datadog/tracing/contrib/faraday/middleware.rb', line 22

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)
    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