Module: Contrast::Agent::Patching::Policy::Patcher

Extended by:
AfterLoadPatcher, Components::Logger::InstanceMethods, Components::Scope::InstanceMethods, Utils::Patching::PatcherUtils
Defined in:
lib/contrast/agent/patching/policy/patcher.rb

Overview

This is how we patch into our customer’s code. It provides a way to track which classes we need to patch into and, once we’ve woven, provides a map for which methods our renamed functions need to call and how.

Constant Summary collapse

PATCH_MONITOR =

Hook to only monkeypatch Contrast. This will not trigger any other functions, like rewriting or scanning. Exposed for those situations, like ActiveRecord dynamically defining functions, where only a subset of the Assess changes are needed.

Monitor.new

Class Method Summary collapse

Methods included from AfterLoadPatcher

catchup_after_load_patches

Methods included from Components::Logger::InstanceMethods

cef_logger, logger

Methods included from Utils::Patching::PatcherUtils

patch_method, patch_specific_module

Methods included from Components::Scope::InstanceMethods

contrast_enter_method_scopes!, contrast_exit_method_scopes!, with_app_scope, with_contrast_scope, with_deserialization_scope, with_split_scope

Class Method Details

.catchup_loaded_methodsObject

Iterate over and patch those Modules and Methods which were loaded before the Agent was enabled.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/contrast/agent/patching/policy/patcher.rb', line 66

def catchup_loaded_methods
  PATCH_MONITOR.synchronize do
    t = Contrast::Agent::Thread.new do
      synchronized_catchup_loaded_methods
    end
    # aborting on exception makes exceptions propagate.
    t.abort_on_exception = true
    t.priority = Thread.current.priority + 1
    t.join
  end
end

.patchObject

Hook to install the Contrast changes needed to allow for the instrumentation of the application - this only occurs once, during startup to catchup on everything we didn’t see get loaded



54
55
56
57
# File 'lib/contrast/agent/patching/policy/patcher.rb', line 54

def patch
  catchup_after_load_patches
  catchup_loaded_methods
end