Class: NewRelic::NoticedError
- Inherits:
-
Object
- Object
- NewRelic::NoticedError
- Extended by:
- CollectionHelper
- Includes:
- Coerce
- Defined in:
- lib/new_relic/noticed_error.rb
Overview
This class encapsulates an error that was noticed by New Relic in a managed app.
Constant Summary collapse
- STRIPPED_EXCEPTION_REPLACEMENT_MESSAGE =
"Message removed by New Relic 'strip_exception_messages' setting"
- UNKNOWN_ERROR_CLASS_NAME =
'Error'
- NIL_ERROR_MESSAGE =
'<no message>'
- USER_ATTRIBUTES =
'userAttributes'
- AGENT_ATTRIBUTES =
'agentAttributes'
- INTRINSIC_ATTRIBUTES =
'intrinsics'
- DESTINATION =
NewRelic::Agent::AttributeFilter::DST_ERROR_COLLECTOR
- AGENT_ATTRIBUTE_ERROR_GROUP =
:'error.group.name'
- ERROR_PREFIX_KEY =
'error'
- ERROR_MESSAGE_KEY =
"#{ERROR_PREFIX_KEY}.message"
- ERROR_CLASS_KEY =
"#{ERROR_PREFIX_KEY}.class"
- ERROR_EXPECTED_KEY =
"#{ERROR_PREFIX_KEY}.expected"
Constants included from CollectionHelper
CollectionHelper::DEFAULT_ARRAY_TRUNCATION_SIZE, CollectionHelper::DEFAULT_TRUNCATION_SIZE
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.
-
#error_group ⇒ Object
Returns the value of attribute error_group.
-
#exception_class_name ⇒ Object
Returns the value of attribute exception_class_name.
-
#exception_id ⇒ Object
readonly
Returns the value of attribute exception_id.
-
#expected ⇒ Object
Returns the value of attribute expected.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#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.
-
#path ⇒ Object
Returns the value of attribute path.
-
#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.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #agent_attributes ⇒ Object
- #append_attributes(outgoing_params, outgoing_key, source_attributes) ⇒ Object
- #base_parameters ⇒ Object
- #build_agent_attributes(merged_attributes) ⇒ Object
- #build_error_attributes ⇒ Object
- #build_intrinsic_attributes ⇒ Object
- #custom_attributes ⇒ Object
- #extract_class_name_and_message_from(exception) ⇒ Object
-
#initialize(path, exception, timestamp = Process.clock_gettime(Process::CLOCK_REALTIME), expected = false) ⇒ NoticedError
constructor
A new instance of NoticedError.
- #intrinsic_attributes ⇒ Object
- #merge_custom_attributes_from_notice_error(merged_attributes) ⇒ Object
- #merge_custom_attributes_from_transaction(merged_attributes) ⇒ Object
-
#merged_custom_attributes(merged_attributes) ⇒ Object
We can get custom attributes from two sources–the transaction, which we hold in @attributes, or passed options to notice_error which show up in in our Attributes class for consistent handling.
-
#processed_attributes ⇒ Object
Note that we process attributes lazily and store the result.
- #to_collector_array(encoder = nil) ⇒ Object
Methods included from CollectionHelper
Methods included from Coerce
boolean_int!, float, float!, int, int!, int_or_nil, log_failure, scalar, string, value_or_nil
Constructor Details
#initialize(path, exception, timestamp = Process.clock_gettime(Process::CLOCK_REALTIME), expected = false) ⇒ NoticedError
Returns a new instance of NoticedError.
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 62 63 64 |
# File 'lib/new_relic/noticed_error.rb', line 37 def initialize(path, exception, = Process.clock_gettime(Process::CLOCK_REALTIME), expected = false) @exception_id = exception.object_id @path = path # 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 < NewRelic::Agent::InternalAgentError) (exception) @transaction_id = NewRelic::Agent::Tracer&.current_transaction&.guid # 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 # replace error message if enabled if NewRelic::Agent.config[:'strip_exception_messages.enabled'] && !self.class.(exception.class) @message = STRIPPED_EXCEPTION_REPLACEMENT_MESSAGE end @attributes_from_notice_error = nil @attributes = nil @timestamp = @expected = expected end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def attributes @attributes end |
#attributes_from_notice_error ⇒ Object
Returns the value of attribute attributes_from_notice_error.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def attributes_from_notice_error @attributes_from_notice_error end |
#error_group ⇒ Object
Returns the value of attribute error_group.
18 19 20 |
# File 'lib/new_relic/noticed_error.rb', line 18 def error_group @error_group end |
#exception_class_name ⇒ Object
Returns the value of attribute exception_class_name.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def exception_class_name @exception_class_name end |
#exception_id ⇒ Object (readonly)
Returns the value of attribute exception_id.
18 19 20 |
# File 'lib/new_relic/noticed_error.rb', line 18 def exception_id @exception_id end |
#expected ⇒ Object
Returns the value of attribute expected.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def expected @expected end |
#file_name ⇒ Object
Returns the value of attribute file_name.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def file_name @file_name end |
#is_internal ⇒ Object (readonly)
Returns the value of attribute is_internal.
18 19 20 |
# File 'lib/new_relic/noticed_error.rb', line 18 def is_internal @is_internal end |
#line_number ⇒ Object
Returns the value of attribute line_number.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def line_number @line_number end |
#message ⇒ Object
Returns the value of attribute message.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def @message end |
#path ⇒ Object
Returns the value of attribute path.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def path @path end |
#request_port ⇒ Object
Returns the value of attribute request_port.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def request_port @request_port end |
#request_uri ⇒ Object
Returns the value of attribute request_uri.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def request_uri @request_uri end |
#stack_trace ⇒ Object
Returns the value of attribute stack_trace.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def stack_trace @stack_trace end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def @timestamp end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
13 14 15 |
# File 'lib/new_relic/noticed_error.rb', line 13 def transaction_id @transaction_id end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/new_relic/noticed_error.rb', line 66 def ==(other) if other.respond_to?(:exception_id) exception_id == other.exception_id else false end end |
#agent_attributes ⇒ Object
166 167 168 |
# File 'lib/new_relic/noticed_error.rb', line 166 def agent_attributes processed_attributes[AGENT_ATTRIBUTES] end |
#append_attributes(outgoing_params, outgoing_key, source_attributes) ⇒ Object
162 163 164 |
# File 'lib/new_relic/noticed_error.rb', line 162 def append_attributes(outgoing_params, outgoing_key, source_attributes) outgoing_params[outgoing_key] = source_attributes || {} end |
#base_parameters ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/new_relic/noticed_error.rb', line 106 def base_parameters params = {} params[:file_name] = file_name if file_name params[:line_number] = line_number if line_number params[:stack_trace] = stack_trace if stack_trace params[ERROR_EXPECTED_KEY.to_sym] = expected params end |
#build_agent_attributes(merged_attributes) ⇒ Object
148 149 150 151 152 |
# File 'lib/new_relic/noticed_error.rb', line 148 def build_agent_attributes(merged_attributes) return NewRelic::EMPTY_HASH unless @attributes @attributes.agent_attributes_for(DESTINATION) end |
#build_error_attributes ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/new_relic/noticed_error.rb', line 140 def build_error_attributes @attributes_from_notice_error ||= {} @attributes_from_notice_error[ERROR_MESSAGE_KEY] = string() @attributes_from_notice_error[ERROR_CLASS_KEY] = string(exception_class_name) @attributes_from_notice_error[ERROR_EXPECTED_KEY] = true if expected end |
#build_intrinsic_attributes ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/new_relic/noticed_error.rb', line 154 def build_intrinsic_attributes if @attributes @attributes.intrinsic_attributes_for(DESTINATION) else NewRelic::EMPTY_HASH end end |
#custom_attributes ⇒ Object
170 171 172 |
# File 'lib/new_relic/noticed_error.rb', line 170 def custom_attributes processed_attributes[USER_ATTRIBUTES] end |
#extract_class_name_and_message_from(exception) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/new_relic/noticed_error.rb', line 178 def (exception) if exception.nil? @exception_class_name = UNKNOWN_ERROR_CLASS_NAME @message = NIL_ERROR_MESSAGE elsif exception.is_a?(NewRelic::Agent::NoticeableError) @exception_class_name = exception.class_name @message = exception. else if defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR < 5 && exception.respond_to?(:original_exception) exception = exception.original_exception || exception end @exception_class_name = exception.is_a?(Exception) ? exception.class.name : UNKNOWN_ERROR_CLASS_NAME @message = exception.to_s end end |
#intrinsic_attributes ⇒ Object
174 175 176 |
# File 'lib/new_relic/noticed_error.rb', line 174 def intrinsic_attributes processed_attributes[INTRINSIC_ATTRIBUTES] end |
#merge_custom_attributes_from_notice_error(merged_attributes) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/new_relic/noticed_error.rb', line 133 def merge_custom_attributes_from_notice_error(merged_attributes) if @attributes_from_notice_error from_notice_error = NewRelic::NoticedError.normalize_params(@attributes_from_notice_error) merged_attributes.merge_custom_attributes(from_notice_error) end end |
#merge_custom_attributes_from_transaction(merged_attributes) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/new_relic/noticed_error.rb', line 126 def merge_custom_attributes_from_transaction(merged_attributes) if @attributes from_transaction = @attributes.custom_attributes_for(DESTINATION) merged_attributes.merge_custom_attributes(from_transaction) end end |
#merged_custom_attributes(merged_attributes) ⇒ Object
We can get custom attributes from two sources–the transaction, which we hold in @attributes, or passed options to notice_error which show up in in our Attributes class for consistent handling
119 120 121 122 123 124 |
# File 'lib/new_relic/noticed_error.rb', line 119 def merged_custom_attributes(merged_attributes) merge_custom_attributes_from_transaction(merged_attributes) merge_custom_attributes_from_notice_error(merged_attributes) merged_attributes.custom_attributes_for(DESTINATION) end |
#processed_attributes ⇒ Object
Note that we process attributes lazily and store the result. This is because there is a possibility that a noticed error will be discarded and not sent back as a traced error or TransactionError.
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/new_relic/noticed_error.rb', line 95 def processed_attributes @processed_attributes ||= begin attributes = base_parameters merged_attributes = NewRelic::Agent::Attributes.new(NewRelic::Agent.instance.attribute_filter) append_attributes(attributes, USER_ATTRIBUTES, merged_custom_attributes(merged_attributes)) append_attributes(attributes, AGENT_ATTRIBUTES, build_agent_attributes(merged_attributes)) append_attributes(attributes, INTRINSIC_ATTRIBUTES, build_intrinsic_attributes) attributes end end |
#to_collector_array(encoder = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/new_relic/noticed_error.rb', line 82 def to_collector_array(encoder = nil) arr = [NewRelic::Helper.time_to_millis(), string(path), string(), string(exception_class_name), processed_attributes] arr << @transaction_id if @transaction_id arr end |