pg-connection-general_log 0.0.3 → 0.0.4
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1d256e00f37404799aeb51dc7f5dd6aab648eb2
|
4
|
+
data.tar.gz: b4380f27151de0fbcb30e5920ee519c9f8c3e2da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1237391687bdbe6a51421c385492c5983bdd29d5436c79c0b7b927fbc137ecda28e5209eaba84f00690af16cc67e9b75c3a905eaa872efccb11cafafbd21346
|
7
|
+
data.tar.gz: 811f8a7dee59434860f688f370013b672b6a8ebb09cced6c2b1e342646499324268119aaab250ccf1d6dc8a21d86db20eb189b3e5b5a7e2ab01abcbc322468e8
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module PG
|
2
4
|
class Connection
|
3
5
|
module GeneralLog
|
@@ -17,18 +19,22 @@ module PG
|
|
17
19
|
|
18
20
|
def call(env)
|
19
21
|
if Middleware.enabled
|
20
|
-
request = Rack::Request.new
|
21
|
-
request_id =
|
22
|
+
request = Rack::Request.new(env)
|
23
|
+
request_id = extract_request_id(env)
|
22
24
|
Thread.current[:request_id] = request_id
|
23
25
|
end
|
24
26
|
@app.call(env)
|
25
27
|
ensure
|
26
28
|
if Middleware.enabled
|
27
|
-
GeneralLog.general_log_with_request_id(request_id)
|
29
|
+
GeneralLog.general_log_with_request_id(request_id)&.writefile(request)
|
28
30
|
GeneralLog.delete_general_log(request_id)
|
29
31
|
Thread.current[:request_id] = nil
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
def extract_request_id(env)
|
36
|
+
env['action_dispatch.request_id'] || env['HTTP_X_REQUEST_ID'] || SecureRandom.hex(16)
|
37
|
+
end
|
32
38
|
end
|
33
39
|
end
|
34
40
|
end
|