class OneApm::Agent::Agent
Attributes
cross_app_encoding_bytes[R]
cross_app_monitor[R]
cross_process_id[R]
events[R]
external_rename_rules[RW]
harvest_lock[R]
harvest_samplers[R]
harvester[R]
javascript_instrumentor[R]
monotonic_gc_profiler[R]
record_sql[R]
service[RW]
transaction_rules[R]
Public Class Methods
config()
click to toggle source
# File lib/one_apm/agent.rb, line 82 def self.config OneApm::Manager.config end
instance()
click to toggle source
# File lib/one_apm/agent.rb, line 78 def self.instance @instance ||= self.new end
new()
click to toggle source
# File lib/one_apm/agent.rb, line 86 def initialize start_service @events = OneApm::Support::EventListener.new init_containers OneApm::Agent::SyntheticsMonitor.new @events OneApm::Agent::RestartMonitor.new @cross_app_monitor = OneApm::Agent::CrossAppMonitor.new(@events) @transaction_rules = OneApm::Support::RulesEngine.new @harvest_samplers = OneApm::Collector::SamplerCollection.new(@events) @monotonic_gc_profiler = OneApm::Support::VM::MonotonicGCProfiler.new @javascript_instrumentor = OneApm::Agent::JavascriptInstrumentor.new(@events) @restart = OneApm::Agent::Restart.new(@events) @cross_app_samples_sender = OneApm::Agent::CrossAppSamplesSender.new(@events, self) @harvester = OneApm::Agent::Harvester.new(@events) @after_fork_lock = Mutex.new @connect_state = :pending @connect_attempts = 0 @environment_report = nil @harvest_lock = Mutex.new end
Public Instance Methods
agent_should_start?()
click to toggle source
# File lib/one_apm/agent.rb, line 148 def agent_should_start? return false if already_started? || disabled? || defer_for_background_jobs? unless app_name_configured? && tier_name_configured? OneApm::Manager.logger.error "No application name or tier name configured in #{probe.env} environment" false else true end end
connect(options={})
click to toggle source
# File lib/one_apm/agent.rb, line 159 def connect(options={}) opts = { :keep_retrying => OneApm::Manager.config[:keep_retrying], :force_reconnect => OneApm::Manager.config[:force_reconnect] }.merge(options) return unless should_connect?(opts[:force_reconnect]) OneApm::Manager.logger.debug "Connecting Process to OneApm: #$0" query_server_for_configuration @connected_pid = Process.pid @connect_state = :connected rescue OneApm::ForceDisconnectException => e handle_force_disconnect(e) rescue OneApm::LicenseException => e handle_license_error(e) rescue OneApm::UnrecoverableAgentException => e handle_unrecoverable_agent_error(e) rescue StandardError, Timeout::Error, OneApm::ServerConnectionException => e log_error(e) if opts[:keep_retrying] note_connect_failure OneApm::Manager.logger.info "Will re-attempt in #{connect_retry_period} seconds" sleep connect_retry_period retry else disconnect end rescue Exception => e OneApm::Manager.logger.error "Exception of unexpected type during Agent#connect():", e raise end
graceful_disconnect()
click to toggle source
# File lib/one_apm/agent.rb, line 193 def graceful_disconnect if connected? begin @service.request_timeout = 10 @events.notify(:before_shutdown) transmit_data transmit_event_data transmit_utilization_data if OneApm::Manager.config[:collect_utilization] if @connected_pid == $$ && !@service.kind_of?(OneApm::Collector::CollectorService) OneApm::Manager.logger.debug "Sending OneApm service agent run shutdown message" @service.shutdown(Time.now.to_f) else OneApm::Manager.logger.debug "This agent connected from parent process #{@connected_pid}--not sending shutdown" end OneApm::Manager.logger.debug "Graceful disconnect complete" rescue Timeout::Error, StandardError => e OneApm::Manager.logger.debug "Error when disconnecting #{e.class.name}: #{e.message}" end else OneApm::Manager.logger.debug "Bypassing graceful disconnect - agent not connected" end end
probe()
click to toggle source
# File lib/one_apm/agent.rb, line 114 def probe OneApm::Probe.instance end
shutdown(options = {})
click to toggle source
# File lib/one_apm/agent.rb, line 136 def shutdown(options = {}) return if not started? OneApm::Manager.logger.info "Starting Agent shutdown" stop_event_loop untraced_graceful_disconnect OneApm::Manager.revert_to_default_configuration @started = nil OneApm::Probe.reset end
start()
click to toggle source
# File lib/one_apm/agent.rb, line 124 def start return unless agent_should_start? log_startup check_config_and_start_agent log_version_and_pid events.subscribe(:finished_configuring) do log_ignore_url_regexes end end
start_service()
click to toggle source
# File lib/one_apm/agent.rb, line 118 def start_service if OneApm::Manager.config[:monitor_mode] && !@service @service = OneApm::Collector::CollectorService.new end end
untraced_graceful_disconnect()
click to toggle source
# File lib/one_apm/agent.rb, line 218 def untraced_graceful_disconnect OneApm::Manager.disable_all_tracing do graceful_disconnect end rescue => e OneApm::Manager.logger.error e end