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'.freeze

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.



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

def initialize(name, start, ending, transaction_id, payload)
  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.



12
13
14
# File 'lib/meta_request/event.rb', line 12

def duration
  @duration
end

Class Method Details

.events_for_exception(exception_wrapper) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/meta_request/event.rb', line 19

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