Class: TingYun::Agent::Collector::NoticedError
- Inherits:
-
Object
- Object
- TingYun::Agent::Collector::NoticedError
- Includes:
- Support::Coerce
- Defined in:
- lib/ting_yun/agent/collector/error_collector/noticed_error.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#attributes_from_notice_error ⇒ Object
Returns the value of attribute attributes_from_notice_error.
-
#code ⇒ Object
Returns the value of attribute code.
-
#count_error ⇒ Object
Returns the value of attribute count_error.
-
#exception_class_name ⇒ Object
Returns the value of attribute exception_class_name.
-
#exception_id ⇒ Object
readonly
Returns the value of attribute exception_id.
-
#external_metric_name ⇒ Object
Returns the value of attribute external_metric_name.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#is_external_error ⇒ Object
Returns the value of attribute is_external_error.
-
#is_internal ⇒ Object
readonly
Returns the value of attribute is_internal.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#message ⇒ Object
Returns the value of attribute message.
-
#metric_name ⇒ Object
Returns the value of attribute metric_name.
-
#request_port ⇒ Object
Returns the value of attribute request_port.
-
#request_uri ⇒ Object
Returns the value of attribute request_uri.
-
#stack_trace ⇒ Object
Returns the value of attribute stack_trace.
-
#thread_name ⇒ Object
Returns the value of attribute thread_name.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#trace ⇒ Object
Returns the value of attribute trace.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #custom_params ⇒ Object
- #error_params ⇒ Object
-
#initialize(metric_name, exception, timestamp = Time.now) ⇒ NoticedError
constructor
A new instance of NoticedError.
- #request_params ⇒ Object
- #to_collector_array(encoder) ⇒ Object
Methods included from Support::Coerce
event_params, float, int, int_or_nil, log_failure, string
Constructor Details
#initialize(metric_name, exception, timestamp = Time.now) ⇒ NoticedError
Returns a new instance of NoticedError.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 24 def initialize(metric_name, exception, = Time.now) @stack_trace = [] @count_error = 1 @exception_id = exception.object_id @metric_name = metric_name @timestamp = @exception_class_name = exception.is_a?(Exception) ? exception.class.name : 'Error' @external_metric_name = exception.instance_variable_get :@tingyun_klass @is_external_error = exception.instance_variable_get :@tingyun_external @code = exception.instance_variable_get :@tingyun_code @trace = exception.instance_variable_get :@tingyun_trace # It's critical that we not hold onto the exception class constant in this # class. These objects get serialized for Resque to a process that might # not have the original exception class loaded, so do all processing now # while we have the actual exception! @is_internal = (exception.class < TingYun::Support::Exception::InternalAgentError) if exception.nil? @message = '<no message>' elsif exception.respond_to?('original_exception') @message = (exception.original_exception || exception).to_s else # exception is not nil, but does not respond to original_exception @message = exception.to_s end unless @message.is_a?(String) # In pre-1.9.3, Exception.new({}).to_s.class != String # That is, Exception#to_s may not return a String instance if one wasn't # passed in upon creation of the Exception. So, try to generate a useful # String representation of the exception message, falling back to failsafe @message = String(@message.inspect) rescue '<unknown message type>' end # clamp long messages to 4k so that we don't send a lot of # overhead across the wire @message = @message[0..4095] if @message.length > 4096 end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def attributes @attributes end |
#attributes_from_notice_error ⇒ Object
Returns the value of attribute attributes_from_notice_error.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def attributes_from_notice_error @attributes_from_notice_error end |
#code ⇒ Object
Returns the value of attribute code.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def code @code end |
#count_error ⇒ Object
Returns the value of attribute count_error.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def count_error @count_error end |
#exception_class_name ⇒ Object
Returns the value of attribute exception_class_name.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def exception_class_name @exception_class_name end |
#exception_id ⇒ Object (readonly)
Returns the value of attribute exception_id.
21 22 23 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 21 def exception_id @exception_id end |
#external_metric_name ⇒ Object
Returns the value of attribute external_metric_name.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def external_metric_name @external_metric_name end |
#file_name ⇒ Object
Returns the value of attribute file_name.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def file_name @file_name end |
#is_external_error ⇒ Object
Returns the value of attribute is_external_error.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def is_external_error @is_external_error end |
#is_internal ⇒ Object (readonly)
Returns the value of attribute is_internal.
21 22 23 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 21 def is_internal @is_internal end |
#line_number ⇒ Object
Returns the value of attribute line_number.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def line_number @line_number end |
#message ⇒ Object
Returns the value of attribute message.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def @message end |
#metric_name ⇒ Object
Returns the value of attribute metric_name.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def metric_name @metric_name end |
#request_port ⇒ Object
Returns the value of attribute request_port.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def request_port @request_port end |
#request_uri ⇒ Object
Returns the value of attribute request_uri.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def request_uri @request_uri end |
#stack_trace ⇒ Object
Returns the value of attribute stack_trace.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def stack_trace @stack_trace end |
#thread_name ⇒ Object
Returns the value of attribute thread_name.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def thread_name @thread_name end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def @timestamp end |
#trace ⇒ Object
Returns the value of attribute trace.
15 16 17 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 15 def trace @trace end |
Instance Method Details
#==(other) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 64 def ==(other) if other.respond_to?(:exception_id) exception_id == other.exception_id else false end end |
#custom_params ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 110 def custom_params hash = {:threadName => string(attributes.agent_attributes[:threadName])} if is_external_error hash[:httpStatus] = int(code) else hash[:httpStatus] = int(attributes.agent_attributes[:httpStatus]) hash[:referer] = string(attributes.agent_attributes[:referer]) || '' end hash end |
#error_params ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 97 def error_params hash = { :params => custom_params } if is_external_error hash[:stacktrace] = trace else hash[:stacktrace] = stack_trace hash[:requestParams] = request_params end hash end |
#request_params ⇒ Object
121 122 123 124 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 121 def request_params return {} unless TingYun::Agent.config['nbs.capture_params'] attributes.request_params end |
#to_collector_array(encoder) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ting_yun/agent/collector/error_collector/noticed_error.rb', line 74 def to_collector_array(encoder) if is_external_error [.to_i, string(external_metric_name), int(code), string(exception_class_name), count_error, string(metric_name), encoder.encode(error_params) ] else [.to_i, string(metric_name), int(attributes.agent_attributes[:httpStatus]), string(exception_class_name), string(), count_error, string(request_uri), encoder.encode(error_params) ] end end |