From 5f8f2b007871f89c53cac9f2d0d45d609e2ddef3 Mon Sep 17 00:00:00 2001 From: fallwith Date: Mon, 21 Oct 2024 15:05:58 -0700 Subject: [PATCH 1/2] DD templating: conditionally invoke requires as per #2844, don't perform `require_relative` on content that won't be used unless all dependency detection checks succeed --- .../templates/dependency_detection.tt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tasks/instrumentation_generator/templates/dependency_detection.tt b/lib/tasks/instrumentation_generator/templates/dependency_detection.tt index e5c82ebb6f..b1af9b4535 100644 --- a/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +++ b/lib/tasks/instrumentation_generator/templates/dependency_detection.tt @@ -2,10 +2,6 @@ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. # frozen_string_literal: true -require_relative '<%= @snake_name.downcase %>/instrumentation' -require_relative '<%= @snake_name.downcase %>/chain' -require_relative '<%= @snake_name.downcase %>/prepend' - DependencyDetection.defer do named :<%= @name.match?(/\-|\_/) ? "'#{@snake_name}'" : @name.downcase %> @@ -18,6 +14,10 @@ DependencyDetection.defer do end executes do + require_relative '<%= @snake_name.downcase %>/instrumentation' + require_relative '<%= @snake_name.downcase %>/chain' + require_relative '<%= @snake_name.downcase %>/prepend' + # prepend_instrument and chain_instrument call extract_supportability_name # to get the library name for supportability metrics and info-level logging. # This is done by spliting on the 2nd to last spot of the instrumented From 1c6d8a35f40240168f043379b4d9f9947fa89877 Mon Sep 17 00:00:00 2001 From: fallwith Date: Mon, 21 Oct 2024 16:21:29 -0700 Subject: [PATCH 2/2] DD: require only prepend OR chain DD code when chaining or prepending, only bring in the appropriate chain or prepend code --- .../templates/dependency_detection.tt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/instrumentation_generator/templates/dependency_detection.tt b/lib/tasks/instrumentation_generator/templates/dependency_detection.tt index b1af9b4535..7c82ca7f35 100644 --- a/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +++ b/lib/tasks/instrumentation_generator/templates/dependency_detection.tt @@ -15,17 +15,17 @@ DependencyDetection.defer do executes do require_relative '<%= @snake_name.downcase %>/instrumentation' - require_relative '<%= @snake_name.downcase %>/chain' - require_relative '<%= @snake_name.downcase %>/prepend' # prepend_instrument and chain_instrument call extract_supportability_name - # to get the library name for supportability metrics and info-level logging. + # to get the library name for supportability metrics and info-level logging. # This is done by spliting on the 2nd to last spot of the instrumented # module. If this isn't how we want the name to appear, pass in the desired # name as a third argument. if use_prepend? + require_relative '<%= @snake_name.downcase %>/prepend' prepend_instrument <%= @class_name %>, NewRelic::Agent::Instrumentation::<%= @class_name %>::Prepend else + require_relative '<%= @snake_name.downcase %>/chain' chain_instrument NewRelic::Agent::Instrumentation::<%= @class_name %>::Chain end end