# encoding: utf-8 require 'one_apm/logger/null_logger' require 'one_apm/logger/memory_logger' require 'one_apm/logger/agent_logger' module OneApm class Probe module InstanceMethods attr_writer :env attr_reader :local_env def init_plugin(options = {}) env = options[:env] || self.env Agent.logger.info("Starting the OneApm agent in #{env.inspect} environment.") configure_agent(env, options) # Be sure to only create once! RUBY-1020 if ::OneApm::Agent.logger.is_startup_logger? ::OneApm::Agent.logger = OneApm::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 OneApm::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, OneApm::Support::MethodTracer::ClassMethods Module.send :include, OneApm::Support::MethodTracer init_config(options) # initialize agent OneApm::Agent.instance = OneApm::Agent::Agent.instance OneApm::Agent.instance.start_service_if_needed if Agent.config[:agent_enabled] && !OneApm::Agent.instance.started? start_agent install_instrumentation elsif !Agent.config[:agent_enabled] install_shim else detect_dependencies end end def configure_agent(env, options) manual = OneApm::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(OneApm::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(OneApm::Configuration::HighSecuritySource.new(Agent.config)) end end # Install the real agent into the Agent module, and issue the start command. def start_agent OneApm::Agent.instance.start end def app Agent.config[:framework] end def framework Agent.config[:framework] end def settings OneApm::Agent.config.to_collector_hash end def dispatcher OneApm::Agent.config[:dispatcher] end def oneapm_root OneApm::Probe.oneapm_root end protected def initialize(local_env, config_file_override = nil) @local_env = local_env @instrumentation_files = [] @config_file_override = config_file_override end def root '.' end end include InstanceMethods end end