Sha256: f8b1462c1c528ec155d01f7d9be28a4c3ab84b156b00d9a2089a317e6b133b1b

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

require 'new_relic/helper'

# This class encapsulates an error that was noticed by New Relic in a managed app.
class NewRelic::NoticedError
  extend NewRelic::CollectionHelper
  attr_accessor :path, :timestamp, :params, :exception_class, :message
  attr_reader :exception_id

  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

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

  include NewRelic::Coerce

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

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
wd_newrelic_rpm-3.5.8 lib/new_relic/noticed_error.rb
sundawg_newrelic_rpm-3.5.8.2 lib/new_relic/noticed_error.rb
sundawg_newrelic_rpm-3.5.8.1 lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.8.72 lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.8.70 lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.8.64.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.7.59 lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.7.59.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.7.58.beta lib/new_relic/noticed_error.rb
wd_newrelic_rpm-3.5.6 lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.7.57.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.5.6.55 lib/new_relic/noticed_error.rb