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: 7825d72bab21243fca9b81dd2f6b3d5f9514e346
4
- data.tar.gz: f31e2f859992fac1039450a8f42f1b22e5c7b91c
3
+ metadata.gz: b1d256e00f37404799aeb51dc7f5dd6aab648eb2
4
+ data.tar.gz: b4380f27151de0fbcb30e5920ee519c9f8c3e2da
5
5
  SHA512:
6
- metadata.gz: caa984d618acbbd775e7fb840662c16aa4403305aec814e0cbefecce23097d7c4abdec7439aece1c1231604d91a557687d6834214d8a7316ca1a94f03929ab45
7
- data.tar.gz: 2490d74401305db28a85a78c6b24cac8305c369630f5d7a4a37bffcdd8dbab55c4cd4ace7ee2eb861057ee61445c029438b830c6266a442513cb9856b2a6a63d
6
+ metadata.gz: e1237391687bdbe6a51421c385492c5983bdd29d5436c79c0b7b927fbc137ecda28e5209eaba84f00690af16cc67e9b75c3a905eaa872efccb11cafafbd21346
7
+ data.tar.gz: 811f8a7dee59434860f688f370013b672b6a8ebb09cced6c2b1e342646499324268119aaab250ccf1d6dc8a21d86db20eb189b3e5b5a7e2ab01abcbc322468e8
@@ -17,7 +17,7 @@ module PG
17
17
  end
18
18
 
19
19
  def general_log_with_request_id(request_id)
20
- Thread.current.dig(:general_log, request_id)
20
+ Thread.current[:general_log]&.fetch(request_id)
21
21
  end
22
22
 
23
23
  def delete_general_log(request_id)
@@ -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 env
21
- request_id = request.uuid
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).writefile(request)
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
@@ -1,7 +1,7 @@
1
1
  module PG
2
2
  class Connection
3
3
  module GeneralLog
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg-connection-general_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - abcang