Class: Timber::Events::HTTPServerRequest

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

Overview

Note:

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

The HTTP server request event tracks incoming HTTP requests to your HTTP server. Such as unicorn, webrick, puma, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ HTTPServerRequest

Returns a new instance of HTTPServerRequest.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/timber/events/http_server_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] || raise(ArgumentError.new(":path is required"))
  @port = attributes[:port]
  @query_string = Util::HTTPEvent.normalize_query_string(attributes[:query_string])
  @scheme = attributes[:scheme] || raise(ArgumentError.new(":scheme is required"))
  @request_id = attributes[:request_id]

  # This is disabled for now. The ControllerCall event records the parsed params.
  # This should be sufficient for body inspection. If we come across a case where
  # it is not we can consider re-enabling this.
  # @body = Util::HTTPEvent.normalize_body(attributes[:body])
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/timber/events/http_server_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_server_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_server_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_server_request.rb', line 9

def scheme
  @scheme
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



34
35
36
# File 'lib/timber/events/http_server_request.rb', line 34

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

#messageObject



38
39
40
# File 'lib/timber/events/http_server_request.rb', line 38

def message
  'Started %s "%s"' % [method, path]
end

#to_hashObject Also known as: to_h



28
29
30
31
# File 'lib/timber/events/http_server_request.rb', line 28

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