Class: Radar::ExceptionEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/radar/exception_event.rb

Overview

Represents the event of an exception being captured. This class contains references to the Application and exception which is raised.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, exception, extra = nil) ⇒ ExceptionEvent

Returns a new instance of ExceptionEvent.



14
15
16
17
18
19
# File 'lib/radar/exception_event.rb', line 14

def initialize(application, exception, extra=nil)
  @application = application
  @exception = exception
  @extra = extra || {}
  @occurred_at = Time.now
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



9
10
11
# File 'lib/radar/exception_event.rb', line 9

def application
  @application
end

#exceptionObject (readonly)

Returns the value of attribute exception.



10
11
12
# File 'lib/radar/exception_event.rb', line 10

def exception
  @exception
end

#extraObject (readonly)

Returns the value of attribute extra.



12
13
14
# File 'lib/radar/exception_event.rb', line 12

def extra
  @extra
end

#occurred_atObject (readonly)

Returns the value of attribute occurred_at.



11
12
13
# File 'lib/radar/exception_event.rb', line 11

def occurred_at
  @occurred_at
end

Instance Method Details

#to_hashHash

A hash of information about this exception event. This includes Application#to_hash as well as information about the exception. This also includes any data_extensions if specified.

Returns:

  • (Hash)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/radar/exception_event.rb', line 27

def to_hash
  result = { :application => application.to_hash,
    :exception => {
      :klass => exception.class.to_s,
      :message => exception.message,
      :backtrace => exception.backtrace,
      :uniqueness_hash => uniqueness_hash
    },
    :occurred_at => occurred_at.to_i
  }

  if !application.config.data_extensions.empty?
    application.config.data_extensions.values.each do |extension|
      Support::Hash.deep_merge!(result, extension.new(self).to_hash)
    end
  end

  result
end

#to_jsonString

JSONified #to_hash output.

Returns:

  • (String)


50
51
52
# File 'lib/radar/exception_event.rb', line 50

def to_json
  to_hash.to_json
end

#uniqueness_hashString

Returns uniqueness hash to test if one event is roughly equivalent to another. The uniqueness hash is generated by taking the exception backtrace and class and generating the SHA1 hash of those concatenated.

Returns:

  • (String)


59
60
61
# File 'lib/radar/exception_event.rb', line 59

def uniqueness_hash
  Digest::SHA1.hexdigest("#{exception.class}-#{exception.backtrace rescue 'blank'}")
end