Module: TingYun::Frameworks::InstanceMethods
- Includes:
- Instrumentation
- Included in:
- Framework
- Defined in:
- lib/ting_yun/frameworks/instance_methods.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
writeonly
The env is the setting used to identify which section of the tingyun.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
- #configure_agent(env, options) ⇒ Object
- #determine_env(options) ⇒ Object
- #dispatcher ⇒ Object
- #framework ⇒ Object
-
#init_plugin(options = {}) ⇒ Object
Initialize the plugin/gem and start the agent.
- #root ⇒ Object
- #start_agent ⇒ Object
Methods included from Instrumentation
#add_instrumentation, #detect_dependencies, #install_instrumentation, #load_instrumentation_files
Instance Attribute Details
#env=(value) ⇒ Object (writeonly)
The env is the setting used to identify which section of the tingyun.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
18 19 20 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 18 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
24 25 26 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 24 def local_env @local_env end |
Instance Method Details
#[](key) ⇒ Object
105 106 107 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 105 def [](key) TingYun::Agent.config[key.to_sym] end |
#configure_agent(env, options) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 87 def configure_agent(env, ) # manual_source TingYun::Agent.config.replace_or_add_config(TingYun::Configuration::ManualSource.new()) unless .empty? # yaml_source config_file_path = @config_file_override || TingYun::Agent.config[:config_path] TingYun::Agent.config.replace_or_add_config(TingYun::Configuration::YamlSource.new(config_file_path,env)) end |
#determine_env(options) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 72 def determine_env() env = [:env] || self.env env = env.to_s if @started_in_env && @started_in_env != env TingYun::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 TingYun::Agent.logger.info("Starting the Ting Yun agent in #{env.inspect} environment.", "To prevent agent startup add a TINGYUN_AGENT_ENABLED=false environment variable or modify the #{env.inspect} section of your tingyun.yml.") end env end |
#dispatcher ⇒ Object
109 110 111 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 109 def dispatcher TingYun::Agent.config[:dispatcher] end |
#framework ⇒ Object
101 102 103 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 101 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 nbs.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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 48 def init_plugin(={}) env = determine_env() configure_agent(env, ) if ::TingYun::Agent.logger.is_startup_logger? ::TingYun::Agent.logger = TingYun::Logger::AgentLogger.new(root, .delete(:log)) end environment_name = .delete(:env) and self.env = environment_name init_config() TingYun::Agent.agent = TingYun::Agent::Agent.instance if TingYun::Agent.config[:'nbs.agent_enabled'] && !TingYun::Agent.agent.started? start_agent install_instrumentation else TingYun::Support::LibraryDetection.detect! end end |
#root ⇒ Object
113 114 115 |
# File 'lib/ting_yun/frameworks/instance_methods.rb', line 113 def root '.' end |