Class: Hoss::Agent Private
- Inherits:
-
Object
- Object
- Hoss::Agent
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/hoss/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
- #config ⇒ Object readonly private
- #context_builder ⇒ Object readonly private
- #error_builder ⇒ Object readonly private
- #instrumenter ⇒ 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:, for_type:) ⇒ Object private
- #current_event ⇒ Object private
- #detect_forking! ⇒ Object private
- #end_event ⇒ 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_custom_context(context) ⇒ Object private
- #set_label(key, value) ⇒ Object private
- #set_user(user) ⇒ Object private
- #start ⇒ Object private
- #start_event ⇒ 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.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hoss/agent.rb', line 78 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) @instrumenter = Instrumenter.new( config, metrics: nil, 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.
93 94 95 |
# File 'lib/hoss/agent.rb', line 93 def central_config @central_config 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.
93 94 95 |
# File 'lib/hoss/agent.rb', line 93 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.
93 94 95 |
# File 'lib/hoss/agent.rb', line 93 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.
93 94 95 |
# File 'lib/hoss/agent.rb', line 93 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.
93 94 95 |
# File 'lib/hoss/agent.rb', line 93 def instrumenter @instrumenter 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.
93 94 95 |
# File 'lib/hoss/agent.rb', line 93 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.
93 94 95 |
# File 'lib/hoss/agent.rb', line 93 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
41 42 43 |
# File 'lib/hoss/agent.rb', line 41 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.
74 75 76 |
# File 'lib/hoss/agent.rb', line 74 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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hoss/agent.rb', line 45 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.
65 66 67 68 69 70 71 72 |
# File 'lib/hoss/agent.rb', line 65 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
211 212 213 |
# File 'lib/hoss/agent.rb', line 211 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.
175 176 177 |
# File 'lib/hoss/agent.rb', line 175 def build_context(rack_env:, for_type:) @context_builder.build(rack_env: rack_env, for_type: for_type) end |
#current_event ⇒ 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/hoss/agent.rb', line 150 def current_event instrumenter.current_event 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.
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/hoss/agent.rb', line 221 def detect_forking! return if @pid == Process.pid config.logger.debug "Detected forking, 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_event ⇒ 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.
159 160 161 |
# File 'lib/hoss/agent.rb', line 159 def end_event instrumenter.end_event 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
146 147 148 |
# File 'lib/hoss/agent.rb', line 146 def enqueue(obj) transport.submit obj 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
217 218 219 |
# File 'lib/hoss/agent.rb', line 217 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
181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/hoss/agent.rb', line 181 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.
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/hoss/agent.rb', line 195 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_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.
167 168 169 |
# File 'lib/hoss/agent.rb', line 167 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.
163 164 165 |
# File 'lib/hoss/agent.rb', line 163 def set_label(key, value) instrumenter.set_label(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.
171 172 173 |
# File 'lib/hoss/agent.rb', line 171 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.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/hoss/agent.rb', line 105 def start unless config.api_key config.logger.warn "Hoss API Key missing, not starting." return end unless config. config.logger.info format( '[%s] Starting agent, reporting to %s', VERSION, config.api_host ) end central_config.start transport.start instrumenter.start # metrics.start config.enabled_instrumentations.each do |lib| debug "Requiring spy: #{lib}" require "hoss/spies/#{lib}" end self end |
#start_event ⇒ 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 157 |
# File 'lib/hoss/agent.rb', line 154 def start_event detect_forking! instrumenter.start_event 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.
130 131 132 133 134 135 136 137 138 |
# File 'lib/hoss/agent.rb', line 130 def stop debug 'Stopping agent' central_config.stop instrumenter.stop transport.stop self end |