Class: Timber::Events::Exception

Inherits:
Timber::Event
  • Object
show all
Defined in:
lib/timber/events/exception.rb

Overview

Note:

This event should be installed automatically through integrations, such as the Integrations::ActionDispatch::DebugExceptions integration.

The exception event is used to track exceptions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Exception

Returns a new instance of Exception.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/timber/events/exception.rb', line 10

def initialize(attributes)
  @name = attributes[:name] || raise(ArgumentError.new(":name is required"))
  @exception_message = attributes[:exception_message] || raise(ArgumentError.new(":exception_message is required"))

  backtrace = attributes[:backtrace]
  if backtrace.nil? || backtrace == []
    raise(ArgumentError.new(":backtrace is required"))
  end

  # 10 items max
  @backtrace = backtrace[0..9].collect { |line| parse_backtrace_line(line) }
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



8
9
10
# File 'lib/timber/events/exception.rb', line 8

def backtrace
  @backtrace
end

#exception_messageObject (readonly)

Returns the value of attribute exception_message.



8
9
10
# File 'lib/timber/events/exception.rb', line 8

def exception_message
  @exception_message
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/timber/events/exception.rb', line 8

def name
  @name
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



28
29
30
# File 'lib/timber/events/exception.rb', line 28

def as_json(_options = {})
  {:server_side_app => {:exception => to_hash}}
end

#messageObject



32
33
34
# File 'lib/timber/events/exception.rb', line 32

def message
  "#{name} (#{exception_message})"
end

#to_hashObject Also known as: to_h



23
24
25
# File 'lib/timber/events/exception.rb', line 23

def to_hash
  {name: name, message: exception_message, backtrace: backtrace}
end