Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit b1c354e

Browse files
committed
Add host to the HTTP context
1 parent 4a0509c commit b1c354e

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Adds the new `host` field into the `http` context, bumping the log event JSON schema to `3.2.0`.
13+
1014
## [2.3.4] - 2017-10-12
1115

1216
### Fixed

lib/timber/contexts/http.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ module Contexts
1515
class HTTP < Context
1616
@keyspace = :http
1717

18-
attr_reader :method, :path, :remote_addr, :request_id
18+
attr_reader :host, :method, :path, :remote_addr, :request_id
1919

2020
def initialize(attributes)
21+
@host = attributes[:host]
2122
@method = attributes[:method] || raise(ArgumentError.new(":method is required"))
22-
@path = attributes[:path] || raise(ArgumentError.new(":path is required"))
23+
@path = attributes[:path]
2324
@remote_addr = attributes[:remote_addr]
2425
@request_id = attributes[:request_id]
2526
end
2627

2728
# Builds a hash representation containing simple objects, suitable for serialization (JSON).
2829
def as_json(_options = {})
29-
{:method => method, :path => path, :remote_addr => remote_addr, :request_id => request_id}
30+
{:host => host, :method => method, :path => path, :remote_addr => remote_addr,
31+
:request_id => request_id}
3032
end
3133
end
3234
end

lib/timber/integrations/rack/http_context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class HTTPContext < Middleware
1111
def call(env)
1212
request = Util::Request.new(env)
1313
context = Contexts::HTTP.new(
14+
host: request.host,
1415
method: request.request_method,
1516
path: request.path,
1617
remote_addr: request.ip,

lib/timber/log_entry.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class LogEntry #:nodoc:
1111
BINARY_LIMIT_THRESHOLD = 1_000.freeze
1212
DT_PRECISION = 6.freeze
1313
MESSAGE_MAX_BYTES = 8192.freeze
14-
SCHEMA = "https://raw.githubusercontent.com/timberio/log-event-json-schema/v3.1.3/schema.json".freeze
14+
SCHEMA = "https://raw.githubusercontent.com/timberio/log-event-json-schema/v3.2.0/schema.json".freeze
1515

1616
attr_reader :context_snapshot, :event, :level, :message, :progname, :tags, :time, :time_ms
1717

spec/timber/integrations/rack/http_context_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def method_for_action(action_name)
4242
dispatch_rails_request("/rack_http")
4343
http_context = Thread.current[:_timber_context_snapshot][:http]
4444

45-
expect(http_context).to eq({:method=>"GET", :path=>"/rack_http", :remote_addr=>"123.456.789.10", :request_id=>"unique-request-id-1234"})
45+
expect(http_context).to eq({:host => "example.org", :method=>"GET", :path=>"/rack_http", :remote_addr=>"123.456.789.10", :request_id=>"unique-request-id-1234"})
4646

4747
lines = clean_lines(io.string.split("\n"))
4848
expect(lines.length).to eq(3)
4949
lines.each do |line|
50-
expect(line).to include("\"http\":{\"method\":\"GET\",\"path\":\"/rack_http\",\"remote_addr\":\"123.456.789.10\",\"request_id\":\"unique-request-id-1234\"}")
50+
expect(line).to include("\"http\":{\"host\":\"example.org\",\"method\":\"GET\",\"path\":\"/rack_http\",\"remote_addr\":\"123.456.789.10\",\"request_id\":\"unique-request-id-1234\"}")
5151
end
5252
end
5353
end

0 commit comments

Comments
 (0)