Module: NewRelic::Control::InstanceMethods
- Included in:
- NewRelic::Control
- Defined in:
- lib/new_relic/control/instance_methods.rb
Overview
Contains methods that relate to the runtime usage of the control object. Note that these are subject to override in the NewRelic::Control::Framework classes that are actually instantiated
Instance Attribute Summary collapse
-
#env ⇒ Object
writeonly
The env is the setting used to identify which section of the newrelic.yml to load.
-
#local_env ⇒ Object
readonly
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.
Instance Method Summary collapse
-
#[](key) ⇒ Object
for backward compatibility with the old config interface.
- #app ⇒ Object
- #dispatcher ⇒ Object
- #framework ⇒ Object
-
#init_plugin(options = {}) ⇒ Object
Initialize the plugin/gem and start the agent.
-
#newrelic_root ⇒ Object
Delegates to the class method newrelic_root, implemented by each subclass.
- #settings ⇒ Object
-
#start_agent ⇒ Object
Install the real agent into the Agent module, and issue the start command.
Instance Attribute Details
#env=(value) ⇒ Object (writeonly)
The env is the setting used to identify which section of the newrelic.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
15 16 17 |
# File 'lib/new_relic/control/instance_methods.rb', line 15 def env=(value) @env = value end |
#local_env ⇒ Object (readonly)
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
21 22 23 |
# File 'lib/new_relic/control/instance_methods.rb', line 21 def local_env @local_env end |
Instance Method Details
#[](key) ⇒ Object
for backward compatibility with the old config interface
94 95 96 |
# File 'lib/new_relic/control/instance_methods.rb', line 94 def [](key) NewRelic::Agent.config[key.to_sym] end |
#app ⇒ Object
85 86 87 |
# File 'lib/new_relic/control/instance_methods.rb', line 85 def app Agent.config[:framework] end |
#dispatcher ⇒ Object
102 103 104 |
# File 'lib/new_relic/control/instance_methods.rb', line 102 def dispatcher NewRelic::Agent.config[:dispatcher] end |
#framework ⇒ Object
89 90 91 |
# File 'lib/new_relic/control/instance_methods.rb', line 89 def framework Agent.config[:framework] end |
#init_plugin(options = {}) ⇒ Object
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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/new_relic/control/instance_methods.rb', line 46 def init_plugin(={}) yaml = Agent::Configuration::YamlSource.new(@config_file_path, [:env] || env) Agent.config.replace_or_add_config(yaml, 1) Agent.config.replace_or_add_config(Agent::Configuration::ManualSource.new(), 1) # Be sure to only create once! RUBY-1020 if ::NewRelic::Agent.logger.is_startup_logger? ::NewRelic::Agent.logger = NewRelic::Agent::AgentLogger.new(Agent.config, root, .delete(:log)) end # Merge the stringified options into the config as overrides: environment_name = .delete(:env) and self.env = environment_name dispatcher_instance_id = .delete(:dispatcher_instance_id) and @local_env.dispatcher_instance_id = dispatcher_instance_id NewRelic::Agent::PipeChannelManager.listener.start if .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, NewRelic::Agent::MethodTracer::ClassMethods Module.send :include, NewRelic::Agent::MethodTracer::InstanceMethods init_config() NewRelic::Agent.agent = NewRelic::Agent::Agent.instance if Agent.config[:agent_enabled] && !NewRelic::Agent.instance.started? start_agent install_instrumentation load_samplers unless Agent.config[:disable_samplers] local_env.gather_environment_info append_environment_info elsif !Agent.config[:agent_enabled] install_shim end end |
#newrelic_root ⇒ Object
Delegates to the class method newrelic_root, implemented by each subclass
108 109 110 |
# File 'lib/new_relic/control/instance_methods.rb', line 108 def newrelic_root self.class.newrelic_root end |