Class: NewRelic::NoticedError

Inherits:
Object
  • Object
show all
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

Constants included from CollectionHelper

CollectionHelper::DEFAULT_ARRAY_TRUNCATION_SIZE, CollectionHelper::DEFAULT_TRUNCATION_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CollectionHelper

normalize_params, strip_nr_from_backtrace

Methods included from Coerce

#float, #int, #log_failure, #string

Constructor Details

#initialize(path, data, exception, timestamp = Time.now) ⇒ NoticedError

Returns a new instance of NoticedError.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/new_relic/noticed_error.rb', line 9

def initialize(path, data, exception, timestamp = Time.now)
  @exception_id = exception.object_id
  @path = path
  @params = NewRelic::NoticedError.normalize_params(data)

  @exception_class = exception.is_a?(Exception) ? exception.class.name : 'Error'

  if exception.respond_to?('original_exception')
    @message = exception.original_exception.message.to_s
  else
    @message = (exception || '<no message>').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
  
  # obfuscate error message if necessary
  if NewRelic::Agent.config[:high_security]
    @message = NewRelic::Agent::Database.obfuscate_sql(@message)
  end
  
  @timestamp = timestamp
end

Instance Attribute Details

#exception_classObject

Returns the value of attribute exception_class.



6
7
8
# File 'lib/new_relic/noticed_error.rb', line 6

def exception_class
  @exception_class
end

#exception_idObject (readonly)

Returns the value of attribute exception_id.



7
8
9
# File 'lib/new_relic/noticed_error.rb', line 7

def exception_id
  @exception_id
end

#messageObject

Returns the value of attribute message.



6
7
8
# File 'lib/new_relic/noticed_error.rb', line 6

def message
  @message
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/new_relic/noticed_error.rb', line 6

def params
  @params
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/new_relic/noticed_error.rb', line 6

def path
  @path
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/new_relic/noticed_error.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#==(other) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/new_relic/noticed_error.rb', line 42

def ==(other)
  if other.respond_to?(:exception_id)
    @exception_id == other.exception_id
  else
    false
  end
end

#to_collector_array(encoder = nil) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/new_relic/noticed_error.rb', line 52

def to_collector_array(encoder=nil)
  [ NewRelic::Helper.time_to_millis(@timestamp),
    string(@path),
    string(@message),
    string(@exception_class),
    @params ]
end