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 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.
Constant Summary collapse
- BODY_MAX_BYTES =
8192.freeze
- HEADERS_JSON_MAX_BYTES =
8192.freeze
- HEADERS_TO_SANITIZE =
['authorization', 'x-amz-security-token'].freeze
- HOST_MAX_BYTES =
256.freeze
- METHOD_MAX_BYTES =
20.freeze
- PATH_MAX_BYTES =
2048.freeze
- QUERY_STRING_MAX_BYTES =
2048.freeze
- REQUEST_ID_MAX_BYTES =
256.freeze
- SCHEME_MAX_BYTES =
20.freeze
- SERVICE_NAME_MAX_BYTES =
256.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#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_string ⇒ Object
readonly
Returns the value of attribute query_string.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#service_name ⇒ Object
readonly
Returns the value of attribute service_name.
Instance Method Summary collapse
-
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
-
#initialize(attributes) ⇒ HTTPRequest
constructor
A new instance of HTTPRequest.
- #message ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(attributes) ⇒ HTTPRequest
Returns a new instance of HTTPRequest.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/timber/events/http_request.rb', line 26 def initialize(attributes) normalizer = Util::AttributeNormalizer.new(attributes) body_limit = Config.instance.http_body_limit || BODY_MAX_BYTES headers_to_sanitize = HEADERS_TO_SANITIZE + (Config.instance.http_header_filters || []) @body = normalizer.fetch(:body, :string, :limit => body_limit) @content_length = normalizer.fetch(:content_length, :integer) @headers = normalizer.fetch(:headers, :hash, :sanitize => headers_to_sanitize) @host = normalizer.fetch(:host, :string, :limit => HOST_MAX_BYTES) @method = normalizer.fetch!(:method, :string, :upcase => true, :limit => METHOD_MAX_BYTES) @path = normalizer.fetch(:path, :string, :limit => PATH_MAX_BYTES) @port = normalizer.fetch(:port, :integer) @query_string = normalizer.fetch(:query_string, :string, :limit => QUERY_STRING_MAX_BYTES) @scheme = normalizer.fetch(:scheme, :string, :limit => SCHEME_MAX_BYTES) @request_id = normalizer.fetch(:request_id, :string, :limit => REQUEST_ID_MAX_BYTES) @service_name = normalizer.fetch(:service_name, :string, :limit => SERVICE_NAME_MAX_BYTES) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def body @body end |
#content_length ⇒ Object (readonly)
Returns the value of attribute content_length.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def content_length @content_length end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def headers @headers end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def host @host end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def port @port end |
#query_string ⇒ Object (readonly)
Returns the value of attribute query_string.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def query_string @query_string end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def request_id @request_id end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def scheme @scheme end |
#service_name ⇒ Object (readonly)
Returns the value of attribute service_name.
23 24 25 |
# File 'lib/timber/events/http_request.rb', line 23 def service_name @service_name end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
62 63 64 |
# File 'lib/timber/events/http_request.rb', line 62 def as_json( = {}) {:http_request => to_hash} end |
#message ⇒ Object
66 67 68 |
# File 'lib/timber/events/http_request.rb', line 66 def 'Started %s "%s"' % [method, path] end |
#to_hash ⇒ Object Also known as: to_h
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/timber/events/http_request.rb', line 44 def to_hash @to_hash ||= Util::NonNilHashBuilder.build do |h| h.add(:body, body) h.add(:content_length, content_length) h.add(:headers_json, headers, :json_encode => true, :limit => HEADERS_JSON_MAX_BYTES) h.add(:host, host) h.add(:method, method) h.add(:path, path) h.add(:port, port) h.add(:query_string, query_string) h.add(:request_id, request_id) h.add(:scheme, scheme) h.add(:service_name, service_name) end end |