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 +4 -4
- data/lib/appydays/loggable/request_logger.rb +18 -10
- data/lib/appydays/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb1862009d51664566983d9878a212b53fbe7db55fa434e169460f86e946f7ed
|
4
|
+
data.tar.gz: 7eecb5b9dcbe494cdbfeb8724ac28f2e6a51db029caab5a39b5d5d8c2b08a7ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
46
|
-
|
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(
|
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
|
-
|
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
|
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(
|
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,
|
data/lib/appydays/version.rb
CHANGED