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

Includes:
Patcher
Defined in:
lib/ddtrace/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



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

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



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

def patch
  require 'ddtrace/contrib/faraday/middleware'

  register_middleware!
  add_default_middleware!
end

.register_middleware!Object



28
29
30
# File 'lib/ddtrace/contrib/faraday/patcher.rb', line 28

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

.target_versionObject



17
18
19
# File 'lib/ddtrace/contrib/faraday/patcher.rb', line 17

def target_version
  Integration.version
end