Class: CrashLog::Payload

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/crash_log/payload.rb

Constant Summary

Constants included from Logging

Logging::ANSI

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included

Constructor Details

#initialize(event_data, config) ⇒ Payload

Returns a new instance of Payload.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/crash_log/payload.rb', line 25

def initialize(event_data, config)
  @config = config || {}
  @event_data = event_data
  @context = {}
  @environment = {}
  @data = {}
  @backtrace_filters = config[:backtrace_filters] || []

  # Actually serialize the exception/event hash for transport
  @event = serialize_event(event_data)

  add_environment_data(:system => SystemInformation.to_hash)
  add_context(:stage => config.stage)
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



52
53
54
# File 'lib/crash_log/payload.rb', line 52

def backtrace
  @backtrace
end

#backtrace_filtersObject (readonly)

Returns the value of attribute backtrace_filters.



23
24
25
# File 'lib/crash_log/payload.rb', line 23

def backtrace_filters
  @backtrace_filters
end

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/crash_log/payload.rb', line 23

def config
  @config
end

#contextObject (readonly)

Returns the value of attribute context.



52
53
54
# File 'lib/crash_log/payload.rb', line 52

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



23
24
25
# File 'lib/crash_log/payload.rb', line 23

def data
  @data
end

#environmentObject (readonly)

Returns the value of attribute environment.



52
53
54
# File 'lib/crash_log/payload.rb', line 52

def environment
  @environment
end

#eventObject (readonly)

Returns the value of attribute event.



52
53
54
# File 'lib/crash_log/payload.rb', line 52

def event
  @event
end

#exception_objectObject (readonly)

Returns the value of attribute exception_object.



52
53
54
# File 'lib/crash_log/payload.rb', line 52

def exception_object
  @exception_object
end

Class Method Details

.build(exception, config) {|payload| ... } ⇒ Object

Yields:

  • (payload)


7
8
9
10
11
# File 'lib/crash_log/payload.rb', line 7

def self.build(exception, config, &block)
  payload = new(exception, config)
  yield(payload) if block_given?
  payload
end

Instance Method Details

#add_context(data) ⇒ Object



58
59
60
# File 'lib/crash_log/payload.rb', line 58

def add_context(data)
  (@context ||= {}).merge!(data) if data.is_a?(Hash)
end

#add_data(data) ⇒ Object



62
63
64
# File 'lib/crash_log/payload.rb', line 62

def add_data(data)
  (@data ||= {}).merge!(data) if data.is_a?(Hash)
end

#add_environment_data(data) ⇒ Object



70
71
72
# File 'lib/crash_log/payload.rb', line 70

def add_environment_data(data)
  @environment.merge!(data) if data.respond_to?(:keys)
end

#add_session_data(data) ⇒ Object



66
67
68
# File 'lib/crash_log/payload.rb', line 66

def add_session_data(data)
  (@data[:session] ||= {}).merge!(data) if data.is_a?(Hash)
end

#bodyObject



54
55
56
# File 'lib/crash_log/payload.rb', line 54

def body
  renderer.render
end

#deliverObject



40
41
42
43
44
45
46
# File 'lib/crash_log/payload.rb', line 40

def deliver
  error("Not configured, please run CrashLog.configure") && return unless reporter

  if reporter.notify(self.body)
    reporter.result
  end
end

#deliver!Object

Delivers this payload to CrashLog

Captures any exceptions and logs them.



16
17
18
19
20
21
# File 'lib/crash_log/payload.rb', line 16

def deliver!
  deliver
rescue Exception => e
  error('Failed to deliver notification to CrashLog collector')
  log_exception(e)
end

#notifierObject

Various meta data about this notifier gem



86
87
88
89
90
91
92
# File 'lib/crash_log/payload.rb', line 86

def notifier
  {
    :name => "crashlog",
    :version => CrashLog::VERSION,
    :language => 'Ruby'
  }
end

#reporterObject



48
49
50
# File 'lib/crash_log/payload.rb', line 48

def reporter
  CrashLog.reporter
end

#timestampObject

The canonical time this exception occurred.

Other notifiers leave this to the collector to set, we however take time more seriously and use this figure internally to detect processing time irregularities.

Returns UNIX UTC timestamp integer.



81
82
83
# File 'lib/crash_log/payload.rb', line 81

def timestamp
  Time.now.utc.to_i
end