class ElasticAPM::Agent
@api private
Constants
- LOCK
Attributes
central_config[R]
config[R]
context_builder[R]
error_builder[R]
instrumenter[R]
metrics[R]
stacktrace_builder[R]
transport[R]
Public Class Methods
instance()
click to toggle source
life cycle
# File lib/elastic_apm/agent.rb, line 42 def self.instance # rubocop:disable Style/TrivialAccessors @instance end
new(config)
click to toggle source
# File lib/elastic_apm/agent.rb, line 79 def initialize(config) @stacktrace_builder = StacktraceBuilder.new(config) @context_builder = ContextBuilder.new(config) @error_builder = ErrorBuilder.new(self) @central_config = CentralConfig.new(config) @transport = Transport::Base.new(config) @metrics = Metrics.new(config) { |event| enqueue event } @instrumenter = Instrumenter.new( config, metrics: metrics, stacktrace_builder: stacktrace_builder ) { |event| enqueue event } @pid = Process.pid end
running?()
click to toggle source
# File lib/elastic_apm/agent.rb, line 75 def self.running? !!@instance end
start(config)
click to toggle source
# File lib/elastic_apm/agent.rb, line 46 def self.start(config) return @instance if @instance config = Config.new(config) unless config.is_a?(Config) LOCK.synchronize do return @instance if @instance unless config.enabled? config.logger.debug format( "%sAgent disabled with `enabled: false'", Logging::PREFIX ) return end @instance = new(config).start end end
stop()
click to toggle source
# File lib/elastic_apm/agent.rb, line 66 def self.stop LOCK.synchronize do return unless @instance @instance.stop @instance = nil end end
Public Instance Methods
add_filter(key, callback)
click to toggle source
filters
# File lib/elastic_apm/agent.rb, line 270 def add_filter(key, callback) transport.add_filter(key, callback) end
build_context(rack_env:, for_type:)
click to toggle source
# File lib/elastic_apm/agent.rb, line 234 def build_context(rack_env:, for_type:) @context_builder.build(rack_env: rack_env, for_type: for_type) end
current_span()
click to toggle source
# File lib/elastic_apm/agent.rb, line 156 def current_span instrumenter.current_span end
current_transaction()
click to toggle source
instrumentation
# File lib/elastic_apm/agent.rb, line 152 def current_transaction instrumenter.current_transaction end
detect_forking!()
click to toggle source
# File lib/elastic_apm/agent.rb, line 280 def detect_forking! return if @pid == Process.pid config.logger.debug( "Forked process detected, restarting threads in process [PID:#{Process.pid}]") central_config.handle_forking! transport.handle_forking! instrumenter.handle_forking! metrics.handle_forking! @pid = Process.pid end
end_span(span = nil)
click to toggle source
rubocop:enable Metrics/ParameterLists
# File lib/elastic_apm/agent.rb, line 214 def end_span(span = nil) instrumenter.end_span(span) end
end_transaction(result = nil)
click to toggle source
# File lib/elastic_apm/agent.rb, line 178 def end_transaction(result = nil) instrumenter.end_transaction(result) end
enqueue(obj)
click to toggle source
transport
# File lib/elastic_apm/agent.rb, line 146 def enqueue(obj) transport.submit obj end
inspect()
click to toggle source
misc
Calls superclass method
# File lib/elastic_apm/agent.rb, line 276 def inspect super.split.first + '>' end
report(exception, context: nil, handled: true)
click to toggle source
errors
# File lib/elastic_apm/agent.rb, line 240 def report(exception, context: nil, handled: true) return unless config.recording? detect_forking! return if config.filter_exception_types.include?(exception.class.to_s) error = @error_builder.build_exception( exception, context: context, handled: handled ) enqueue error error.id end
report_message(message, context: nil, backtrace: nil, **attrs)
click to toggle source
# File lib/elastic_apm/agent.rb, line 254 def report_message(message, context: nil, backtrace: nil, **attrs) return unless config.recording? detect_forking! error = @error_builder.build_log( message, context: context, backtrace: backtrace, **attrs ) enqueue error error.id end
set_custom_context(context)
click to toggle source
# File lib/elastic_apm/agent.rb, line 222 def set_custom_context(context) instrumenter.set_custom_context(context) end
set_destination(address: nil, port: nil, service: nil, cloud: nil)
click to toggle source
# File lib/elastic_apm/agent.rb, line 230 def set_destination(address: nil, port: nil, service: nil, cloud: nil) current_span&.set_destination(address: nil, port: nil, service: nil, cloud: nil) end
set_label(key, value)
click to toggle source
# File lib/elastic_apm/agent.rb, line 218 def set_label(key, value) instrumenter.set_label(key, value) end
set_user(user)
click to toggle source
# File lib/elastic_apm/agent.rb, line 226 def set_user(user) instrumenter.set_user(user) end
start()
click to toggle source
# File lib/elastic_apm/agent.rb, line 108 def start unless config.disable_start_message? config.logger.info format( '[%s] Starting agent, reporting to %s', VERSION, config.server_url ) end central_config.start transport.start instrumenter.start metrics.start config.enabled_instrumentations.each do |lib| debug "Requiring spy: #{lib}" require "elastic_apm/spies/#{lib}" end self end
start_span( name = nil, type = nil, subtype: nil, action: nil, backtrace: nil, context: nil, trace_context: nil, parent: nil, sync: nil )
click to toggle source
rubocop:disable Metrics/ParameterLists
# File lib/elastic_apm/agent.rb, line 183 def start_span( name = nil, type = nil, subtype: nil, action: nil, backtrace: nil, context: nil, trace_context: nil, parent: nil, sync: nil ) detect_forking! # We don't check config.recording? because the span # will not be created if there's no transaction. # We want to use the recording value from the config # that existed when start_transaction was called. ~estolfo instrumenter.start_span( name, type, subtype: subtype, action: action, backtrace: backtrace, context: context, trace_context: trace_context, parent: parent, sync: sync ) end
start_transaction( name = nil, type = nil, context: nil, trace_context: nil )
click to toggle source
# File lib/elastic_apm/agent.rb, line 160 def start_transaction( name = nil, type = nil, context: nil, trace_context: nil ) return unless config.recording? detect_forking! instrumenter.start_transaction( name, type, config: config, context: context, trace_context: trace_context ) end
stop()
click to toggle source
# File lib/elastic_apm/agent.rb, line 129 def stop info 'Stopping agent' central_config.stop metrics.stop instrumenter.stop transport.stop self end