Class: Timber::Events::HTTPRequest

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

Overview

Note:

This event should be installed automatically through probes, such as the Probes::ActionControllerLogSubscriber probe.

The HTTP request event tracks incoming HTTP requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ HTTPRequest

Returns a new instance of HTTPRequest.



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

def initialize(attributes)
  @host = attributes[:host] || raise(ArgumentError.new(":host is required"))
  @method = attributes[:method] || raise(ArgumentError.new(":method is required"))
  @path = attributes[:path] || raise(ArgumentError.new(":path is required"))
  @port = attributes[:port]
  @query_params = attributes[:query_params]
  @content_type = attributes[:content_type]
  @remote_addr = attributes[:remote_addr]
  @referrer = attributes[:referrer]
  @request_id = attributes[:request_id]
  @user_agent = attributes[:user_agent]
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



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

def content_type
  @content_type
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#query_paramsObject (readonly)

Returns the value of attribute query_params.



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

def query_params
  @query_params
end

#referrerObject (readonly)

Returns the value of attribute referrer.



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

def referrer
  @referrer
end

#remote_addrObject (readonly)

Returns the value of attribute remote_addr.



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

def remote_addr
  @remote_addr
end

#request_idObject (readonly)

Returns the value of attribute request_id.



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

def request_id
  @request_id
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



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

def user_agent
  @user_agent
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/timber/events/http_request.rb', line 31

def as_json(_options = {})
  hash = to_hash
  hash[:headers] = Util::Hash.compact(hash[:headers])
  hash = Util::Hash.compact(hash)
  {:http_request => hash}
end

#messageObject



38
39
40
41
42
43
# File 'lib/timber/events/http_request.rb', line 38

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

#status_descriptionObject



45
46
47
# File 'lib/timber/events/http_request.rb', line 45

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

#to_hashObject Also known as: to_h



24
25
26
27
28
# File 'lib/timber/events/http_request.rb', line 24

def to_hash
  {host: host, method: method, path: path, port: port, query_params: query_params,
    headers: {content_type: content_type, remote_addr: remote_addr, referrer: referrer,
      request_id: request_id, user_agent: user_agent}}
end