Class: RailsSpotlight::Event

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

Overview

Subclass of ActiveSupport Event that is JSON encodable

Constant Summary collapse

NOT_JSON_ENCODABLE =
'Not JSON Encodable'
NON_SERIALIZABLE_CLASSES =
[Proc, Binding, Method, UnboundMethod, Thread, IO, Class, Module].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.



15
16
17
18
19
20
21
22
23
# File 'lib/rails_spotlight/event.rb', line 15

def initialize(name, start, ending, transaction_id, payload)
  @seen_not_encodable = Set.new
  raw_payload = json_encodable(payload)
  raw_payload.merge!(raw_payload[:original_callsite]) if raw_payload[:original_callsite].present? && raw_payload[:filename].blank?
  super(name, start, ending, transaction_id, raw_payload)
  @duration = 1000.0 * (ending - start)
rescue # rubocop:disable Lint/RedundantCopDisableDirective, Style/RescueStandardError
  @duration = 0
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



13
14
15
# File 'lib/rails_spotlight/event.rb', line 13

def duration
  @duration
end

#seen_not_encodableObject (readonly)

Returns the value of attribute seen_not_encodable.



13
14
15
# File 'lib/rails_spotlight/event.rb', line 13

def seen_not_encodable
  @seen_not_encodable
end

Class Method Details

.events_for_exception(exception_wrapper) ⇒ Object



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

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:)
  end
end