Class: Timber::Contexts::HTTP

Inherits:
Timber::Context
  • Object
show all
Defined in:
lib/timber/contexts/http.rb

Overview

Note:

This context should be installed automatically through probes, such as the Probes::RackHTTPContext probe.

The HTTP content tracks the current HTTP request being processed. This serves as join data across your logs, allowing you to query all logs for any attribute presented here. For example, viewing all logs for a given request_id.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ HTTP

Returns a new instance of HTTP.



14
15
16
17
18
19
# File 'lib/timber/contexts/http.rb', line 14

def initialize(attributes)
  @method = attributes[:method] || raise(ArgumentError.new(":method is required"))
  @path = attributes[:path] || raise(ArgumentError.new(":path is required"))
  @remote_addr = attributes[:remote_addr]
  @request_id = attributes[:request_id]
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



12
13
14
# File 'lib/timber/contexts/http.rb', line 12

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/timber/contexts/http.rb', line 12

def path
  @path
end

#remote_addrObject (readonly)

Returns the value of attribute remote_addr.



12
13
14
# File 'lib/timber/contexts/http.rb', line 12

def remote_addr
  @remote_addr
end

#request_idObject (readonly)

Returns the value of attribute request_id.



12
13
14
# File 'lib/timber/contexts/http.rb', line 12

def request_id
  @request_id
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



21
22
23
# File 'lib/timber/contexts/http.rb', line 21

def as_json(_options = {})
  {:method => method, :path => path, :remote_addr => remote_addr, :request_id => request_id}
end