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.



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

def initialize(application, exception, extra=nil)
  @application = application
  @exception   = exception
  @backtrace   = Backtrace.new(exception.backtrace)
  @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

#backtraceObject (readonly)

Returns the value of attribute backtrace.



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

def backtrace
  @backtrace
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.



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

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)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/radar/exception_event.rb', line 29

def to_hash
  return @_to_hash_result if @_to_hash_result

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

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

  application.config.filters.values.each do |filter|
    result = filter.call(result)
  end

  # Cache the resulting hash to it is only generated once.
  @_to_hash_result = result
  result
end

#to_jsonString

JSONified #to_hash output.

Returns:

  • (String)


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

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)


67
68
69
# File 'lib/radar/exception_event.rb', line 67

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