Sha256: 5c7cc9ebf018c87b1bd934eb3ab02e04a2448e705faa56156bfa83013c37bc71

Contents?: true

Size: 1.96 KB

Versions: 14

Compression:

Stored size: 1.96 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

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

14 entries across 14 versions & 1 rubygems

Version Path
newrelic_rpm-3.6.3.111 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.3.106 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.3.105.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.3.104 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.3.103.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.2.96 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.2.90.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.1.88 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.1.87 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.1.86.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.1.85.beta lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.0.83 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.0.78 lib/new_relic/noticed_error.rb
newrelic_rpm-3.6.0.74.beta lib/new_relic/noticed_error.rb