Class: Airbrake::Rails::Event Private
- Inherits:
-
Object
- Object
- Airbrake::Rails::Event
- Includes:
- Loggable
- Defined in:
- lib/airbrake/rails/event.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Event is a wrapper around ActiveSupport::Notifications::Event.
Constant Summary collapse
- HTML_RESPONSE_WILDCARD =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"*/*"
- MILLISECOND =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1000
Instance Method Summary collapse
- #db_runtime ⇒ Object private
- #duration ⇒ Object private
- #groups ⇒ Object private
-
#initialize(*args) ⇒ Event
constructor
private
A new instance of Event.
- #method ⇒ Object private
- #params ⇒ Object private
- #response_type ⇒ Object private
- #sql ⇒ Object private
- #status_code ⇒ Object private
- #time ⇒ Object private
- #view_runtime ⇒ Object private
Constructor Details
#initialize(*args) ⇒ Event
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Event.
18 19 20 21 |
# File 'lib/airbrake/rails/event.rb', line 18 def initialize(*args) @event = ActiveSupport::Notifications::Event.new(*args) @rails_7_or_greater = ::Rails::VERSION::MAJOR >= 7 end |
Instance Method Details
#db_runtime ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/airbrake/rails/event.rb', line 40 def db_runtime @db_runtime ||= @event.payload[:db_runtime] || 0 end |
#duration ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
88 89 90 |
# File 'lib/airbrake/rails/event.rb', line 88 def duration @event.duration end |
#groups ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 |
# File 'lib/airbrake/rails/event.rb', line 60 def groups groups = {} groups[:db] = db_runtime if db_runtime > 0 groups[:view] = view_runtime if view_runtime > 0 groups end |
#method ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/airbrake/rails/event.rb', line 23 def method @event.payload[:method] end |
#params ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/airbrake/rails/event.rb', line 32 def params @event.payload[:params] end |
#response_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 |
# File 'lib/airbrake/rails/event.rb', line 27 def response_type response_type = @event.payload[:format] response_type == HTML_RESPONSE_WILDCARD ? :html : response_type end |
#sql ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 |
# File 'lib/airbrake/rails/event.rb', line 36 def sql @event.payload[:sql] end |
#status_code ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/airbrake/rails/event.rb', line 67 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 |
#time ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/airbrake/rails/event.rb', line 48 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 @rails_7_or_greater ? @event.time / MILLISECOND : @event.time end |
#view_runtime ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/airbrake/rails/event.rb', line 44 def view_runtime @view_runtime ||= @event.payload[:view_runtime] || 0 end |