minato_logger 0.4.0 → 0.5.1
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9bf719d37bf79a26579772b2753989b316b3f78866f3533298df2f3aa3088dd
|
|
4
|
+
data.tar.gz: 6339f31ad25bed2e5518e7a73a63e213fc2d3712043c075cfcd3759b0cacdf9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 647f83adf955ffb6f147759a0cd6ef3fc4be7bd523c79fdc63587eb507f6da4c3dabaf5f7624f0b636d0f2be867ea2cab2ccd353a43a75cbb7fdae8ee8ff4b0d
|
|
7
|
+
data.tar.gz: 8831bb2737316ed30688f3fbdd08c585cbc0d51618ce19a95d76c1fc928cbb1fe64f573269c18f8102f170c411ed5d7e9cca45dc085e41fb465b3deeef1f3676
|
data/.rubocop.yml
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module MinatoLogger
|
|
4
4
|
module Middlewares
|
|
5
5
|
class RequestContextEnricher
|
|
6
|
-
CONTEXT_FIELDS = %i[session_id page_url
|
|
6
|
+
CONTEXT_FIELDS = %i[session_id page_url identity_id user_agent calling_service].freeze
|
|
7
7
|
|
|
8
8
|
def call(log)
|
|
9
9
|
return log unless log.is_a?(Hash)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'base64'
|
|
3
4
|
require 'json'
|
|
4
5
|
require 'rails/rack/logger'
|
|
5
6
|
|
|
@@ -10,8 +11,13 @@ module MinatoLogger
|
|
|
10
11
|
|
|
11
12
|
def call_app(request, env)
|
|
12
13
|
hdrs = extract_request_headers(request)
|
|
13
|
-
attrs = {
|
|
14
|
-
|
|
14
|
+
attrs = {
|
|
15
|
+
session_id: hdrs['X_SESSION_ID'],
|
|
16
|
+
page_url: hdrs['X_PAGE_URL'],
|
|
17
|
+
calling_service: hdrs['X_SERVICE_NAME'],
|
|
18
|
+
identity_id: extract_identity_id(request.headers['Authorization']),
|
|
19
|
+
user_agent: request.user_agent
|
|
20
|
+
}.compact
|
|
15
21
|
MinatoLogger.with_context(attrs) { process_with_logging(request, env) }
|
|
16
22
|
end
|
|
17
23
|
|
|
@@ -29,8 +35,7 @@ module MinatoLogger
|
|
|
29
35
|
end
|
|
30
36
|
|
|
31
37
|
def compute_tags(request)
|
|
32
|
-
|
|
33
|
-
tags_to_use.collect do |tag|
|
|
38
|
+
(@taggers.presence || Rails.application.config.log_tags || []).collect do |tag|
|
|
34
39
|
next tag.call(request) if tag.is_a?(Proc)
|
|
35
40
|
next request.send(tag) if tag.is_a?(Symbol)
|
|
36
41
|
|
|
@@ -44,8 +49,7 @@ module MinatoLogger
|
|
|
44
49
|
end
|
|
45
50
|
|
|
46
51
|
def should_log?(request)
|
|
47
|
-
|
|
48
|
-
blacklist.none? do |item|
|
|
52
|
+
(Rails.application.config.minato_logger.route_blacklist || []).none? do |item|
|
|
49
53
|
next item.call(request) if item.is_a?(Proc)
|
|
50
54
|
|
|
51
55
|
request.path == item
|
|
@@ -66,9 +70,15 @@ module MinatoLogger
|
|
|
66
70
|
|
|
67
71
|
def dispatch_request_event(request)
|
|
68
72
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
payload = { request: request }
|
|
74
|
+
if instrumenter.respond_to?(:build_handle)
|
|
75
|
+
handle = instrumenter.build_handle('request.action_dispatch', payload)
|
|
76
|
+
handle.start
|
|
77
|
+
handle
|
|
78
|
+
else
|
|
79
|
+
instrumenter.start('request.action_dispatch', payload)
|
|
80
|
+
nil
|
|
81
|
+
end
|
|
72
82
|
end
|
|
73
83
|
|
|
74
84
|
def log_request(request, env, ctx)
|
|
@@ -80,14 +90,13 @@ module MinatoLogger
|
|
|
80
90
|
def log_response(request, env, ctx)
|
|
81
91
|
ctx[:response][:duration] = ((current_time - ctx.dig(:request, :start_time)) * 1000).round(2)
|
|
82
92
|
payload = build_response_payload(request, env, ctx)
|
|
83
|
-
|
|
84
|
-
log(payload, log_level)
|
|
93
|
+
log(payload, ctx.dig(:response, :status) >= 500 ? :error : :info)
|
|
85
94
|
end
|
|
86
95
|
|
|
87
96
|
def default_log_data(request, env, ctx)
|
|
88
|
-
route = env['action_dispatch.route_uri_pattern'] || request.path
|
|
89
97
|
request = { id: request.request_id, method: request.method,
|
|
90
|
-
time: Time.zone.now.iso8601, remote_ip: request.remote_ip,
|
|
98
|
+
time: Time.zone.now.iso8601, remote_ip: request.remote_ip,
|
|
99
|
+
route: env['action_dispatch.route_uri_pattern'] || request.path, ip: request.ip,
|
|
91
100
|
path: request.fullpath, params: filter_params(request), headers: ctx.dig(:request, :headers),
|
|
92
101
|
body: ctx.dig(:request, :body) }
|
|
93
102
|
{ rails_version: Rails.version, request: request }
|
|
@@ -163,10 +172,21 @@ module MinatoLogger
|
|
|
163
172
|
def filter_sensitive_headers(headers)
|
|
164
173
|
return {} unless headers.is_a?(Hash)
|
|
165
174
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
sensitive = Rails.application.config.minato_logger.sensitive_headers
|
|
176
|
+
headers.reject { |k, _| sensitive.any? { |s| k.to_s.upcase.tr('-', '_').include?(s) } }
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def extract_identity_id(auth_header)
|
|
180
|
+
return unless auth_header&.match?(/\ABearer /i)
|
|
181
|
+
|
|
182
|
+
payload_b64 = auth_header.split.last.split('.')[1]
|
|
183
|
+
return unless payload_b64
|
|
184
|
+
|
|
185
|
+
padded = payload_b64 + ('=' * (((4 - (payload_b64.length % 4)) % 4)))
|
|
186
|
+
payload = JSON.parse(Base64.urlsafe_decode64(padded))
|
|
187
|
+
payload.dig('session', 'identity', 'id')
|
|
188
|
+
rescue StandardError
|
|
189
|
+
nil
|
|
170
190
|
end
|
|
171
191
|
|
|
172
192
|
def finish_request_instrumentation(handle, payload)
|
|
@@ -174,6 +194,8 @@ module MinatoLogger
|
|
|
174
194
|
super
|
|
175
195
|
elsif handle
|
|
176
196
|
handle.finish
|
|
197
|
+
else
|
|
198
|
+
ActiveSupport::Notifications.instrumenter.finish('request.action_dispatch', {})
|
|
177
199
|
end
|
|
178
200
|
end
|
|
179
201
|
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.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ferreri
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|