lib/contrast/agent/patching/policy/patcher.rb in contrast-agent-3.14.0 vs lib/contrast/agent/patching/policy/patcher.rb in contrast-agent-3.15.0
- old
+ new
@@ -75,23 +75,25 @@
end
# This method is called by TracePointHook to instrument a specific class during a require
# or eval of dynamic class definition
def patch_specific_module mod
- mod_name = mod.cs__name
- return unless Contrast::Utils::ClassUtil.truly_defined?(mod_name)
- return if AGENT.skip_instrumentation?(mod_name)
+ with_contrast_scope do
+ mod_name = mod.cs__name
+ return unless Contrast::Utils::ClassUtil.truly_defined?(mod_name)
+ return if AGENT.skip_instrumentation?(mod_name)
- load_patches_for_module(mod_name)
+ load_patches_for_module(mod_name)
- return unless all_module_names.any? { |name| name == mod_name }
+ return unless all_module_names.any? { |name| name == mod_name }
- module_data = Contrast::Agent::ModuleData.new(mod, mod_name)
- patch_into_module(module_data)
- all_module_names.delete(mod_name) if status_type.get_status(mod).patched?
- rescue StandardError => e
- logger.error('Unable to patch module', e, module: mod_name)
+ module_data = Contrast::Agent::ModuleData.new(mod, mod_name)
+ patch_into_module(module_data)
+ all_module_names.delete(mod_name) if status_type.get_status(mod).patched?
+ rescue StandardError => e
+ logger.error('Unable to patch module', e, module: mod_name)
+ end
end
# We did it, team. We found a patcher(s) that applies to the given
# class (or module) and the given method. Time to do some tracking.
#
@@ -184,11 +186,11 @@
module_policy = Contrast::Agent::Patching::Policy::ModulePolicy.create_module_policy(module_data.name)
clazz = module_data.mod
status.patching!
- patched = include_module(module_data)
+ patched = false
counts = 0
# Monkey patch any methods in this class that have matching nodes in the policy
unless module_policy.empty?
instance_methods = all_instance_methods(clazz, true)
@@ -215,20 +217,9 @@
ensure
logger.trace('Patching complete',
module: module_data.name,
result: Contrast::Agent::Patching::Policy::PatchStatus.get_status(
module_data.mod).patch_status)
- end
-
- # Includes the given module with the
- # Contrast::Extension::Assess::AssessExtension
- # @param module_data [Contrast::Agent::ModuleData] the module, and
- # its name, that's being patched into
- def include_module module_data
- return false unless Contrast::Agent::Assess::Policy::Policy.instance.tracked_classes.include?(module_data.name)
-
- module_data.mod.send(:include, Contrast::Extension::Assess::AssessExtension)
- true
end
# Get all of the instance methods on the given module, excluding
# those from super classes. this list will always include the
# initialize method