Class: NewRelic::Agent::ErrorCollector
- Inherits:
-
Object
- Object
- NewRelic::Agent::ErrorCollector
- Includes:
- NoticeError, CollectionHelper
- Defined in:
- lib/new_relic/agent/error_collector.rb
Overview
This class collects errors from the parent application, storing them until they are harvested and transmitted to the server
Defined Under Namespace
Modules: NoticeError, Shim
Constant Summary collapse
- MAX_ERROR_QUEUE_LENGTH =
Maximum possible length of the queue - defaults to 20, may be made configurable in the future. This is a tradeoff between memory and data retention
20
Constants included from CollectionHelper
CollectionHelper::DEFAULT_ARRAY_TRUNCATION_SIZE, CollectionHelper::DEFAULT_TRUNCATION_SIZE
Instance Attribute Summary collapse
-
#config_enabled ⇒ Object
readonly
Returns the value of attribute config_enabled.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
Instance Method Summary collapse
-
#control ⇒ Object
Helper method to get the NewRelic::Control.instance.
-
#harvest_errors(unsent_errors) ⇒ Object
Get the errors currently queued up.
-
#ignore(errors) ⇒ Object
errors is an array of Exception Class Names.
-
#ignore_error_filter(&block) ⇒ Object
Returns the error filter proc that is used to check if an error should be reported.
-
#initialize ⇒ ErrorCollector
constructor
Returns a new error collector.
-
#notice_error(exception, options = {}) ⇒ Object
Notice the error with the given available options:.
Methods included from NoticeError
#add_to_error_queue, #custom_params_from_opts, #disabled?, #error_is_ignored?, #error_params_from_options, #exception_info, #extract_source, #extract_stack_trace, #fetch_from_options, #filtered_by_error_filter?, #filtered_error?, #increment_error_count!, #normalized_request_and_custom_params, #over_queue_limit?, #request_params_from_opts, #sense_method, #should_exit_notice_error?, #uri_ref_and_root
Methods included from CollectionHelper
#normalize_params, #strip_nr_from_backtrace
Constructor Details
#initialize ⇒ ErrorCollector
Returns a new error collector
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/new_relic/agent/error_collector.rb', line 23 def initialize @errors = [] # lookup of exception class names to ignore. Hash for fast access @ignore = {} config = NewRelic::Control.instance.fetch('error_collector', {}) @enabled = @config_enabled = config.fetch('enabled', true) @capture_source = config.fetch('capture_source', true) ignore_errors = config.fetch('ignore_errors', "") ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String ignore_errors.each { |error| error.strip! } ignore(ignore_errors) @lock = Mutex.new end |
Instance Attribute Details
#config_enabled ⇒ Object (readonly)
Returns the value of attribute config_enabled.
20 21 22 |
# File 'lib/new_relic/agent/error_collector.rb', line 20 def config_enabled @config_enabled end |
#enabled ⇒ Object
Returns the value of attribute enabled.
19 20 21 |
# File 'lib/new_relic/agent/error_collector.rb', line 19 def enabled @enabled end |
Instance Method Details
#control ⇒ Object
Helper method to get the NewRelic::Control.instance
41 42 43 |
# File 'lib/new_relic/agent/error_collector.rb', line 41 def control NewRelic::Control.instance end |
#harvest_errors(unsent_errors) ⇒ Object
Get the errors currently queued up. Unsent errors are left over from a previous unsuccessful attempt to send them to the server.
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/new_relic/agent/error_collector.rb', line 232 def harvest_errors(unsent_errors) @lock.synchronize do errors = @errors @errors = [] if unsent_errors && !unsent_errors.empty? errors = unsent_errors + errors end errors end end |
#ignore(errors) ⇒ Object
errors is an array of Exception Class Names
61 62 63 |
# File 'lib/new_relic/agent/error_collector.rb', line 61 def ignore(errors) errors.each { |error| @ignore[error] = true; log.debug("Ignoring errors of type '#{error}'") } end |
#ignore_error_filter(&block) ⇒ Object
Returns the error filter proc that is used to check if an error should be reported. When given a block, resets the filter to the provided block. The define_method() is used to wrap the block in a lambda so return statements don’t result in a LocalJump exception.
50 51 52 53 54 55 56 57 |
# File 'lib/new_relic/agent/error_collector.rb', line 50 def ignore_error_filter(&block) if block self.class.class_eval { define_method(:ignore_filter_proc, &block) } @ignore_filter = method(:ignore_filter_proc) else @ignore_filter end end |
#notice_error(exception, options = {}) ⇒ Object
Notice the error with the given available options:
-
:uri
=> The request path, minus any request params or query string. -
:referer
=> The URI of the referer -
:metric
=> The metric name associated with the transaction -
:request_params
=> Request parameters, already filtered if necessary -
:custom_params
=> Custom parameters
If anything is left over, it’s added to custom params If exception is nil, the error count is bumped and no traced error is recorded
220 221 222 223 224 225 226 227 228 |
# File 'lib/new_relic/agent/error_collector.rb', line 220 def notice_error(exception, ={}) return if should_exit_notice_error?(exception) action_path = (, :metric, (NewRelic::Agent.instance.stats_engine.scope_name || '')) = ().merge(exception_info(exception)) add_to_error_queue(NewRelic::NoticedError.new(action_path, , exception)) exception rescue => e log.error("Error capturing an error, yodawg. #{e}") end |