minato_logger 0.4.0 → 0.5.0
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: 33395b0697e82cb51f13e678fd28bb6544ad52eab50f347b5d3067f27fb8af75
|
|
4
|
+
data.tar.gz: bb623b01437a87f6fff02dd2b806efbf13fcd06c8e419593ce2168cf2afd8919
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5bafc0f8acc6c35a31f87a3c745202bdf731c395b6f3906a37202e27af66f4de20bd022d8e703e09b49a01e85c0a4542f593880d47a281e650f548546e5c7c7e
|
|
7
|
+
data.tar.gz: 3c569ff3dcfec30885b7ef807ebd9b1c76a4b9b3c34a322b2ed037d424d3c2a33e1e10a45f6ad4f7866c940c01cfa85aa5cb67ac70c254d1bb4e7ab48b4bcb35
|
|
@@ -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
|
|
@@ -80,14 +84,13 @@ module MinatoLogger
|
|
|
80
84
|
def log_response(request, env, ctx)
|
|
81
85
|
ctx[:response][:duration] = ((current_time - ctx.dig(:request, :start_time)) * 1000).round(2)
|
|
82
86
|
payload = build_response_payload(request, env, ctx)
|
|
83
|
-
|
|
84
|
-
log(payload, log_level)
|
|
87
|
+
log(payload, ctx.dig(:response, :status) >= 500 ? :error : :info)
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
def default_log_data(request, env, ctx)
|
|
88
|
-
route = env['action_dispatch.route_uri_pattern'] || request.path
|
|
89
91
|
request = { id: request.request_id, method: request.method,
|
|
90
|
-
time: Time.zone.now.iso8601, remote_ip: request.remote_ip,
|
|
92
|
+
time: Time.zone.now.iso8601, remote_ip: request.remote_ip,
|
|
93
|
+
route: env['action_dispatch.route_uri_pattern'] || request.path, ip: request.ip,
|
|
91
94
|
path: request.fullpath, params: filter_params(request), headers: ctx.dig(:request, :headers),
|
|
92
95
|
body: ctx.dig(:request, :body) }
|
|
93
96
|
{ rails_version: Rails.version, request: request }
|
|
@@ -163,10 +166,21 @@ module MinatoLogger
|
|
|
163
166
|
def filter_sensitive_headers(headers)
|
|
164
167
|
return {} unless headers.is_a?(Hash)
|
|
165
168
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
sensitive = Rails.application.config.minato_logger.sensitive_headers
|
|
170
|
+
headers.reject { |k, _| sensitive.any? { |s| k.to_s.upcase.tr('-', '_').include?(s) } }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def extract_identity_id(auth_header)
|
|
174
|
+
return unless auth_header&.match?(/\ABearer /i)
|
|
175
|
+
|
|
176
|
+
payload_b64 = auth_header.split.last.split('.')[1]
|
|
177
|
+
return unless payload_b64
|
|
178
|
+
|
|
179
|
+
padded = payload_b64 + ('=' * (((4 - (payload_b64.length % 4)) % 4)))
|
|
180
|
+
payload = JSON.parse(Base64.urlsafe_decode64(padded))
|
|
181
|
+
payload.dig('session', 'identity', 'id')
|
|
182
|
+
rescue StandardError
|
|
183
|
+
nil
|
|
170
184
|
end
|
|
171
185
|
|
|
172
186
|
def finish_request_instrumentation(handle, payload)
|
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.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ferreri
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|