Module: OneApm::Collector::ErrorCollector::NoticeError
- Included in:
- OneApm::Collector::ErrorCollector
- Defined in:
- lib/one_apm/collector/containers/error_collector.rb
Overview
This module was extracted from the notice_error method - it is internally tested and can be refactored without major issues.
Instance Method Summary collapse
-
#add_to_error_queue(noticed_error) ⇒ Object
Synchronizes adding an error to the error queue, and checks if the error queue is too long - if so, we drop the error on the floor after logging a warning.
- #aggregated_metric_names(txn) ⇒ Object
- #blamed_metric_name(txn, options) ⇒ Object
-
#custom_params_from_opts(options) ⇒ Object
If anything else is left over, we treat it like a custom param.
-
#error_is_ignored?(error) ⇒ Boolean
an error is ignored if it is nil or if it is filtered.
-
#error_params_from_options(options) ⇒ Object
Merges together many of the options into something that can actually be attached to the error.
-
#exception_info(exception) ⇒ Object
extracts a bunch of information from the exception to include in the noticed error - some may or may not be available, but we try to include all of it.
-
#extract_stack_trace(exception) ⇒ Object
extracts a stack trace from the exception for debugging purposes.
-
#fetch_from_options(options, key, default = nil) ⇒ Object
acts just like Hash#fetch, but deletes the key from the hash.
-
#filtered_by_error_filter?(error) ⇒ Boolean
Checks the provided error against the error filter, if there is an error filter.
-
#filtered_error?(error) ⇒ Boolean
Checks the array of error names and the error filter against the provided error.
-
#increment_error_count!(state, exception, options = {}) ⇒ Object
Increments a statistic that tracks total error rate.
-
#normalized_request_and_custom_params(options) ⇒ Object
normalizes the request and custom parameters before attaching them to the error.
-
#over_queue_limit?(message) ⇒ Boolean
checks the size of the error queue to make sure we are under the maximum limit, and logs a warning if we are over the limit.
-
#request_params_from_opts(options) ⇒ Object
takes the request parameters out of the options hash, and returns them if we are capturing parameters, otherwise returns nil.
- #seen?(txn, exception) ⇒ Boolean
-
#sense_method(object, method) ⇒ Object
calls a method on an object, if it responds to it - used for detection and soft fail-safe.
- #skip_notice_error?(state, exception) ⇒ Boolean
- #tag_as_seen(state, exception) ⇒ Object
-
#uri_ref_and_root(options) ⇒ Object
returns some basic option defaults pulled from the provided options hash.
Instance Method Details
#add_to_error_queue(noticed_error) ⇒ Object
Synchronizes adding an error to the error queue, and checks if the error queue is too long - if so, we drop the error on the floor after logging a warning.
258 259 260 261 262 263 264 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 258 def add_to_error_queue(noticed_error) @lock.synchronize do if !over_queue_limit?(noticed_error.) && !@errors.include?(noticed_error) @errors << noticed_error end end end |
#aggregated_metric_names(txn) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 132 def aggregated_metric_names(txn) metric_names = ["Errors/all"] return metric_names unless txn if txn.recording_web_transaction? metric_names << "Errors/allWeb" else metric_names << "Errors/allOther" end metric_names end |
#blamed_metric_name(txn, options) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 124 def blamed_metric_name(txn, ) if [:metric] && [:metric] != OneApm::Transaction::OA_UNKNOWN_METRIC "Errors/#{[:metric]}" else "Errors/#{txn.best_name}" if txn end end |
#custom_params_from_opts(options) ⇒ Object
If anything else is left over, we treat it like a custom param
182 183 184 185 186 187 188 189 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 182 def custom_params_from_opts() # If anything else is left over, treat it like a custom param: if OneApm::Manager.config[:'error_collector.capture_attributes'] (, :custom_params, {}).merge() else {} end end |
#error_is_ignored?(error) ⇒ Boolean
an error is ignored if it is nil or if it is filtered
107 108 109 110 111 112 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 107 def error_is_ignored?(error) error && filtered_error?(error) rescue => e OneApm::Manager.logger.error("Error '#{error}' will NOT be ignored. Exception '#{e}' while determining whether to ignore or not.", e) false end |
#error_params_from_options(options) ⇒ Object
Merges together many of the options into something that can actually be attached to the error
214 215 216 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 214 def () uri_ref_and_root().merge(normalized_request_and_custom_params()) end |
#exception_info(exception) ⇒ Object
extracts a bunch of information from the exception to include in the noticed error - some may or may not be available, but we try to include all of it
239 240 241 242 243 244 245 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 239 def exception_info(exception) { :file_name => sense_method(exception, 'file_name'), :line_number => sense_method(exception, 'line_number'), :stack_trace => extract_stack_trace(exception) } end |
#extract_stack_trace(exception) ⇒ Object
extracts a stack trace from the exception for debugging purposes
226 227 228 229 230 231 232 233 234 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 226 def extract_stack_trace(exception) actual_exception = sense_method(exception, 'original_exception') || exception if bt = sense_method(actual_exception, 'backtrace') bt.reject! { |t| t.include?('one_apm') } bt else '<no stack trace>' end end |
#fetch_from_options(options, key, default = nil) ⇒ Object
acts just like Hash#fetch, but deletes the key from the hash
167 168 169 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 167 def (, key, default=nil) .delete(key) || default end |
#filtered_by_error_filter?(error) ⇒ Boolean
Checks the provided error against the error filter, if there is an error filter
96 97 98 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 96 def filtered_by_error_filter?(error) respond_to?(:ignore_filter_proc) && !ignore_filter_proc(error) end |
#filtered_error?(error) ⇒ Boolean
Checks the array of error names and the error filter against the provided error
102 103 104 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 102 def filtered_error?(error) @ignore[error.class.name] || filtered_by_error_filter?(error) end |
#increment_error_count!(state, exception, options = {}) ⇒ Object
Increments a statistic that tracks total error rate
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 146 def increment_error_count!(state, exception, ={}) txn = state.current_transaction metric_names = aggregated_metric_names(txn) blamed_metric = blamed_metric_name(txn, ) metric_names << blamed_metric if blamed_metric stats_engine = OneApm::Manager.agent.stats_engine stats_engine.record_unscoped_metrics(state, metric_names) do |stats| stats.increment_count end end |
#normalized_request_and_custom_params(options) ⇒ Object
normalizes the request and custom parameters before attaching them to the error. See OneApm::CollectionHelper#normalize_params
205 206 207 208 209 210 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 205 def normalized_request_and_custom_params() { :request_params => normalize_params(request_params_from_opts()), :custom_params => normalize_params(custom_params_from_opts()) } end |
#over_queue_limit?(message) ⇒ Boolean
checks the size of the error queue to make sure we are under the maximum limit, and logs a warning if we are over the limit.
249 250 251 252 253 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 249 def over_queue_limit?() over_limit = (@errors.reject{|err| err.is_internal}.length >= OA_MAX_ERROR_QUEUE_LENGTH) OneApm::Manager.logger.warn("The error reporting queue has reached #{OA_MAX_ERROR_QUEUE_LENGTH}. The error detail for this and subsequent errors will not be transmitted to OneApm until the queued errors have been sent: #{}") if over_limit over_limit end |
#request_params_from_opts(options) ⇒ Object
takes the request parameters out of the options hash, and returns them if we are capturing parameters, otherwise returns nil
194 195 196 197 198 199 200 201 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 194 def request_params_from_opts() value = .delete(:request_params) if OneApm::Manager.config[:capture_params] value else nil end end |
#seen?(txn, exception) ⇒ Boolean
114 115 116 117 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 114 def seen?(txn, exception) error_ids = txn.nil? ? [] : txn.noticed_error_ids error_ids.include?(exception.object_id) end |
#sense_method(object, method) ⇒ Object
calls a method on an object, if it responds to it - used for detection and soft fail-safe. Returns nil if the method does not exist
221 222 223 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 221 def sense_method(object, method) object.send(method) if object.respond_to?(method) end |
#skip_notice_error?(state, exception) ⇒ Boolean
159 160 161 162 163 164 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 159 def skip_notice_error?(state, exception) disabled? || error_is_ignored?(exception) || exception.nil? || seen?(state.current_transaction, exception) end |
#tag_as_seen(state, exception) ⇒ Object
119 120 121 122 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 119 def tag_as_seen(state, exception) txn = state.current_transaction txn.noticed_error_ids << exception.object_id if txn end |
#uri_ref_and_root(options) ⇒ Object
returns some basic option defaults pulled from the provided options hash
173 174 175 176 177 178 179 |
# File 'lib/one_apm/collector/containers/error_collector.rb', line 173 def uri_ref_and_root() { :request_uri => (, :uri, ''), :request_referer => (, :referer, ''), :rails_root => OneApm::Probe.instance.root } end |