Class: Timber::Events::HTTPClientRequest

Inherits:
Timber::Event
  • Object
show all
Defined in:
lib/timber/events/http_client_request.rb

Overview

Note:

This event should be installed automatically through integrations, such as the Integrations::NetHTTP integration.

The HTTP client request event tracks outgoing HTTP requests giving you structured insight into communication with external services.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ HTTPClientRequest

Returns a new instance of HTTPClientRequest.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/timber/events/http_client_request.rb', line 12

def initialize(attributes)
  @headers = Util::HTTPEvent.normalize_headers(attributes[:headers])
  @host = attributes[:host] || raise(ArgumentError.new(":host is required"))
  @method = Util::HTTPEvent.normalize_method(attributes[:method]) || raise(ArgumentError.new(":method is required"))
  @path = attributes[:path]
  @port = attributes[:port]
  @query_string = Util::HTTPEvent.normalize_query_string(attributes[:query_string])
  @request_id = attributes[:request_id]
  @scheme = attributes[:scheme] || raise(ArgumentError.new(":scheme is required"))
  @service_name = attributes[:service_name]

  @body = Util::HTTPEvent.normalize_body(@headers["content-type"], attributes[:body])
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def headers
  @headers
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def host
  @host
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def port
  @port
end

#query_stringObject (readonly)

Returns the value of attribute query_string.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def query_string
  @query_string
end

#request_idObject (readonly)

Returns the value of attribute request_id.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def request_id
  @request_id
end

#schemeObject (readonly)

Returns the value of attribute scheme.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def scheme
  @scheme
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



9
10
11
# File 'lib/timber/events/http_client_request.rb', line 9

def service_name
  @service_name
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



33
34
35
# File 'lib/timber/events/http_client_request.rb', line 33

def as_json(_options = {})
  {:server_side_app => {:http_client_request => to_hash}}
end

#messageObject



37
38
39
40
41
42
43
44
45
# File 'lib/timber/events/http_client_request.rb', line 37

def message
  message = 'Outgoing HTTP request to '

  if service_name
    mesage << " #{service_name} [#{method}] #{full_path}"
  else
    message << " [#{method}] #{full_url}"
  end
end

#status_descriptionObject



47
48
49
# File 'lib/timber/events/http_client_request.rb', line 47

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

#to_hashObject Also known as: to_h



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

def to_hash
  {headers: headers, host: host, method: method, parsed_body_json: parsed_body_json,
    path: path, port: port, query_string: query_string, request_id: request_id,
    scheme: scheme, service_name: service_name}
end