Class: Atatus::Agent Private
- Inherits:
-
Object
- Object
- Atatus::Agent
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/atatus/agent.rb
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.
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
- #central_config ⇒ Object readonly private
- #collector ⇒ Object readonly private
- #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
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:, for_type:) ⇒ Object private
- #current_span ⇒ Object private
-
#current_transaction ⇒ Object
private
instrumentation.
- #detect_forking! ⇒ Object private
-
#end_span ⇒ Object
private
rubocop:enable Metrics/ParameterLists.
- #end_transaction(result = nil) ⇒ Object private
-
#enqueue(obj) ⇒ Object
private
transport.
-
#initialize(config) ⇒ Agent
constructor
private
A new instance of Agent.
-
#inspect ⇒ Object
private
misc.
-
#report(exception, context: nil, handled: true) ⇒ Object
private
errors.
- #report_message(message, context: nil, backtrace: nil, **attrs) ⇒ Object private
- #set_company(company) ⇒ Object private
- #set_custom_context(context) ⇒ Object private
- #set_label(key, value) ⇒ Object private
- #set_response_body(response_body) ⇒ Object private
- #set_user(user) ⇒ Object private
- #start ⇒ Object private
-
#start_span(name = nil, type = nil, subtype: nil, action: nil, backtrace: nil, context: nil, trace_context: nil, parent: nil, sync: nil) ⇒ Object
private
rubocop:disable Metrics/ParameterLists.
- #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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/atatus/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) @collector = Collector::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 |
Instance Attribute Details
#central_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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 def central_config @central_config end |
#collector ⇒ 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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 def collector @collector end |
#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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 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.
95 96 97 |
# File 'lib/atatus/agent.rb', line 95 def stacktrace_builder @stacktrace_builder 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
42 43 44 |
# File 'lib/atatus/agent.rb', line 42 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.
75 76 77 |
# File 'lib/atatus/agent.rb', line 75 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/atatus/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 ⇒ 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.
66 67 68 69 70 71 72 73 |
# File 'lib/atatus/agent.rb', line 66 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
294 295 296 |
# File 'lib/atatus/agent.rb', line 294 def add_filter(key, callback) # transport.add_filter(key, callback) end |
#build_context(rack_env:, for_type:) ⇒ 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.
258 259 260 |
# File 'lib/atatus/agent.rb', line 258 def build_context(rack_env:, for_type:) @context_builder.build(rack_env: rack_env, for_type: for_type) 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.
176 177 178 |
# File 'lib/atatus/agent.rb', line 176 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
172 173 174 |
# File 'lib/atatus/agent.rb', line 172 def current_transaction instrumenter.current_transaction end |
#detect_forking! ⇒ 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.
304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/atatus/agent.rb', line 304 def detect_forking! return if @pid == Process.pid config.logger.debug "Detected forking, restarting threads in process [PID:#{Process.pid}]" central_config.handle_forking! collector.handle_forking! instrumenter.handle_forking! metrics.handle_forking! @pid = Process.pid 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.
rubocop:enable Metrics/ParameterLists
234 235 236 |
# File 'lib/atatus/agent.rb', line 234 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.
198 199 200 |
# File 'lib/atatus/agent.rb', line 198 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
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/atatus/agent.rb', line 156 def enqueue(obj) # transport.submit obj case obj when Atatus::Transaction collector.add_txn(obj) when Atatus::Span collector.add_span(obj) when Atatus::Error collector.add_error(obj) when Atatus::Metricset collector.add_metrics(obj) end end |
#inspect ⇒ 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.
misc
300 301 302 |
# File 'lib/atatus/agent.rb', line 300 def inspect super.split.first + '>' end |
#report(exception, context: nil, 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
264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/atatus/agent.rb', line 264 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) ⇒ 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.
278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/atatus/agent.rb', line 278 def (, context: nil, backtrace: nil, **attrs) return unless config.recording? detect_forking! error = @error_builder.build_log( , context: context, backtrace: backtrace, **attrs ) enqueue error error.id end |
#set_company(company) ⇒ 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.
250 251 252 |
# File 'lib/atatus/agent.rb', line 250 def set_company(company) instrumenter.set_company(company) 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.
242 243 244 |
# File 'lib/atatus/agent.rb', line 242 def set_custom_context(context) instrumenter.set_custom_context(context) end |
#set_label(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.
238 239 240 |
# File 'lib/atatus/agent.rb', line 238 def set_label(key, value) instrumenter.set_label(key, value) end |
#set_response_body(response_body) ⇒ 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.
254 255 256 |
# File 'lib/atatus/agent.rb', line 254 def set_response_body(response_body) instrumenter.set_response_body(response_body) 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.
246 247 248 |
# File 'lib/atatus/agent.rb', line 246 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.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/atatus/agent.rb', line 108 def start unless config. config.logger.info format( '[%s] Starting atatus ruby agent', VERSION ) end if config.license_key.nil? || config.app_name.nil? if config.license_key.nil? && config.app_name.nil? error 'Atatus configuration license_key and app_name are missing' elsif config.license_key.nil? error 'Atatus configuration license_key is missing' elsif config.app_name.nil? error 'Atatus configuration app_name is missing' end end central_config.start collector.start instrumenter.start metrics.start config.enabled_instrumentations.each do |lib| debug "Requiring spy: #{lib}" require "atatus/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) ⇒ 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.
rubocop:disable Metrics/ParameterLists
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/atatus/agent.rb', line 203 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) ⇒ 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.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/atatus/agent.rb', line 180 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 ⇒ 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.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/atatus/agent.rb', line 139 def stop debug 'Stopping agent' central_config.stop metrics.stop instrumenter.stop collector.stop self end |