Class: TingYun::Agent::Collector::ErrorCollector
- Inherits:
-
Object
- Object
- TingYun::Agent::Collector::ErrorCollector
- Defined in:
- lib/ting_yun/agent/collector/error_collector.rb
Defined Under Namespace
Constant Summary collapse
- ERRORS_ACTION =
"Errors/Count/".freeze
- ERRORS_ALL =
"Errors/Count/All".freeze
- ERRORS_ALL_WEB =
"Errors/Count/AllWeb".freeze
- ERRORS_ALL_BACK_GROUND =
"Errors/Count/AllBackground".freeze
- MAX_ERROR_QUEUE_LENGTH =
Maximum possible length of the queue - defaults to 20, may be
20
- EMPTY_STRING =
''.freeze
Constants included from Tag
Instance Attribute Summary collapse
-
#error_trace_array ⇒ Object
readonly
Returns the value of attribute error_trace_array.
-
#external_error_array ⇒ Object
readonly
Returns the value of attribute external_error_array.
Instance Method Summary collapse
- #create_noticed_error(exception, options) ⇒ Object
-
#extract_stack_trace(exception) ⇒ Object
extracts a stack trace from the exception for debugging purposes.
-
#increment_error_count(state) ⇒ Object
Increments a statistic that tracks total error rate.
-
#initialize ⇒ ErrorCollector
constructor
A new instance of ErrorCollector.
-
#notice_agent_error(exception) ⇒ Object
*Use sparingly for difficult to track bugs.*.
-
#notice_error(exception, options = {}) ⇒ Object
See TingYun::Agent.notice_error for options and commentary.
- #reset! ⇒ Object
-
#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?(exception) ⇒ Boolean
Methods included from Metric
#action_metric_name, #aggregated_metric_names
Methods included from Tag
#exception_tagged?, #tag_exception
Constructor Details
#initialize ⇒ ErrorCollector
Returns a new instance of ErrorCollector.
66 67 68 69 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 66 def initialize @error_trace_array = ::TingYun::Agent::Collector::ErrorTraceArray.new(MAX_ERROR_QUEUE_LENGTH) @external_error_array = ::TingYun::Agent::Collector::ErrorTraceArray.new(MAX_ERROR_QUEUE_LENGTH) end |
Instance Attribute Details
#error_trace_array ⇒ Object (readonly)
Returns the value of attribute error_trace_array.
64 65 66 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 64 def error_trace_array @error_trace_array end |
#external_error_array ⇒ Object (readonly)
Returns the value of attribute external_error_array.
64 65 66 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 64 def external_error_array @external_error_array end |
Instance Method Details
#create_noticed_error(exception, options) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 104 def create_noticed_error(exception, ) attributes = [:attributes] error_metric = attributes.agent_attributes[:metric_name] || EMPTY_STRING noticed_error = TingYun::Agent::Collector::NoticedError.new(error_metric, exception) noticed_error.attributes = attributes noticed_error.stack_trace = extract_stack_trace(exception) noticed_error end |
#extract_stack_trace(exception) ⇒ Object
extracts a stack trace from the exception for debugging purposes
126 127 128 129 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 126 def extract_stack_trace(exception) actual_exception = sense_method(exception, 'original_exception') || exception sense_method(actual_exception, 'backtrace') || '<no stack trace>' end |
#increment_error_count(state) ⇒ Object
Increments a statistic that tracks total error rate
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 88 def increment_error_count(state) txn = state.current_transaction metric_names = aggregated_metric_names(txn) action_metric = action_metric_name(txn) metric_names << action_metric if action_metric stats_engine = TingYun::Agent.agent.stats_engine stats_engine.record_unscoped_metrics(state, metric_names) do |stats| stats.increment_count end end |
#notice_agent_error(exception) ⇒ Object
*Use sparingly for difficult to track bugs.*
Track internal agent errors for communication back to TingYun To use, make a specific subclass of TingYun::Support::Exception::InternalAgentError, then pass an instance of it to this method when your problem occurs.
Limits are treated differently for these errors. We only gather one per class per harvest, disregarding (and not impacting) the app error queue limit.
140 141 142 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 140 def notice_agent_error(exception) error_trace_array.notice_agent_error(exception) end |
#notice_error(exception, options = {}) ⇒ Object
See TingYun::Agent.notice_error for options and commentary
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 72 def notice_error(exception, ={}) tag_exception(exception) state = ::TingYun::Agent::TransactionState.tl_get increment_error_count(state) noticed_error = create_noticed_error(exception, ) if noticed_error.is_external_error external_error_array.add_to_error_queue(noticed_error) else error_trace_array.add_to_error_queue(noticed_error) end rescue => e ::TingYun::Agent.logger.warn("Failure when capturing error '#{exception}':", e) nil end |
#reset! ⇒ Object
144 145 146 147 148 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 144 def reset! @error_trace_array.reset! @external_error_array.reset! nil 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
121 122 123 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 121 def sense_method(object, method) object.send(method) if object.respond_to?(method) end |
#skip_notice_error?(exception) ⇒ Boolean
114 115 116 |
# File 'lib/ting_yun/agent/collector/error_collector.rb', line 114 def skip_notice_error?(exception) exception_tagged?(exception) end |