Class: Timber::Events::HTTPClientResponse
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::HTTPClientResponse
- Defined in:
- lib/timber/events/http_client_response.rb
Overview
This event should be installed automatically through integrations, such as the Integrations::NetHTTP integration.
The HTTP client response event tracks responses for outgoing HTTP requests. This gives you structured insight into communication with external services.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
-
#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) ⇒ HTTPClientResponse
constructor
A new instance of HTTPClientResponse.
- #message ⇒ Object
- #status_description ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(attributes) ⇒ HTTPClientResponse
Returns a new instance of HTTPClientResponse.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/timber/events/http_client_response.rb', line 11 def initialize(attributes) @headers = Util::HTTPEvent.normalize_headers(attributes[:headers]) @request_id = attributes[:request_id] @service_name = attributes[:service_name] @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) @body = Util::HTTPEvent.normalize_body(@headers["content-type"], attributes[:body]) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/timber/events/http_client_response.rb', line 9 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
9 10 11 |
# File 'lib/timber/events/http_client_response.rb', line 9 def headers @headers end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
9 10 11 |
# File 'lib/timber/events/http_client_response.rb', line 9 def request_id @request_id end |
#service_name ⇒ Object (readonly)
Returns the value of attribute service_name.
9 10 11 |
# File 'lib/timber/events/http_client_response.rb', line 9 def service_name @service_name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/timber/events/http_client_response.rb', line 9 def status @status end |
#time_ms ⇒ Object (readonly)
Returns the value of attribute time_ms.
9 10 11 |
# File 'lib/timber/events/http_client_response.rb', line 9 def time_ms @time_ms end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
28 29 30 |
# File 'lib/timber/events/http_client_response.rb', line 28 def as_json( = {}) {:http_client_response => to_hash} end |
#message ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/timber/events/http_client_response.rb', line 32 def = "Outgoing HTTP response" if service_name << " from #{service_name}" end << " #{status_description} in #{time_ms}ms" end |
#status_description ⇒ Object
42 43 44 |
# File 'lib/timber/events/http_client_response.rb', line 42 def status_description Rack::Utils::HTTP_STATUS_CODES[status] end |
#to_hash ⇒ Object Also known as: to_h
22 23 24 25 |
# File 'lib/timber/events/http_client_response.rb', line 22 def to_hash {body: body, headers: headers, request_id: request_id, service_name: service_name, status: status, time_ms: time_ms} end |