class Airbrake::Rails::Event
@api private
@since v9.0.3
Event is a wrapper around ActiveSupport::Notifications::Event.
def db_runtime
def db_runtime @db_runtime ||= @event.payload[:db_runtime] || 0 end
def duration
def duration @event.duration end
def groups
def groups groups = {} groups[:db] = db_runtime if db_runtime > 0 groups[:view] = view_runtime if view_runtime > 0 groups end
def initialize(*args)
def initialize(*args) @event = ActiveSupport::Notifications::Event.new(*args) end
def method
def method @event.payload[:method] end
def params
def params @event.payload[:params] end
def rails_7_0?
def rails_7_0? ::Rails::VERSION::MAJOR == 7 && ::Rails::VERSION::MINOR == 0 end
def response_type
def response_type response_type = @event.payload[:format] response_type == HTML_RESPONSE_WILDCARD ? :html : response_type end
def sql
def sql @event.payload[:sql] end
def status_code
def status_code return @event.payload[:status] if @event.payload[:status] if @event.payload[:exception] status = ActionDispatch::ExceptionWrapper.status_code_for_exception( @event.payload[:exception].first, ) status = 500 if status == 0 return status end # The ActiveSupport event doesn't have status only in two cases: # - an exception was thrown # - unauthorized access # We have already handled the exception so what's left is unauthorized # access. There's no way to know for sure it's unauthorized access, so # we are rather optimistic here. 401 end
def time
def time # On RailsĀ 7+ `ActiveSupport::Notifications::Event#time` returns an # instance of Float. It represents monotonic time in milliseconds. # Airbrake Ruby expects that the provided time is in seconds. Hence, # we need to convert it from milliseconds to seconds. In the # versions below Rails 7, time is an instance of Time. # # Relevant commit: # https://github.com/rails/rails/commit/81d0dc90becfe0b8e7f7f26beb66c25d84b8ec7f # # Ensure this conversion is applied exclusively for Rails 7.0 return @event.time / MILLISECOND if rails_7_0? @event.time end
def view_runtime
def view_runtime @view_runtime ||= @event.payload[:view_runtime] || 0 end