class DependencyDetection::Dependent
Constants
- AUTO_CONFIG_VALUE
- VALID_CONFIG_VALUES
Attributes
Public Class Methods
Source
# File lib/new_relic/dependency_detection.rb, line 53 def initialize @dependencies = [] @executes = [] @prepend_conflicts = [] @name = nil @config_name = nil end
Public Instance Methods
Source
# File lib/new_relic/dependency_detection.rb, line 143 def allowed_by_config? !(disabled_configured? || deprecated_disabled_configured?) end
Source
# File lib/new_relic/dependency_detection.rb, line 100 def chain_instrument(instrumenting_module, supportability_name = nil) log_and_instrument('MethodChaining', instrumenting_module, supportability_name) do instrumenting_module.instrument! end end
Source
# File lib/new_relic/dependency_detection.rb, line 106 def chain_instrument_target(target, instrumenting_module, supportability_name = nil) NewRelic::Agent.logger.info("Installing deferred #{target} instrumentation") log_and_instrument('MethodChaining', instrumenting_module, supportability_name) do instrumenting_module.instrument!(target) end end
Source
# File lib/new_relic/dependency_detection.rb, line 126 def check_dependencies return false unless allowed_by_config? && dependencies dependencies.all? do |dep| begin dep.call rescue => err NewRelic::Agent.logger.error("Error while detecting #{self.name}:", err) false end end end
Source
# File lib/new_relic/dependency_detection.rb, line 157 def config_key return nil if self.config_name.nil? @config_key ||= "instrumentation.#{self.config_name}".to_sym end
Source
# File lib/new_relic/dependency_detection.rb, line 49 def config_name @config_name || @name end
Source
# File lib/new_relic/dependency_detection.rb, line 195 def config_value return AUTO_CONFIG_VALUE unless config_key fetch_config_value(config_key) end
Source
# File lib/new_relic/dependency_detection.rb, line 65 def configure_as_unsatisfied # TODO: currently using :unsatisfied for Padrino will clobber the value # already set for Sinatra, so skip Padrino and circle back with a # new Padrino specific solution in the future. # # https://github.com/newrelic/newrelic-ruby-agent/issues/2912 return if name == :padrino NewRelic::Agent.config.instance_variable_get(:@cache)[config_key] = :unsatisfied end
Source
# File lib/new_relic/dependency_detection.rb, line 205 def configure_with(new_config_name) self.config_name = new_config_name end
Source
# File lib/new_relic/dependency_detection.rb, line 213 def conflicts_with_prepend(&block) @prepend_conflicts << block if block end
Source
# File lib/new_relic/dependency_detection.rb, line 61 def dependencies_satisfied? !executed and check_dependencies end
Source
# File lib/new_relic/dependency_detection.rb, line 139 def depends_on(&block) @dependencies << block if block end
Source
# File lib/new_relic/dependency_detection.rb, line 147 def deprecated_disabled_configured? return false if self.name.nil? key = "disable_#{self.name}".to_sym return false unless ::NewRelic::Agent.config[key] == true ::NewRelic::Agent.logger.debug("Not installing #{self.name} instrumentation because of configuration #{key}") true end
Source
# File lib/new_relic/dependency_detection.rb, line 113 def execute @executes.each do |x| begin x.call rescue => err NewRelic::Agent.logger.error("Error while installing #{self.name} instrumentation:", err) break end end ensure executed! end
Source
# File lib/new_relic/dependency_detection.rb, line 45 def executed! @executed = true end
Source
# File lib/new_relic/dependency_detection.rb, line 209 def executes(&block) @executes << block if block end
Source
# File lib/new_relic/dependency_detection.rb, line 83 def extract_supportability_name(instrumenting_module) instrumenting_module.to_s.split('::')[-2] end
Extracts the instrumented library name from the instrumenting module’s name Given “NewRelic::Agent::Instrumentation::NetHTTP::Prepend” Will extract “NetHTTP” which is in the 2nd to last spot
Source
# File lib/new_relic/dependency_detection.rb, line 180 def fetch_config_value(key) valid_value = valid_config_value(::NewRelic::Agent.config[key].to_s.to_sym) ::NewRelic::Agent.logger.debug("Using #{valid_value} configuration value for #{self.name} to configure instrumentation") return valid_value end
fetches and transform potentially invalid value given to one of the valid config values logs the resolved value during debug mode.
Source
# File lib/new_relic/dependency_detection.rb, line 87 def log_and_instrument(method, instrumenting_module, supportability_name) supportability_name ||= extract_supportability_name(instrumenting_module) NewRelic::Agent.logger.info("Installing New Relic supported #{supportability_name} instrumentation using #{method}") NewRelic::Agent.record_metric("Supportability/Instrumentation/#{supportability_name}/#{method}", 0.0) yield end
Source
# File lib/new_relic/dependency_detection.rb, line 201 def named(new_name) self.name = new_name end
Source
# File lib/new_relic/dependency_detection.rb, line 221 def prepend_conflicts? @prepend_conflicts.any? do |conflict| begin conflict.call rescue => err NewRelic::Agent.logger.error("Error while checking prepend conflicts #{self.name}:", err) false # assumes no conflicts exist since `prepend` is preferred method of instrumenting end end end
Source
# File lib/new_relic/dependency_detection.rb, line 94 def prepend_instrument(target_class, instrumenting_module, supportability_name = nil) log_and_instrument('Prepend', instrumenting_module, supportability_name) do target_class.send(:prepend, instrumenting_module) end end
Source
# File lib/new_relic/dependency_detection.rb, line 76 def source_location_for(klass, method_name) Object.instance_method(:method).bind(klass.allocate).call(method_name).source_location.to_s end
Source
# File lib/new_relic/dependency_detection.rb, line 188 def update_config_value(use_prepend) if config_key && auto_configured? NewRelic::Agent.config.instance_variable_get(:@cache)[config_key] = use_prepend ? :prepend : :chain end use_prepend end
update any :auto config value to be either :prepend or :chain after auto determination has selected one of those to use
Source
# File lib/new_relic/dependency_detection.rb, line 217 def use_prepend? update_config_value(prepend_configured? || (auto_configured? && !prepend_conflicts?)) end
Source
# File lib/new_relic/dependency_detection.rb, line 174 def valid_config_value(retrieved_value) VALID_CONFIG_VALUES.include?(retrieved_value) ? retrieved_value : AUTO_CONFIG_VALUE end
returns only a valid value for instrumentation configuration If user uses “enabled” it’s converted to “auto”