minato_logger 0.2.14 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4353d7f52d8e5b812f3dcbcb4d8b858f26aeba0e8bb69f3d8ee3c251997d60f3
4
- data.tar.gz: 3abd0c444b2595ed337a95a74d2a79b7a1178178af9236fbdc1ccf498dfa0c77
3
+ metadata.gz: a92bc90dad9351db28e1822889e30507ec655fbbd8af5d8958e0bd71d0543adf
4
+ data.tar.gz: 116eae9a2b9e93b22227c349bac98bdf939575ab6ffac7c1a381ce34a262f297
5
5
  SHA512:
6
- metadata.gz: 26d919b4c5e727e0539b6737c5cb5d7379e6ef5500b1d97d9c9de73a411a4914202a64b54076600629f25a7de81f2a304ed9caf503733f01b13c98edc398ef59
7
- data.tar.gz: 8bdf7d8ccca898cb5eba5e9e4adca003ffa6537d024a580af3fb3a1ef759437a8fc11fba161fd18df7d6c1f21bb09145d795052b939773bc1033b372d8617859
6
+ metadata.gz: fe0647f14553910186ae4bd62937ef60d9768b2c0875aed66a921696c786f3f867057f7016d2551f622d5d43654979225a15a80efe64ef61a8c4fe2e93bb3d01
7
+ data.tar.gz: 95ff3b9a514096cd59de2f4f48238646beaec3ab8da2cbd712aed8fe26db654ce70506636bef85142c926794c6db1ff327c5e121cdf9f4e2e1fe0bdf5d9d9702
data/.rubocop.yml CHANGED
@@ -18,7 +18,7 @@ Style/Documentation:
18
18
  Enabled: false
19
19
 
20
20
  Layout/LineLength:
21
- Max: 120
21
+ Max: 125
22
22
 
23
23
  Metrics/ClassLength:
24
- Max: 120
24
+ Max: 150
@@ -2,11 +2,16 @@
2
2
 
3
3
  module MinatoLogger
4
4
  class Configuration
5
- attr_reader :middleware, :route_blacklist
5
+ attr_reader :middleware, :route_blacklist, :sensitive_headers
6
6
 
7
7
  def initialize
8
8
  @middleware = MinatoLogger::Middleware.new
9
9
  @route_blacklist = %w[/health/alive /health/ready]
10
+ @sensitive_headers = %w[
11
+ AUTHORIZATION PROXY_AUTHORIZATION X_CSRF_TOKEN
12
+ HTTP_AUTHORIZATION HTTP_PROXY_AUTHORIZATION
13
+ HTTP_X_CSRF_TOKEN COOKIE HTTP_COOKIE
14
+ ]
10
15
 
11
16
  yield(self) if block_given?
12
17
  end
@@ -6,22 +6,18 @@ require 'rails/rack/logger'
6
6
  module MinatoLogger
7
7
  module Middlewares
8
8
  class RequestResponseLogger < Rails::Rack::Logger
9
- SENSITIVE_HEADERS = %w[
10
- AUTHORIZATION PROXY_AUTHORIZATION X_CSRF_TOKEN
11
- HTTP_AUTHORIZATION HTTP_PROXY_AUTHORIZATION
12
- HTTP_X_CSRF_TOKEN COOKIE HTTP_COOKIE
13
- ].freeze
14
-
15
9
  private
16
10
 
17
11
  def call_app(request, env)
18
- shoud_log_request = shoud_log_request?(request)
19
- log_request(request, env) if shoud_log_request
12
+ should_log = should_log?(request)
13
+ ctx = { request: { start_time: current_time, headers: extract_request_headers(request),
14
+ body: extract_request_body(request) } }
15
+ log_request(request, env, ctx) if should_log
20
16
  handle = dispatch_request_event(request)
21
- data = process_request(env)
22
- log_response(request, env, data) if shoud_log_request
17
+ ctx[:response] = process_request(env)
18
+ log_response(request, env, ctx) if should_log
23
19
  finish_request_instrumentation(handle, env['rails.rack_logger_tag_count'])
24
- [data[:status], data[:headers], [data[:body]]]
20
+ [ctx.dig(:response, :status), ctx.dig(:response, :headers), [ctx.dig(:response, :body)]]
25
21
  end
26
22
 
27
23
  def compute_tags(request)
@@ -34,7 +30,7 @@ module MinatoLogger
34
30
  end
35
31
  end
36
32
 
37
- def shoud_log_request?(request)
33
+ def should_log?(request)
38
34
  blacklist = Rails.application.config.minato_logger.route_blacklist || []
39
35
  blacklist.none? do |item|
40
36
  next item.call(request) if item.is_a?(Proc)
@@ -44,11 +40,10 @@ module MinatoLogger
44
40
  end
45
41
 
46
42
  def process_request(env)
47
- data = { body: '', status: 500, start_time: current_time, headers: {} }
48
-
49
- data[:status], data[:headers], response = @app.call(env)
50
- data[:body] = extract_body_safely(response || [])
51
- data
43
+ res = { body: '', status: 500, headers: {} }
44
+ res[:status], res[:headers], response = @app.call(env)
45
+ res[:body] = extract_body_safely(response || [])
46
+ res
52
47
  end
53
48
 
54
49
  def dispatch_request_event(request)
@@ -58,37 +53,36 @@ module MinatoLogger
58
53
  handle
59
54
  end
60
55
 
61
- def log_request(request, env)
62
- log(default_log_data(request, env).merge({
63
- type: 'REQUEST',
64
- headers: extract_request_headers(request),
65
- body: extract_request_body(request),
66
- message: "REQUEST: #{request.method} #{request.fullpath}"
67
- }))
56
+ def log_request(request, env, ctx)
57
+ payload = { type: 'REQUEST', message: "Receiving request #{request.method} #{request.fullpath}" }
58
+ payload.merge!(default_log_data(request, env, ctx))
59
+ log(payload)
68
60
  end
69
61
 
70
- def log_response(request, env, data)
71
- data[:duration] = ((current_time - data[:start_time]) * 1000).round(2)
72
- payload = build_response_payload(request, env, data)
73
- log_level = data[:status] >= 500 ? :error : :info
62
+ def log_response(request, env, ctx)
63
+ ctx[:response][:duration] = ((current_time - ctx.dig(:request, :start_time)) * 1000).round(2)
64
+ payload = build_response_payload(request, env, ctx)
65
+ log_level = ctx.dig(:response, :status) >= 500 ? :error : :info
74
66
  log(payload, log_level)
75
67
  end
76
68
 
77
- def default_log_data(request, env)
69
+ def default_log_data(request, env, ctx)
78
70
  route = env['action_dispatch.route_uri_pattern'] || request.path
79
- { rails_version: Rails.version, request_id: request.request_id, method: request.method,
80
- time: Time.zone.now.iso8601, remote_ip: request.remote_ip, route: route, ip: request.ip,
81
- path: request.fullpath, params: filter_params(request) }
71
+ request = { id: request.request_id, method: request.method,
72
+ time: Time.zone.now.iso8601, remote_ip: request.remote_ip, route: route, ip: request.ip,
73
+ path: request.fullpath, params: filter_params(request), headers: ctx.dig(:request, :headers),
74
+ body: ctx.dig(:request, :body) }
75
+ { rails_version: Rails.version, request: request }
82
76
  end
83
77
 
84
- def build_response_payload(request, env, data)
85
- default_log_data(request, env).merge({
86
- type: 'RESPONSE', duration: data[:duration], status: data[:status],
87
- response: safe_parse_json(data[:body]),
88
- headers: filter_sensitive_headers(data[:headers]),
89
- message: "RESPONSE: #{request.method} #{request.fullpath} - " \
90
- "#{data[:status]} (#{data[:duration]}ms)"
91
- })
78
+ def build_response_payload(request, env, ctx)
79
+ response = { body: safe_parse_json(ctx.dig(:response, :body)),
80
+ headers: filter_sensitive_headers(ctx.dig(:response, :headers)),
81
+ status: ctx.dig(:response, :status), duration: ctx.dig(:response, :duration) }
82
+ payload = { type: 'RESPONSE', response: response,
83
+ message: "Responding #{request.method} #{request.fullpath} " \
84
+ "- #{ctx.dig(:response, :status)} (#{ctx.dig(:response, :duration)}ms)" }
85
+ default_log_data(request, env, ctx).merge(payload)
92
86
  end
93
87
 
94
88
  def log(payload, level = :info)
@@ -150,7 +144,7 @@ module MinatoLogger
150
144
 
151
145
  headers.reject do |k, _|
152
146
  key = k.to_s.upcase.tr('-', '_')
153
- SENSITIVE_HEADERS.any? { |sensitive| key.include?(sensitive) }
147
+ Rails.application.config.minato_logger.sensitive_headers.any? { |sensitive| key.include?(sensitive) }
154
148
  end
155
149
  end
156
150
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MinatoLogger
4
- VERSION = '0.2.14'
4
+ VERSION = '0.2.16'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minato_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferreri
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-02-13 00:00:00.000000000 Z
11
+ date: 2026-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport