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

Inherits:
Faraday::Middleware
  • Object
show all
Includes:
HttpAnnotationHelper, Ext::DistributedTracing
Defined in:
lib/ddtrace/contrib/faraday/middleware.rb

Overview

Middleware implements a faraday-middleware for ddtrace instrumentation

Constant Summary

Constants included from Ext::DistributedTracing

Ext::DistributedTracing::B3_HEADER_SAMPLED, Ext::DistributedTracing::B3_HEADER_SINGLE, Ext::DistributedTracing::B3_HEADER_SPAN_ID, Ext::DistributedTracing::B3_HEADER_TRACE_ID, Ext::DistributedTracing::GRPC_METADATA_ORIGIN, Ext::DistributedTracing::GRPC_METADATA_PARENT_ID, Ext::DistributedTracing::GRPC_METADATA_SAMPLING_PRIORITY, Ext::DistributedTracing::GRPC_METADATA_TRACE_ID, Ext::DistributedTracing::HTTP_HEADER_ORIGIN, Ext::DistributedTracing::HTTP_HEADER_PARENT_ID, Ext::DistributedTracing::HTTP_HEADER_SAMPLING_PRIORITY, Ext::DistributedTracing::HTTP_HEADER_TRACE_ID, Ext::DistributedTracing::ORIGIN_KEY, Ext::DistributedTracing::PROPAGATION_EXTRACT_STYLE_ENV_OLD, Ext::DistributedTracing::PROPAGATION_INJECT_STYLE_ENV_OLD, Ext::DistributedTracing::PROPAGATION_STYLE_B3, Ext::DistributedTracing::PROPAGATION_STYLE_B3_SINGLE_HEADER, Ext::DistributedTracing::PROPAGATION_STYLE_DATADOG, Ext::DistributedTracing::PROPAGATION_STYLE_EXTRACT_ENV, Ext::DistributedTracing::PROPAGATION_STYLE_INJECT_ENV, Ext::DistributedTracing::SAMPLING_PRIORITY_KEY

Instance Method Summary collapse

Methods included from HttpAnnotationHelper

#service_name

Constructor Details

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

Returns a new instance of Middleware.



19
20
21
22
# File 'lib/ddtrace/contrib/faraday/middleware.rb', line 19

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

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ddtrace/contrib/faraday/middleware.rb', line 24

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)

  request_options[:tracer].trace(Ext::SPAN_REQUEST) do |span|
    annotate!(span, env, request_options)
    propagate!(span, env) if request_options[:distributed_tracing] && request_options[:tracer].enabled
    app.call(env).on_complete { |resp| handle_response(span, resp, request_options) }
  end
end