researchable_loggable 1.5.1 → 1.6.0
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2005d7d174fbe9815687b94b4960961860d6b3a63ea445e01bc7cdaa8af8acfa
|
4
|
+
data.tar.gz: 9cd24968d9a82efaf1442acfeb4aa2aaf41f0634fe302c8297cccf13c2bc78fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd4baf5861bfc5acb9b0ebcbb0636691f698b51fb78b917cd00b5a39ddeafb558c9f7fd3f385b03f8d7ba6aac6af75360dbbdbd52019c1d052a4843cbaee28d5
|
7
|
+
data.tar.gz: 47b75545f83e0a1ad52a6ab80a480b369a706758b1f4844a10d0165ca04b223780bcd9f60b36430eb69fc06cedaaf612cf0782be4b1e3e4bc4c0a8e03b9e371a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [1.6.0](https://gitlab.com/researchable/general/gems/loggable/compare/v1.5.1...v1.6.0) (2025-01-15)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* **logging:** add request.id, file, and line to log payload ([f3db220](https://gitlab.com/researchable/general/gems/loggable/commit/f3db2209b6046aa6ce6ab9f0f052d9316b4508b9))
|
7
|
+
|
1
8
|
## [1.5.1](https://gitlab.com/researchable/general/gems/loggable/compare/v1.5.0...v1.5.1) (2024-12-05)
|
2
9
|
|
3
10
|
|
data/Gemfile.lock
CHANGED
@@ -24,7 +24,13 @@ module Loggable
|
|
24
24
|
# Custom formatter class that renders logs as in a key-value style using Logfmt formatting
|
25
25
|
class KeyValueFormatter < ::Logger::Formatter
|
26
26
|
def call(severity, timestamp, progname, msg)
|
27
|
-
|
27
|
+
file, line = extract_caller_info
|
28
|
+
file = relative_to_rails_root(file)
|
29
|
+
|
30
|
+
file_info = format_tag('file', file)
|
31
|
+
line_info = format_tag('line', line)
|
32
|
+
|
33
|
+
%(time=#{datetime(timestamp)} severity=#{severity.ljust(5)}#{file_info}#{line_info}#{progname(progname)} #{message(msg)}\n) # rubocop:disable Layout/LineLength
|
28
34
|
end
|
29
35
|
|
30
36
|
private
|
@@ -80,6 +86,47 @@ module Loggable
|
|
80
86
|
value
|
81
87
|
end
|
82
88
|
end
|
89
|
+
|
90
|
+
# Extracts caller information (file and line number) for the log message
|
91
|
+
def extract_caller_info
|
92
|
+
caller_locations.each do |loc|
|
93
|
+
# Skip frames that are part of internal or irrelevant paths (gems, vendor, etc.)
|
94
|
+
next if internal_frame?(loc.path)
|
95
|
+
|
96
|
+
# Return the first relevant application-level frame
|
97
|
+
return [loc.path, loc.lineno]
|
98
|
+
end
|
99
|
+
|
100
|
+
# Fallback if no relevant frame is found
|
101
|
+
%w[unknown unknown]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Determines if a given file path corresponds to an internal or excluded frame
|
105
|
+
def internal_frame?(path)
|
106
|
+
excluded_patterns = %w[
|
107
|
+
/gems/
|
108
|
+
/vendor/
|
109
|
+
<internal:kernel>
|
110
|
+
loggable
|
111
|
+
].freeze
|
112
|
+
|
113
|
+
excluded_patterns.any? { |pattern| path.include?(pattern) }
|
114
|
+
end
|
115
|
+
|
116
|
+
# Converts an absolute file path to a path relative to Rails.root
|
117
|
+
# If the path is outside of Rails.root, it returns the original path
|
118
|
+
def relative_to_rails_root(path)
|
119
|
+
rails_root = defined?(Rails) ? Rails.root.to_s : ''
|
120
|
+
path.start_with?(rails_root) ? path.sub(%r{^#{rails_root}/}, '') : path
|
121
|
+
end
|
122
|
+
|
123
|
+
# Formats a key-value tag for log output
|
124
|
+
# If the value is 'unknown', it returns an empty string to omit the tag
|
125
|
+
def format_tag(key, value)
|
126
|
+
return '' if value == 'unknown'
|
127
|
+
|
128
|
+
" #{key}=#{value}"
|
129
|
+
end
|
83
130
|
end
|
84
131
|
end
|
85
132
|
end
|
data/lib/loggable/railtie.rb
CHANGED
@@ -37,9 +37,15 @@ module Loggable
|
|
37
37
|
user_id = controller.send(config.loggable.current_user_method).try(:id)
|
38
38
|
end
|
39
39
|
|
40
|
+
# Look for the request ID in headers
|
41
|
+
request_id = controller.request.headers['X-Request-ID'] || # Check for a custom request ID header
|
42
|
+
controller.request.headers['traceparent'] || # Check for the W3C Trace Context header
|
43
|
+
controller.request.env['HTTP_X_REQUEST_ID'] # Fallback to Rack's normalized header
|
44
|
+
|
40
45
|
{
|
41
46
|
'source.ip': controller.request.ip,
|
42
47
|
'user.id': user_id,
|
48
|
+
'request.id': request_id,
|
43
49
|
status: response_code,
|
44
50
|
span_id: OpenTelemetry::Trace.current_span.context.hex_span_id,
|
45
51
|
trace_id: OpenTelemetry::Trace.current_span.context.hex_trace_id
|
data/lib/loggable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: researchable_loggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Researchable
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lograge
|
@@ -109,13 +109,13 @@ files:
|
|
109
109
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/prerelease/lib/test-gem/version.rb
|
110
110
|
- node_modules/semantic-release-rubygem/src/__tests__/fixtures/valid/lib/test-gem/version.rb
|
111
111
|
- sig/loggable.rbs
|
112
|
-
homepage: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.
|
112
|
+
homepage: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.6.0/README.md
|
113
113
|
licenses:
|
114
114
|
- MIT
|
115
115
|
metadata:
|
116
|
-
homepage_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.
|
116
|
+
homepage_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.6.0/README.md
|
117
117
|
source_code_uri: https://gitlab.com/researchable/general/gems/loggable
|
118
|
-
changelog_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.
|
118
|
+
changelog_uri: https://gitlab.com/researchable/general/gems/loggable/-/blob/v1.6.0/CHANGELOG.md
|
119
119
|
post_install_message:
|
120
120
|
rdoc_options: []
|
121
121
|
require_paths:
|