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
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#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.
- #initialize_ignored_errors(ignore_errors) ⇒ Object
-
#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, #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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/new_relic/agent/error_collector.rb', line 22 def initialize @errors = [] @seen_error_ids = [] # lookup of exception class names to ignore. Hash for fast access @ignore = {} @capture_source = Agent.config[:'error_collector.capture_source'] initialize_ignored_errors(Agent.config[:'error_collector.ignore_errors']) @lock = Mutex.new Agent.config.register_callback(:'error_collector.enabled') do |config_enabled| ::NewRelic::Agent.logger.debug "Errors will #{config_enabled ? '' : 'not '}be sent to the New Relic service." end Agent.config.register_callback(:'error_collector.ignore_errors') do |ignore_errors| initialize_ignored_errors(ignore_errors) end end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
19 20 21 |
# File 'lib/new_relic/agent/error_collector.rb', line 19 def errors @errors end |
Instance Method Details
#enabled? ⇒ Boolean
48 49 50 |
# File 'lib/new_relic/agent/error_collector.rb', line 48 def enabled? Agent.config[:'error_collector.enabled'] 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.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/new_relic/agent/error_collector.rb', line 249 def harvest_errors(unsent_errors) @lock.synchronize do errors = @errors @errors = [] # Only expect to re-see errors on same request, so clear on harvest @seen_error_ids = [] 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
68 69 70 71 72 73 |
# File 'lib/new_relic/agent/error_collector.rb', line 68 def ignore(errors) errors.each do |error| @ignore[error] = true ::NewRelic::Agent.logger.debug("Ignoring errors of type '#{error}'") end 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.
57 58 59 60 61 62 63 64 |
# File 'lib/new_relic/agent/error_collector.rb', line 57 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 |
#initialize_ignored_errors(ignore_errors) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/new_relic/agent/error_collector.rb', line 41 def initialize_ignored_errors(ignore_errors) @ignore.clear ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String ignore_errors.each { |error| error.strip! } ignore(ignore_errors) 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
236 237 238 239 240 241 242 243 244 245 |
# File 'lib/new_relic/agent/error_collector.rb', line 236 def notice_error(exception, ={}) return if should_exit_notice_error?(exception) NewRelic::Agent.instance.events.notify(: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 ::NewRelic::Agent.logger.warn("Failure when capturing error '#{exception}':", e) end |