Class: Timber::Events::HTTPResponse
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::HTTPResponse
- Defined in:
- lib/timber/events/http_server_response.rb
Overview
Note:
This event should be installed automatically through probes, such as the Probes::ActionControllerLogSubscriber probe.
The HTTP response event tracks outgoing HTTP request responses.
Instance Attribute Summary collapse
-
#additions ⇒ Object
readonly
Returns the value of attribute additions.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#time_ms ⇒ Object
readonly
Returns the value of attribute time_ms.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ HTTPResponse
constructor
A new instance of HTTPResponse.
- #message ⇒ Object
- #status_description ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(attributes) ⇒ HTTPResponse
Returns a new instance of HTTPResponse.
10 11 12 13 14 15 |
# File 'lib/timber/events/http_server_response.rb', line 10 def initialize(attributes) @status = attributes[:status] || raise(ArgumentError.new(":status is required")) @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required")) @time_ms = @time_ms.round(6) @additions = attributes[:additions] end |
Instance Attribute Details
#additions ⇒ Object (readonly)
Returns the value of attribute additions.
8 9 10 |
# File 'lib/timber/events/http_server_response.rb', line 8 def additions @additions end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/timber/events/http_server_response.rb', line 8 def status @status end |
#time_ms ⇒ Object (readonly)
Returns the value of attribute time_ms.
8 9 10 |
# File 'lib/timber/events/http_server_response.rb', line 8 def time_ms @time_ms end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
22 23 24 |
# File 'lib/timber/events/http_server_response.rb', line 22 def as_json( = {}) {:server_side_app => {:http_server_response => to_hash}} end |
#message ⇒ Object
26 27 28 29 30 |
# File 'lib/timber/events/http_server_response.rb', line 26 def = "Completed #{status} #{status_description} in #{time_ms}ms" << " (#{additions.join(" | ".freeze)})" unless additions.empty? end |
#status_description ⇒ Object
32 33 34 |
# File 'lib/timber/events/http_server_response.rb', line 32 def status_description Rack::Utils::HTTP_STATUS_CODES[status] end |
#to_hash ⇒ Object Also known as: to_h
17 18 19 |
# File 'lib/timber/events/http_server_response.rb', line 17 def to_hash {status: status, time_ms: time_ms} end |