module Mmtrix::Control::InstanceMethods
Contains methods that relate to the runtime usage of the control object. Note that these are subject to override in the Mmtrix::Control::Framework classes that are actually instantiated
Attributes
The env is the setting used to identify which section of the mmtrix.yml to load. This defaults to a framework specific value, such as ENV but can be overridden as long as you set it before calling init_plugin
The local environment contains all the information we report to the server about what kind of application this is, what gems and plugins it uses, and many other kinds of machine-dependent information useful in debugging
Public Class Methods
# File lib/mmtrix/control/instance_methods.rb, line 144 def initialize(local_env, config_file_override=nil) @local_env = local_env @started_in_env = nil @instrumented = nil @instrumentation_files = [] @config_file_override = config_file_override end
Public Instance Methods
for backward compatibility with the old config interface
# File lib/mmtrix/control/instance_methods.rb, line 124 def [](key) Mmtrix::Agent.config[key.to_sym] end
# File lib/mmtrix/control/instance_methods.rb, line 115 def app Agent.config[:framework] end
# File lib/mmtrix/control/instance_methods.rb, line 96 def configure_agent(env, options) manual = Agent::Configuration::ManualSource.new(options) Agent.config.replace_or_add_config(manual) config_file_path = @config_file_override || Agent.config[:config_path] Agent.config.replace_or_add_config(Agent::Configuration::YamlSource.new(config_file_path, env)) if Agent.config[:high_security] Agent.logger.info("Installing high security configuration based on local configuration") Agent.config.replace_or_add_config(Agent::Configuration::HighSecuritySource.new(Agent.config)) end end
# File lib/mmtrix/control/instance_methods.rb, line 81 def determine_env(options) env = options[:env] || self.env env = env.to_s if @started_in_env && @started_in_env != env Agent.logger.error("Attempted to start agent in #{env.inspect} environment, but agent was already running in #{@started_in_env.inspect}", "The agent will continue running in #{@started_in_env.inspect}. To alter this, ensure the desired environment is set before the agent starts.") else Agent.logger.info("Starting the Mmtrix agent in #{env.inspect} environment.", "To prevent agent startup add a MMTRIX_AGENT_ENABLED=false environment variable or modify the #{env.inspect} section of your mmtrix.yml.") end env end
# File lib/mmtrix/control/instance_methods.rb, line 132 def dispatcher Mmtrix::Agent.config[:dispatcher] end
# File lib/mmtrix/control/instance_methods.rb, line 119 def framework Agent.config[:framework] end
Initialize the plugin/gem and start the agent. This does the necessary configuration based on the framework environment and determines whether or not to start the agent. If the agent is not going to be started then it loads the agent shim which has stubs for all the external api.
This may be invoked multiple times, as long as you don’t attempt to uninstall the agent after it has been started.
If the plugin is initialized and it determines that the agent is not enabled, it will skip starting it and install the shim. But if you later call this with :agent_enabled => true
, then it will install the real agent and start it.
What determines whether the agent is launched is the result of calling agent_enabled? This will indicate whether the instrumentation should/will be installed. If we’re in a mode where tracers are not installed then we should not start the agent.
Subclasses are not allowed to override, but must implement init_config({}) which is called one or more times.
# File lib/mmtrix/control/instance_methods.rb, line 50 def init_plugin(options={}) env = determine_env(options) configure_agent(env, options) # Be sure to only create once! RUBY-1020 if ::Mmtrix::Agent.logger.is_startup_logger? ::Mmtrix::Agent.logger = Mmtrix::Agent::AgentLogger.new(root, options.delete(:log)) end # Merge the stringified options into the config as overrides: environment_name = options.delete(:env) and self.env = environment_name Mmtrix::Agent::PipeChannelManager.listener.start if options.delete(:start_channel_listener) # An artifact of earlier implementation, we put both #add_method_tracer and #trace_execution # methods in the module methods. Module.send :include, Mmtrix::Agent::MethodTracer::ClassMethods Module.send :include, Mmtrix::Agent::MethodTracer init_config(options) Mmtrix::Agent.agent = Mmtrix::Agent::Agent.instance if Agent.config[:agent_enabled] && !Mmtrix::Agent.instance.started? start_agent install_instrumentation elsif !Agent.config[:agent_enabled] install_shim else DependencyDetection.detect! end end
Delegates to the class method mmtrix_root
, implemented by each subclass
# File lib/mmtrix/control/instance_methods.rb, line 138 def mmtrix_root self.class.mmtrix_root end
# File lib/mmtrix/control/instance_methods.rb, line 128 def settings Mmtrix::Agent.config.to_collector_hash end
Install the real agent into the Agent
module, and issue the start command.
# File lib/mmtrix/control/instance_methods.rb, line 110 def start_agent @started_in_env = self.env Mmtrix::Agent.agent.start end
Protected Instance Methods
# File lib/mmtrix/control/instance_methods.rb, line 154 def root '.' end