Class: Timber::Events::HTTPResponse

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

Instance Method Summary collapse

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

#additionsObject (readonly)

Returns the value of attribute additions.



8
9
10
# File 'lib/timber/events/http_server_response.rb', line 8

def additions
  @additions
end

#statusObject (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_msObject (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(_options = {})
  {:server_side_app => {:http_server_response => to_hash}}
end

#messageObject



26
27
28
29
30
# File 'lib/timber/events/http_server_response.rb', line 26

def message
  message = "Completed #{status} #{status_description} in #{time_ms}ms"
  message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
  message
end

#status_descriptionObject



32
33
34
# File 'lib/timber/events/http_server_response.rb', line 32

def status_description
  Rack::Utils::HTTP_STATUS_CODES[status]
end

#to_hashObject 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