appydays 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f1f73c4eb2c61d4b2e218bc3254ba6dffe3241737cae24ba7be92b20f63223d
4
- data.tar.gz: 0b4f8eed51455f752dbe4885abeb9cbfb1178bbfb4e35397fd444858aabb0845
3
+ metadata.gz: cb1862009d51664566983d9878a212b53fbe7db55fa434e169460f86e946f7ed
4
+ data.tar.gz: 7eecb5b9dcbe494cdbfeb8724ac28f2e6a51db029caab5a39b5d5d8c2b08a7ea
5
5
  SHA512:
6
- metadata.gz: 927b8d9fe9ce1fb67fbac6b0431230b68a081a7a01edbc3db7c7878cda8c1671c3297255ec3869188a8409006f5db8ad47d78cacb3d6edeea12f7848c5ede5d6
7
- data.tar.gz: 161743e389b05dc0724dac0b034f40b19781e51a60b766e502cf5d2b370746353a137e38ddb0e952758a4625f15e959764762b9a2b5ede35aecc520f11687d0d
6
+ metadata.gz: 4a0c0fd8f35ac2e1d39a91cb6b9a32b753e57035c4f34e6ef42a16f32dd344ce7acd18b2198037b5b47e18132ddffcafeedae593dc5b9cf65c1b92756c6ff5c3
7
+ data.tar.gz: a9d3043afcb2e5c4338757fc83107b77d1bd67dccc863fed42e6114d512898794cc8723b07673f80f51fee4a527a03577c40a2476e43370ed0187b46833e6735
@@ -42,29 +42,36 @@ class Appydays::Loggable::RequestLogger
42
42
  # so clear the request tags first thing.
43
43
  self.class.request_tags.clear
44
44
  began_at = Time.now
45
- request_fields = self._request_tags(env, began_at)
46
- status, header, body = SemanticLogger.named_tagged(request_fields) { @app.call(env) }
45
+ request_id = self._ensure_request_id(env)
46
+ # Only use the request_id as the context/correllation id for log messages,
47
+ # otherwise we end up with a lot of log spam.
48
+ status, header, body = SemanticLogger.named_tagged(request_id:) do
49
+ @app.call(env)
50
+ end
47
51
  header = Rack::Utils::HeaderHash.new(header)
48
- body = Rack::BodyProxy.new(body) { self.log_finished(request_fields, began_at, status, header) }
52
+ body = Rack::BodyProxy.new(body) { self.log_finished(env, began_at, status, header) }
49
53
  [status, header, body]
50
54
  rescue StandardError => e
51
55
  began_at ||= nil
52
- request_fields ||= {}
53
- self.log_finished(request_fields, began_at, 599, {}, e)
56
+ self.log_finished(env, began_at, 599, {}, e)
54
57
  raise if @reraise
55
58
  end
56
59
 
57
- protected def _request_tags(env, began_at)
58
- req_id = SecureRandom.uuid.to_s
60
+ protected def _ensure_request_id(env)
61
+ req_id = env["HTTP_X_REQUEST_ID"] ||= SecureRandom.uuid.to_s
59
62
  env["HTTP_TRACE_ID"] ||= req_id
63
+ return req_id
64
+ end
65
+
66
+ protected def _request_tags(env, began_at)
60
67
  h = {
68
+ request_id: env["HTTP_X_REQUEST_ID"], # Added by _ensure_request_id
69
+ trace_id: env["HTTP_TRACE_ID"], # Legacy purposes
61
70
  remote_addr: env["HTTP_X_FORWARDED_FOR"] || env["REMOTE_ADDR"] || "-",
62
71
  request_started_at: began_at.to_s,
63
72
  request_method: env[Rack::REQUEST_METHOD],
64
73
  request_path: env[Rack::PATH_INFO],
65
74
  request_query: env.fetch(Rack::QUERY_STRING, "").empty? ? "" : "?#{env[Rack::QUERY_STRING]}",
66
- request_id: req_id,
67
- trace_id: env["HTTP_TRACE_ID"],
68
75
  }
69
76
  h.merge!(self.request_tags(env))
70
77
  return h
@@ -74,8 +81,9 @@ class Appydays::Loggable::RequestLogger
74
81
  return {}
75
82
  end
76
83
 
77
- protected def log_finished(tags, began_at, status, header, exc=nil)
84
+ protected def log_finished(env, began_at, status, header, exc=nil)
78
85
  elapsed = (Time.now - began_at).to_f
86
+ tags = self._request_tags(env, began_at)
79
87
  tags.merge!(
80
88
  response_finished_at: Time.now.iso8601,
81
89
  response_status: status,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appydays
4
- VERSION = "0.12.0"
4
+ VERSION = "0.12.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appydays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lithic Tech