Class: MetaRequest::Event

Inherits:
ActiveSupport::Notifications::Event
  • Object
show all
Defined in:
lib/meta_request/event.rb

Overview

Subclass of ActiveSupport Event that is JSON encodable

Constant Summary collapse

NOT_JSON_ENCODABLE =
'Not JSON Encodable'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, start, ending, transaction_id, payload) ⇒ Event

Returns a new instance of Event.



16
17
18
19
20
# File 'lib/meta_request/event.rb', line 16

def initialize(name, start, ending, transaction_id, payload)
  @name = name
  super(name, start, ending, transaction_id, json_encodable(payload))
  @duration = 1000.0 * (ending - start)
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



14
15
16
# File 'lib/meta_request/event.rb', line 14

def duration
  @duration
end

Class Method Details

.events_for_exception(exception_wrapper) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/meta_request/event.rb', line 22

def self.events_for_exception(exception_wrapper)
  if defined?(ActionDispatch::ExceptionWrapper)
    exception = exception_wrapper.exception
    trace = exception_wrapper.application_trace
    trace = exception_wrapper.framework_trace if trace.empty?
  else
    exception = exception_wrapper
    trace = exception.backtrace
  end
  trace.unshift "#{exception.class} (#{exception.message})"
  trace.map do |call|
    Event.new('process_action.action_controller.exception', 0, 0, nil, call: call)
  end
end