# 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 OneApm::Manager.logger.info("Starting the OneAPM Agent (#{OneApm::VERSION::STRING}) in #{env.inspect} environment.") configure_agent(env, options) # Be sure to only create once! RUBY-1020 if OneApm::Manager.logger.is_startup_logger? OneApm::Manager.logger = OneApm::Logger::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::Support::ForkedProcessChannel.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::Manager.agent = OneApm::Agent::Agent.instance OneApm::Manager.agent.start_service if OneApm::Manager.config[:agent_enabled] && !OneApm::Manager.agent.started? start_agent install_instrumentation elsif !Manager.config[:agent_enabled] install_shim else detect_dependencies end end def configure_agent(env, options) manual = OneApm::Configuration::ManualSource.new(options) OneApm::Manager.config.replace_or_add_config(manual) config_file_path = @config_file_override || OneApm::Manager.config[:config_path] OneApm::Manager.config.replace_or_add_config(OneApm::Configuration::YamlSource.new(config_file_path, env)) if OneApm::Manager.config[:high_security] OneApm::Manager.logger.info("Installing high security configuration based on local configuration") OneApm::Manager.config.replace_or_add_config(OneApm::Configuration::HighSecuritySource.new(Manager.config)) end end # Install the real agent into the Agent module, and issue the start command. def start_agent OneApm::Manager.agent.start end def app OneApm::Manager.config[:framework] end def framework OneApm::Manager.config[:framework] end def settings OneApm::Manager.config.to_collector_hash end def dispatcher OneApm::Manager.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