Class: ElasticAPM::Agent Private
- Inherits:
-
Object
- Object
- ElasticAPM::Agent
- Includes:
- Logging
- Defined in:
- lib/elastic_apm/agent.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- LOCK =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mutex.new
Constants included from Logging
Logging::LEVELS, Logging::PREFIX
Instance Attribute Summary collapse
- #config ⇒ Object readonly private
- #context_builder ⇒ Object readonly private
- #error_builder ⇒ Object readonly private
- #instrumenter ⇒ Object readonly private
- #metrics ⇒ Object readonly private
- #stacktrace_builder ⇒ Object readonly private
- #transport ⇒ Object readonly private
Class Method Summary collapse
-
.instance ⇒ Object
private
life cycle.
- .running? ⇒ Boolean private
- .start(config) ⇒ Object private
- .stop ⇒ Object private
Instance Method Summary collapse
-
#add_filter(key, callback) ⇒ Object
private
filters.
- #build_context(rack_env) ⇒ Object private
- #current_span ⇒ Object private
-
#current_transaction ⇒ Object
private
instrumentation.
- #end_span ⇒ Object private
- #end_transaction(result = nil) ⇒ Object private
-
#enqueue(obj) ⇒ Object
private
transport.
-
#initialize(config) ⇒ Agent
constructor
private
A new instance of Agent.
-
#report(exception, handled: true) ⇒ Object
private
errors.
- #report_message(message, backtrace: nil, **attrs) ⇒ Object private
- #set_custom_context(context) ⇒ Object private
- #set_tag(key, value) ⇒ Object private
- #set_user(user) ⇒ Object private
- #start ⇒ Object private
- #start_span(name = nil, type = nil, backtrace: nil, context: nil, trace_context: nil) ⇒ Object private
- #start_transaction(name = nil, type = nil, context: nil, trace_context: nil) ⇒ Object private
- #stop ⇒ Object private
Methods included from Logging
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(config) ⇒ Agent
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Agent.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/elastic_apm/agent.rb', line 50 def initialize(config) @config = config @stacktrace_builder = StacktraceBuilder.new(config) @context_builder = ContextBuilder.new(config) @error_builder = ErrorBuilder.new(self) @transport = Transport::Base.new(config) @instrumenter = Instrumenter.new( config, stacktrace_builder: stacktrace_builder ) { |event| enqueue event } @metrics = Metrics.new(config) { |event| enqueue event } end |
Instance Attribute Details
#config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/elastic_apm/agent.rb', line 65 def config @config end |
#context_builder ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/elastic_apm/agent.rb', line 65 def context_builder @context_builder end |
#error_builder ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/elastic_apm/agent.rb', line 65 def error_builder @error_builder end |
#instrumenter ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/elastic_apm/agent.rb', line 65 def instrumenter @instrumenter end |
#metrics ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/elastic_apm/agent.rb', line 65 def metrics @metrics end |
#stacktrace_builder ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/elastic_apm/agent.rb', line 65 def stacktrace_builder @stacktrace_builder end |
#transport ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/elastic_apm/agent.rb', line 65 def transport @transport end |
Class Method Details
.instance ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
life cycle
21 22 23 |
# File 'lib/elastic_apm/agent.rb', line 21 def self.instance # rubocop:disable Style/TrivialAccessors @instance end |
.running? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/elastic_apm/agent.rb', line 46 def self.running? !!@instance end |
.start(config) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/elastic_apm/agent.rb', line 25 def self.start(config) return @instance if @instance config = Config.new(config) unless config.is_a?(Config) LOCK.synchronize do return @instance if @instance @instance = new(config).start end end |
.stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 |
# File 'lib/elastic_apm/agent.rb', line 37 def self.stop LOCK.synchronize do return unless @instance @instance.stop @instance = nil end end |
Instance Method Details
#add_filter(key, callback) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
filters
189 190 191 |
# File 'lib/elastic_apm/agent.rb', line 189 def add_filter(key, callback) transport.add_filter(key, callback) end |
#build_context(rack_env) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
162 163 164 |
# File 'lib/elastic_apm/agent.rb', line 162 def build_context(rack_env) @context_builder.build(rack_env) end |
#current_span ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 |
# File 'lib/elastic_apm/agent.rb', line 108 def current_span instrumenter.current_span end |
#current_transaction ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
instrumentation
104 105 106 |
# File 'lib/elastic_apm/agent.rb', line 104 def current_transaction instrumenter.current_transaction end |
#end_span ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 |
# File 'lib/elastic_apm/agent.rb', line 146 def end_span instrumenter.end_span end |
#end_transaction(result = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
126 127 128 |
# File 'lib/elastic_apm/agent.rb', line 126 def end_transaction(result = nil) instrumenter.end_transaction(result) end |
#enqueue(obj) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
transport
98 99 100 |
# File 'lib/elastic_apm/agent.rb', line 98 def enqueue(obj) transport.submit obj end |
#report(exception, handled: true) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
errors
168 169 170 171 172 173 174 175 176 |
# File 'lib/elastic_apm/agent.rb', line 168 def report(exception, handled: true) return if config.filter_exception_types.include?(exception.class.to_s) error = @error_builder.build_exception( exception, handled: handled ) enqueue error end |
#report_message(message, backtrace: nil, **attrs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
178 179 180 181 182 183 184 185 |
# File 'lib/elastic_apm/agent.rb', line 178 def (, backtrace: nil, **attrs) error = @error_builder.build_log( , backtrace: backtrace, **attrs ) enqueue error end |
#set_custom_context(context) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
154 155 156 |
# File 'lib/elastic_apm/agent.rb', line 154 def set_custom_context(context) instrumenter.set_custom_context(context) end |
#set_tag(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
150 151 152 |
# File 'lib/elastic_apm/agent.rb', line 150 def set_tag(key, value) instrumenter.set_tag(key, value) end |
#set_user(user) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
158 159 160 |
# File 'lib/elastic_apm/agent.rb', line 158 def set_user(user) instrumenter.set_user(user) end |
#start ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/elastic_apm/agent.rb', line 68 def start info '[%s] Starting agent, reporting to %s', VERSION, config.server_url transport.start instrumenter.start metrics.start config.enabled_spies.each do |lib| require "elastic_apm/spies/#{lib}" end self end |
#start_span(name = nil, type = nil, backtrace: nil, context: nil, trace_context: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/elastic_apm/agent.rb', line 130 def start_span( name = nil, type = nil, backtrace: nil, context: nil, trace_context: nil ) instrumenter.start_span( name, type, backtrace: backtrace, context: context, trace_context: trace_context ) end |
#start_transaction(name = nil, type = nil, context: nil, trace_context: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/elastic_apm/agent.rb', line 112 def start_transaction( name = nil, type = nil, context: nil, trace_context: nil ) instrumenter.start_transaction( name, type, context: context, trace_context: trace_context ) end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 88 89 90 |
# File 'lib/elastic_apm/agent.rb', line 82 def stop debug 'Stopping agent' instrumenter.stop transport.stop metrics.stop self end |