Module: Datadog::Monkey

Defined in:
lib/ddtrace/monkey.rb

Overview

Monkey is used for monkey-patching 3rd party libs.

Class Method Summary collapse

Class Method Details

.autopatch_modulesObject



27
28
29
# File 'lib/ddtrace/monkey.rb', line 27

def autopatch_modules
  @autopatch_modules.clone
end

.get_patched_modulesObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ddtrace/monkey.rb', line 49

def get_patched_modules
  patched = autopatch_modules
  @autopatch_modules.each do |k, v|
    @mutex.synchronize do
      if v
        patcher = @patchers[k]
        patched[k] = patcher.patched? if patcher
      end
    end
  end
  patched
end

.patch(modules) ⇒ Object



43
44
45
46
47
# File 'lib/ddtrace/monkey.rb', line 43

def patch(modules)
  modules.each do |k, v|
    patch_module(k) if v
  end
end

.patch_allObject



31
32
33
# File 'lib/ddtrace/monkey.rb', line 31

def patch_all
  patch @autopatch_modules
end

.patch_module(m) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/ddtrace/monkey.rb', line 35

def patch_module(m)
  @mutex.synchronize do
    patcher = @patchers[m]
    raise 'Unsupported module #{m}' unless patcher
    patcher.patch
  end
end

.without_warningsObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ddtrace/monkey.rb', line 62

def without_warnings
  # This is typically used when monkey patching functions such as
  # intialize, which Ruby advices you not to. Use cautiously.
  v = $VERBOSE
  $VERBOSE = nil
  begin
    yield
  ensure
    $VERBOSE = v
  end
end