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

Inherits:
Faraday::Middleware
  • Object
show all
Includes:
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, Ext::DistributedTracing::PROPAGATION_INJECT_STYLE_ENV, Ext::DistributedTracing::PROPAGATION_STYLE_B3, Ext::DistributedTracing::PROPAGATION_STYLE_B3_SINGLE_HEADER, Ext::DistributedTracing::PROPAGATION_STYLE_DATADOG, Ext::DistributedTracing::SAMPLING_PRIORITY_KEY

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Middleware.



15
16
17
18
19
# File 'lib/ddtrace/contrib/faraday/middleware.rb', line 15

def initialize(app, options = {})
  super(app)
  @options = datadog_configuration.options_hash.merge(options)
  setup_service!
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/ddtrace/contrib/faraday/middleware.rb', line 21

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