class ScoutApm::AgentContext
Attributes
Accessors #
Public Class Methods
Source
# 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
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.
Public Instance Methods
Source
# File lib/scout_apm/agent_context.rb, line 113 def auto_instruments_layer_histograms @auto_instruments_layer_histograms ||= ScoutApm::RequestHistograms.new end
Maintains a Histogram of insignificant/significant autoinstrument layers. significant = 1 insignificant = 0
Source
# 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
Execute this in the child process of a remote agent. The parent is expected to have its accepting webserver up and running
Source
# File lib/scout_apm/agent_context.rb, line 70 def config @config ||= ScoutApm::Config.without_file(self) end
Source
# File lib/scout_apm/agent_context.rb, line 170 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
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
Source
# File lib/scout_apm/agent_context.rb, line 145 def dev_trace_enabled? config.value('dev_trace') && environment.env == "development" end
Source
# File lib/scout_apm/agent_context.rb, line 74 def environment @environment ||= ScoutApm::Environment.instance end
Source
# File lib/scout_apm/agent_context.rb, line 214 def environment=(env) @environment = env end
I believe this is only useful for testing?
Source
# File lib/scout_apm/agent_context.rb, line 153 def error_buffer @error_buffer ||= ScoutApm::ErrorService::ErrorBuffer.new(self) end
Error
Service #
Source
# File lib/scout_apm/agent_context.rb, line 157 def ignored_exceptions @ignored_exceptions ||= ScoutApm::ErrorService::IgnoredExceptions.new(self, config.value('errors_ignored_exceptions')) end
Source
# File lib/scout_apm/agent_context.rb, line 98 def ignored_uris @ignored_uris ||= ScoutApm::IgnoredUris.new(config.value('ignore')) end
Source
# File lib/scout_apm/agent_context.rb, line 187 def installed! @installed = true end
Source
# File lib/scout_apm/agent_context.rb, line 137 def layaway @layaway ||= ScoutApm::Layaway.new(self) end
Source
# File lib/scout_apm/agent_context.rb, line 225 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
Called after config is reset and loaded from file
Source
# File lib/scout_apm/agent_context.rb, line 90 def logger @logger ||= LoggerFactory.build(config, environment) end
Source
# File lib/scout_apm/agent_context.rb, line 22 def marshal_load(*args) @logger = LoggerFactory.build_minimal_logger @process_start_time = Time.now end
Source
# File lib/scout_apm/agent_context.rb, line 141 def recorder @recorder ||= RecorderFactory.build(self) end
Source
# File lib/scout_apm/agent_context.rb, line 209 def recorder=(recorder) @recorder = recorder end
Source
# File lib/scout_apm/agent_context.rb, line 118 def request_histograms @request_histograms ||= ScoutApm::RequestHistograms.new end
Histogram of the cumulative requests since the start of the process
Source
# File lib/scout_apm/agent_context.rb, line 124 def request_histograms_by_time @request_histograms_by_time ||= Hash.new { |h, k| h[k] = ScoutApm::RequestHistograms.new } end
Histogram of the requests, distinct by reporting period (minute) { StoreReportingPeriodTimestamp
=> RequestHistograms
}
Source
# File lib/scout_apm/agent_context.rb, line 94 def sampling @sampling ||= ScoutApm::Sampling.new(config) end
Source
# File lib/scout_apm/agent_context.rb, line 195 def shutting_down! @shutting_down = true end
Source
# File lib/scout_apm/agent_context.rb, line 82 def shutting_down? @shutting_down end
Source
# File lib/scout_apm/agent_context.rb, line 106 def slow_job_policy @slow_job_policy ||= ScoutApm::SlowRequestPolicy.new(self).tap{|p| p.add_default_policies } end
Source
# File lib/scout_apm/agent_context.rb, line 102 def slow_request_policy @slow_request_policy ||= ScoutApm::SlowRequestPolicy.new(self).tap{|p| p.add_default_policies } end
Source
# 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
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
Source
# File lib/scout_apm/agent_context.rb, line 132 def store return @store if @store self.store = ScoutApm::Store.new(self) end
Source
# File lib/scout_apm/agent_context.rb, line 199 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
Source
# File lib/scout_apm/agent_context.rb, line 128 def transaction_time_consumed @transaction_time_consumed ||= ScoutApm::TransactionTimeConsumed.new end