lib/tasks/instrumentation_generator/instrumentation.thor in newrelic_rpm-8.10.1 vs lib/tasks/instrumentation_generator/instrumentation.thor in newrelic_rpm-8.11.0

- old
+ new

@@ -1,6 +1,5 @@ -# encoding: utf-8 # This file is distributed under New Relic's license terms. # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details. # frozen_string_literal: true require_relative '../../new_relic/language_support' @@ -33,17 +32,13 @@ @name = name @method = options[:method] if options[:method] @args = options[:args] if options[:args] @class_name = ::NewRelic::LanguageSupport.camelize(name) base_path = "#{INSTRUMENTATION_ROOT}#{name.downcase}" - empty_directory(base_path) - ['chain', 'instrumentation', 'prepend'].each do |file| - template("templates/#{file}.tt", "#{base_path}/#{file}.rb") - end - - template('templates/dependency_detection.tt', "#{base_path}.rb") + empty_directory(base_path) + create_instrumentation_files(base_path) create_configuration(name) create_tests(name) end desc 'add_new_method NAME', 'Inserts a new method into an existing piece of instrumentation' @@ -59,10 +54,18 @@ # move the method content to a partial end private + def create_instrumentation_files(base_path) + %w[chain instrumentation prepend].each do |file| + template("templates/#{file}.tt", "#{base_path}/#{file}.rb") + end + + template('templates/dependency_detection.tt', "#{base_path}.rb") + end + def create_tests(name) @name = name @instrumentation_method_global_erb_snippet = '<%= $instrumentation_method %>' base_path = "#{MULTIVERSE_SUITE_ROOT}#{@name.downcase}" empty_directory(base_path) @@ -72,25 +75,28 @@ empty_directory("#{base_path}/config") template('templates/newrelic.yml.tt', "#{base_path}/config/newrelic.yml") end def create_configuration(name) - config = <<-CONFIG - :'instrumentation.#{name.downcase}' => { + insert_into_file( + DEFAULT_SOURCE_LOCATION, + config_block(name.downcase), + after: ":description => 'Controls auto-instrumentation of bunny at start up. May be one of [auto|prepend|chain|disabled].' + },\n" + ) + end + + def config_block(library) + <<-CONFIG + :'instrumentation.#{library}' => { :default => 'auto', :public => true, :type => String, :dynamic_name => true, :allowed_from_server => false, - :description => 'Controls auto-instrumentation of the #{name.downcase} library at start up. May be one of [auto|prepend|chain|disabled].' + :description => 'Controls auto-instrumentation of the #{library} library at start up. May be one of [auto|prepend|chain|disabled].' }, CONFIG - insert_into_file( - DEFAULT_SOURCE_LOCATION, - config, - after: ":description => 'Controls auto-instrumentation of bunny at start up. May be one of [auto|prepend|chain|disabled].' - },\n" - ) end end Instrumentation.start(ARGV)