Class: Airbrake::Rails::Event Private

Inherits:
Object
  • Object
show all
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.

Since:

  • v9.0.3

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.

Returns:

  • (Integer)

Since:

  • v9.0.3

1000

Instance Method Summary collapse

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.

Since:

  • v9.0.3



18
19
20
# File 'lib/airbrake/rails/event.rb', line 18

def initialize(*args)
  @event = ActiveSupport::Notifications::Event.new(*args)
end

Instance Method Details

#db_runtimeObject

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.

Since:

  • v9.0.3



39
40
41
# File 'lib/airbrake/rails/event.rb', line 39

def db_runtime
  @db_runtime ||= @event.payload[:db_runtime] || 0
end

#durationObject

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.

Since:

  • v9.0.3



91
92
93
# File 'lib/airbrake/rails/event.rb', line 91

def duration
  @event.duration
end

#groupsObject

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.

Since:

  • v9.0.3



63
64
65
66
67
68
# File 'lib/airbrake/rails/event.rb', line 63

def groups
  groups = {}
  groups[:db] = db_runtime if db_runtime > 0
  groups[:view] = view_runtime if view_runtime > 0
  groups
end

#methodObject

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.

Since:

  • v9.0.3



22
23
24
# File 'lib/airbrake/rails/event.rb', line 22

def method
  @event.payload[:method]
end

#paramsObject

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.

Since:

  • v9.0.3



31
32
33
# File 'lib/airbrake/rails/event.rb', line 31

def params
  @event.payload[:params]
end

#rails_7_0?Boolean

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:

  • (Boolean)

Since:

  • v9.0.3



95
96
97
# File 'lib/airbrake/rails/event.rb', line 95

def rails_7_0?
  ::Rails::VERSION::MAJOR == 7 && ::Rails::VERSION::MINOR == 0
end

#response_typeObject

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.

Since:

  • v9.0.3



26
27
28
29
# File 'lib/airbrake/rails/event.rb', line 26

def response_type
  response_type = @event.payload[:format]
  response_type == HTML_RESPONSE_WILDCARD ? :html : response_type
end

#sqlObject

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.

Since:

  • v9.0.3



35
36
37
# File 'lib/airbrake/rails/event.rb', line 35

def sql
  @event.payload[:sql]
end

#status_codeObject

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.

Since:

  • v9.0.3



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/airbrake/rails/event.rb', line 70

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

#timeObject

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.

Since:

  • v9.0.3



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/airbrake/rails/event.rb', line 47

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

#view_runtimeObject

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.

Since:

  • v9.0.3



43
44
45
# File 'lib/airbrake/rails/event.rb', line 43

def view_runtime
  @view_runtime ||= @event.payload[:view_runtime] || 0
end