Class: ScoutApm::AgentContext
- Inherits:
-
Object
- Object
- ScoutApm::AgentContext
- Defined in:
- lib/scout_apm/agent_context.rb
Instance Attribute Summary collapse
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#process_start_time ⇒ Object
readonly
Accessors #.
Instance Method Summary collapse
-
#auto_instruments_layer_histograms ⇒ Object
Maintains a Histogram of insignificant/significant autoinstrument layers.
-
#become_remote_client!(host, port) ⇒ Object
Execute this in the child process of a remote agent.
- #config ⇒ Object
-
#config=(config) ⇒ Object
When we set the config for any reason, there are some values we must reinitialize, since the config could have changed their settings, so nil them out here, then let them get lazily reset as needed.
- #dev_trace_enabled? ⇒ Boolean
- #environment ⇒ Object
-
#environment=(env) ⇒ Object
I believe this is only useful for testing?.
-
#error_buffer ⇒ Object
Error Service #.
- #ignored_exceptions ⇒ Object
- #ignored_uris ⇒ Object
-
#initialize ⇒ AgentContext
constructor
Initially start up without attempting to load a configuration file.
- #installed! ⇒ Object
- #installed? ⇒ Boolean
- #layaway ⇒ Object
-
#log_configuration_settings ⇒ Object
Called after config is reset and loaded from file.
- #logger ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(*args) ⇒ Object
- #recorder ⇒ Object
- #recorder=(recorder) ⇒ Object
-
#request_histograms ⇒ Object
Histogram of the cumulative requests since the start of the process.
-
#request_histograms_by_time ⇒ Object
Histogram of the requests, distinct by reporting period (minute) { StoreReportingPeriodTimestamp => RequestHistograms }.
- #shutting_down! ⇒ Object
- #shutting_down? ⇒ Boolean
- #slow_job_policy ⇒ Object
- #slow_request_policy ⇒ Object
-
#start_remote_server!(bind, port) ⇒ Object
Lifecycle: Remote Server/Client.
- #started! ⇒ Object
- #started? ⇒ Boolean
- #store ⇒ Object
- #store=(store) ⇒ Object
- #transaction_time_consumed ⇒ Object
Constructor Details
#initialize ⇒ AgentContext
Initially start up without attempting to load a configuration file. We need to be able to lookup configuration options like “application_root” which would then in turn influence where the yaml configuration file is located
Later in initialization, we set config= to include the file.
12 13 14 15 16 |
# File 'lib/scout_apm/agent_context.rb', line 12 def initialize() @logger = LoggerFactory.build_minimal_logger @process_start_time = Time.now @extensions = ScoutApm::Extensions::Config.new(self) end |
Instance Attribute Details
#extensions ⇒ Object
Returns the value of attribute extensions.
4 5 6 |
# File 'lib/scout_apm/agent_context.rb', line 4 def extensions @extensions end |
#process_start_time ⇒ Object (readonly)
Accessors #
68 69 70 |
# File 'lib/scout_apm/agent_context.rb', line 68 def process_start_time @process_start_time end |
Instance Method Details
#auto_instruments_layer_histograms ⇒ Object
Maintains a Histogram of insignificant/significant autoinstrument layers. significant = 1 insignificant = 0
109 110 111 |
# File 'lib/scout_apm/agent_context.rb', line 109 def auto_instruments_layer_histograms @auto_instruments_layer_histograms ||= ScoutApm::RequestHistograms.new end |
#become_remote_client!(host, port) ⇒ Object
Execute this in the child process of a remote agent. The parent is expected to have its accepting webserver up and running
57 58 59 60 61 |
# File 'lib/scout_apm/agent_context.rb', line 57 def become_remote_client!(host, port) logger.debug("Becoming Remote Agent (reporting to: #{host}:#{port})") @recorder = ScoutApm::Remote::Recorder.new(host, port, logger) @store = ScoutApm::FakeStore.new end |
#config ⇒ Object
70 71 72 |
# File 'lib/scout_apm/agent_context.rb', line 70 def config @config ||= ScoutApm::Config.without_file(self) end |
#config=(config) ⇒ Object
When we set the config for any reason, there are some values we must reinitialize, since the config could have changed their settings, so nil them out here, then let them get lazily reset as needed
Don’t use this in initializer, since it’ll attempt to log immediately
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/scout_apm/agent_context.rb', line 166 def config=(config) @config = config @logger = nil log_configuration_settings @ignored_uris = nil @slow_request_policy = nil @slow_job_policy = nil @request_histograms = nil @request_histograms_by_time = nil @store = nil @layaway = nil @recorder = nil end |
#dev_trace_enabled? ⇒ Boolean
141 142 143 |
# File 'lib/scout_apm/agent_context.rb', line 141 def dev_trace_enabled? config.value('dev_trace') && environment.env == "development" end |
#environment ⇒ Object
74 75 76 |
# File 'lib/scout_apm/agent_context.rb', line 74 def environment @environment ||= ScoutApm::Environment.instance end |
#environment=(env) ⇒ Object
I believe this is only useful for testing?
210 211 212 |
# File 'lib/scout_apm/agent_context.rb', line 210 def environment=(env) @environment = env end |
#error_buffer ⇒ Object
Error Service #
149 150 151 |
# File 'lib/scout_apm/agent_context.rb', line 149 def error_buffer @error_buffer ||= ScoutApm::ErrorService::ErrorBuffer.new(self) end |
#ignored_exceptions ⇒ Object
153 154 155 |
# File 'lib/scout_apm/agent_context.rb', line 153 def ignored_exceptions @ignored_exceptions ||= ScoutApm::ErrorService::IgnoredExceptions.new(self, config.value('errors_ignored_exceptions')) end |
#ignored_uris ⇒ Object
94 95 96 |
# File 'lib/scout_apm/agent_context.rb', line 94 def ignored_uris @ignored_uris ||= ScoutApm::IgnoredUris.new(config.value('ignore')) end |
#installed! ⇒ Object
183 184 185 |
# File 'lib/scout_apm/agent_context.rb', line 183 def installed! @installed = true end |
#installed? ⇒ Boolean
86 87 88 |
# File 'lib/scout_apm/agent_context.rb', line 86 def installed? @installed end |
#layaway ⇒ Object
133 134 135 |
# File 'lib/scout_apm/agent_context.rb', line 133 def layaway @layaway ||= ScoutApm::Layaway.new(self) end |
#log_configuration_settings ⇒ Object
Called after config is reset and loaded from file
221 222 223 224 225 226 227 228 229 |
# File 'lib/scout_apm/agent_context.rb', line 221 def log_configuration_settings @config.log_settings(logger) if !@config.any_keys_found? logger.info("No configuration file loaded, and no configuration found in ENV. " + "For assistance configuring Scout, visit " + "https://docs.scoutapm.com/#ruby-configuration-options") end end |
#logger ⇒ Object
90 91 92 |
# File 'lib/scout_apm/agent_context.rb', line 90 def logger @logger ||= LoggerFactory.build(config, environment) end |
#marshal_dump ⇒ Object
18 19 20 |
# File 'lib/scout_apm/agent_context.rb', line 18 def marshal_dump [] end |
#marshal_load(*args) ⇒ Object
22 23 24 25 |
# File 'lib/scout_apm/agent_context.rb', line 22 def marshal_load(*args) @logger = LoggerFactory.build_minimal_logger @process_start_time = Time.now end |
#recorder ⇒ Object
137 138 139 |
# File 'lib/scout_apm/agent_context.rb', line 137 def recorder @recorder ||= RecorderFactory.build(self) end |
#recorder=(recorder) ⇒ Object
205 206 207 |
# File 'lib/scout_apm/agent_context.rb', line 205 def recorder=(recorder) @recorder = recorder end |
#request_histograms ⇒ Object
Histogram of the cumulative requests since the start of the process
114 115 116 |
# File 'lib/scout_apm/agent_context.rb', line 114 def request_histograms @request_histograms ||= ScoutApm::RequestHistograms.new end |
#request_histograms_by_time ⇒ Object
Histogram of the requests, distinct by reporting period (minute) { StoreReportingPeriodTimestamp => RequestHistograms }
120 121 122 |
# File 'lib/scout_apm/agent_context.rb', line 120 def request_histograms_by_time @request_histograms_by_time ||= Hash.new { |h, k| h[k] = ScoutApm::RequestHistograms.new } end |
#shutting_down! ⇒ Object
191 192 193 |
# File 'lib/scout_apm/agent_context.rb', line 191 def shutting_down! @shutting_down = true end |
#shutting_down? ⇒ Boolean
82 83 84 |
# File 'lib/scout_apm/agent_context.rb', line 82 def shutting_down? @shutting_down end |
#slow_job_policy ⇒ Object
102 103 104 |
# File 'lib/scout_apm/agent_context.rb', line 102 def slow_job_policy @slow_job_policy ||= ScoutApm::SlowRequestPolicy.new(self).tap{|p| p.add_default_policies } end |
#slow_request_policy ⇒ Object
98 99 100 |
# File 'lib/scout_apm/agent_context.rb', line 98 def slow_request_policy @slow_request_policy ||= ScoutApm::SlowRequestPolicy.new(self).tap{|p| p.add_default_policies } end |
#start_remote_server!(bind, port) ⇒ Object
Lifecycle: Remote Server/Client
This allows short lived forked processes to communicate back to the parent process.
Used in the Resque instrumentation
Parent Pre-fork: start_remote_server! once
Child Post-fork: become_remote_client! after each fork
TODO: Figure out where to extract this to
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/scout_apm/agent_context.rb', line 39 def start_remote_server!(bind, port) return if @remote_server && @remote_server.running? logger.info("Starting Remote Agent Server") # Start the listening web server only in parent process. @remote_server = ScoutApm::Remote::Server.new( bind, port, ScoutApm::Remote::Router.new(ScoutApm::SynchronousRecorder.new(self), logger), logger ) @remote_server.start end |
#started! ⇒ Object
187 188 189 |
# File 'lib/scout_apm/agent_context.rb', line 187 def started! @started = true end |
#started? ⇒ Boolean
78 79 80 |
# File 'lib/scout_apm/agent_context.rb', line 78 def started? @started end |
#store ⇒ Object
128 129 130 131 |
# File 'lib/scout_apm/agent_context.rb', line 128 def store return @store if @store self.store = ScoutApm::Store.new(self) end |
#store=(store) ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/scout_apm/agent_context.rb', line 195 def store=(store) @store = store # Installs the default samplers # Don't install samplers on nil stores if store ScoutApm::Instruments::Samplers::DEFAULT_SAMPLERS.each { |s| store.add_sampler(s) } end end |
#transaction_time_consumed ⇒ Object
124 125 126 |
# File 'lib/scout_apm/agent_context.rb', line 124 def transaction_time_consumed @transaction_time_consumed ||= ScoutApm::TransactionTimeConsumed.new end |