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



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

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(:datadog_tracing)

    # 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



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

def patch
  require_relative 'middleware'

  register_middleware!
  add_default_middleware!
end

.register_middleware!Object



29
30
31
# File 'lib/datadog/tracing/contrib/faraday/patcher.rb', line 29

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

.target_versionObject



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

def target_version
  Integration.version
end