Class: Timber::Events::HTTPRequest
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::HTTPRequest
- Defined in:
- lib/timber/events/http_request.rb
Overview
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
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#query_params ⇒ Object
readonly
Returns the value of attribute query_params.
-
#referrer ⇒ Object
readonly
Returns the value of attribute referrer.
-
#remote_addr ⇒ Object
readonly
Returns the value of attribute remote_addr.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ HTTPRequest
constructor
A new instance of HTTPRequest.
- #message ⇒ Object
- #status_description ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
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_type ⇒ Object (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 |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/timber/events/http_request.rb', line 8 def host @host end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/timber/events/http_request.rb', line 8 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/timber/events/http_request.rb', line 8 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/timber/events/http_request.rb', line 8 def port @port end |
#query_params ⇒ Object (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 |
#referrer ⇒ Object (readonly)
Returns the value of attribute referrer.
8 9 10 |
# File 'lib/timber/events/http_request.rb', line 8 def referrer @referrer end |
#remote_addr ⇒ Object (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_id ⇒ Object (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_agent ⇒ Object (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( = {}) hash = to_hash hash[:headers] = Util::Hash.compact(hash[:headers]) hash = Util::Hash.compact(hash) {:http_request => hash} end |
#message ⇒ Object
38 39 40 41 42 43 |
# File 'lib/timber/events/http_request.rb', line 38 def 'Started %s "%s" for %s' % [ method, path, remote_addr] end |
#status_description ⇒ Object
45 46 47 |
# File 'lib/timber/events/http_request.rb', line 45 def status_description Rack::Utils::HTTP_STATUS_CODES[status] end |
#to_hash ⇒ Object 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 |