class OneApm::NoticedError

This class encapsulates an error that was noticed by OneApm in a managed app.

Constants

OA_STRIPPED_EXCEPTION_REPLACEMENT_MESSAGE

Attributes

exception_class_name[RW]
exception_id[R]
is_internal[R]
message[RW]
params[RW]
path[RW]
timestamp[RW]

Public Class Methods

new(path, data, exception, timestamp = Time.now) click to toggle source
# File lib/one_apm/errors/noticed_error.rb, line 15
def initialize(path, data, exception, timestamp = Time.now)
  @exception_id = exception.object_id
  @path = path
  @params = OneApm::NoticedError.normalize_params(data)

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

  # 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 < OneApm::Agent::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

  # replace error message if enabled
  if OneApm::Manager.config[:'strip_exception_messages.enabled'] &&
     !self.class.passes_message_whitelist(exception.class)
    @message = OA_STRIPPED_EXCEPTION_REPLACEMENT_MESSAGE
  end

  @timestamp = timestamp
end
passes_message_whitelist(exception_class) click to toggle source
# File lib/one_apm/errors/noticed_error.rb, line 66
def self.passes_message_whitelist(exception_class)
  OneApm::Manager.config.stripped_exceptions_whitelist.any? do |klass|
    exception_class <= klass
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/one_apm/errors/noticed_error.rb, line 58
def ==(other)
  if other.respond_to?(:exception_id)
    exception_id == other.exception_id
  else
    false
  end
end
to_collector_array(encoder=nil) click to toggle source
# File lib/one_apm/errors/noticed_error.rb, line 72
def to_collector_array(encoder=nil)
  [ OneApm::Helper.time_to_millis(timestamp),
    string(path),
    string(message),
    string(exception_class_name),
    params ]
end