Module: Datadog::Tracing::Contrib::Faraday::Patcher

Includes:
Patcher
Defined in:
lib/datadog/tracing/contrib/faraday/patcher.rb

Overview

Patcher enables patching of ‘faraday’ module.

Class Method Summary collapse

Methods included from Patcher

included

Class Method Details

.add_default_middleware!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/datadog/tracing/contrib/faraday/patcher.rb', line 31

def add_default_middleware!
  if target_version >= Gem::Version.new('1.0.0')
    # Patch the default connection (e.g. +Faraday.get+)
    ::Faraday.default_connection.use(:ddtrace)

    # Patch new connection instances (e.g. +Faraday.new+)
    ::Faraday::Connection.prepend(Connection)
  else
    # Patch the default connection (e.g. +Faraday.get+)
    #
    # We insert our middleware before the 'adapter', which is
    # always the last handler.
    idx = ::Faraday.default_connection.builder.handlers.size - 1
    ::Faraday.default_connection.builder.insert(idx, Middleware)

    # Patch new connection instances (e.g. +Faraday.new+)
    ::Faraday::RackBuilder.prepend(RackBuilder)
  end
end

.patchObject



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

def patch
  require_relative 'middleware'

  register_middleware!
  add_default_middleware!
end

.register_middleware!Object



27
28
29
# File 'lib/datadog/tracing/contrib/faraday/patcher.rb', line 27

def register_middleware!
  ::Faraday::Middleware.register_middleware(ddtrace: Middleware)
end

.target_versionObject



16
17
18
# File 'lib/datadog/tracing/contrib/faraday/patcher.rb', line 16

def target_version
  Integration.version
end