lorekeeper 2.5.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +9 -1
- data/lib/lorekeeper/backtrace_cleaner.rb +63 -0
- data/lib/lorekeeper/json_logger.rb +1 -43
- data/lib/lorekeeper/version.rb +1 -1
- data/lib/lorekeeper.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6d72806736892898e7cd27786d25a37e4569f8e7f1562b3097ddb614324cf1a
|
4
|
+
data.tar.gz: 1102556da650a22b1b30b177150a2d64a4eaa9d7d05697eaf3498db0af2a6915
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a430d1ce3d1865df5223c9790c0129464eb88a20b9872d689a6b6180a9c7bc89594d07950e8ad0eac4c9834a97cb144c7f0a1e43d9dd635bd7c8d0a2e3dad016
|
7
|
+
data.tar.gz: f8793ed6d04b6ce8ec649b3feebd843e57eafef32eadf0c56e94a0ec310455c81a75119ab1176e86536ead7439adc6f684164ed36762d9edaef5c3d89ef7f66c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 2.6.1
|
2
|
+
* Fix Lorekeeper::BacktraceCleaner#clean to not raise when a non-array value is passed
|
3
|
+
|
4
|
+
# 2.6.0
|
5
|
+
* Expose Lorekeeper::BacktraceCleaner
|
6
|
+
|
1
7
|
# 2.5.0
|
2
8
|
* Update the backtrace cleaner in JSONLogger to remove web server and stdlib lines, and to strip the Rails.root prefix
|
3
9
|
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ When used without extra fields it outputs 20% faster than the standard Logger fo
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem 'lorekeeper', '~>
|
13
|
+
gem 'lorekeeper', '~> 2.0'
|
14
14
|
```
|
15
15
|
|
16
16
|
And then execute:
|
@@ -210,6 +210,14 @@ end
|
|
210
210
|
```
|
211
211
|
|
212
212
|
|
213
|
+
### Backtrace Cleaner
|
214
|
+
|
215
|
+
The backtrace cleaner can be used independently:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
Lorekeeper::BacktraceCleaner.instance.clean(backtrace)
|
219
|
+
```
|
220
|
+
|
213
221
|
|
214
222
|
## License
|
215
223
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module Lorekeeper
|
6
|
+
class BacktraceCleaner
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@backtrace_cleaner = set_backtrace_cleaner
|
11
|
+
@rails_root = defined?(Rails.root) ? Rails.root.to_s : nil
|
12
|
+
@rails_root_size = @rails_root.to_s.size
|
13
|
+
@gem_path = defined?(Gem.path) ? Gem.path : []
|
14
|
+
@denylisted_fingerprint = denylisted_fingerprint
|
15
|
+
end
|
16
|
+
|
17
|
+
def clean(backtrace)
|
18
|
+
return [] unless backtrace.is_a?(Array)
|
19
|
+
|
20
|
+
backtrace = filter_rails_root_backtrace(backtrace)
|
21
|
+
@backtrace_cleaner&.clean(backtrace) || backtrace
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
DENYLISTED_FINGERPRINT =
|
27
|
+
%r{newrelic_rpm|active_support/callbacks.rb|zipkin-tracer|puma|phusion_passenger|opentelemetry}.freeze
|
28
|
+
|
29
|
+
def denylisted_fingerprint
|
30
|
+
return DENYLISTED_FINGERPRINT unless ENV.key?('LOREKEEPER_DENYLIST')
|
31
|
+
|
32
|
+
/#{ENV.fetch('LOREKEEPER_DENYLIST').split(',').map(&:strip).join('|')}/
|
33
|
+
end
|
34
|
+
|
35
|
+
def filter_rails_root_backtrace(backtrace)
|
36
|
+
return backtrace unless @rails_root
|
37
|
+
|
38
|
+
last_index = nil
|
39
|
+
result = []
|
40
|
+
backtrace.each_with_index do |line, idx|
|
41
|
+
if line.start_with?(@rails_root) && @gem_path.none? { |path| line.start_with?(path) }
|
42
|
+
result << line[@rails_root_size..]
|
43
|
+
last_index = idx
|
44
|
+
else
|
45
|
+
result << line
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
last_index ? result[..last_index] : result
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_backtrace_cleaner
|
53
|
+
return nil unless defined?(ActiveSupport::BacktraceCleaner)
|
54
|
+
|
55
|
+
cleaner = ActiveSupport::BacktraceCleaner.new
|
56
|
+
cleaner.remove_silencers!
|
57
|
+
cleaner.add_silencer do |line|
|
58
|
+
line.match?(@denylisted_fingerprint) || line.start_with?(RbConfig::CONFIG['rubylibdir'])
|
59
|
+
end
|
60
|
+
cleaner
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -9,11 +9,6 @@ module Lorekeeper
|
|
9
9
|
def initialize(file)
|
10
10
|
reset_state
|
11
11
|
@base_fields = { TIMESTAMP => '', MESSAGE => '', LEVEL => '' }
|
12
|
-
@backtrace_cleaner = set_backtrace_cleaner
|
13
|
-
@rails_root = defined?(Rails.root) ? Rails.root.to_s : nil
|
14
|
-
@rails_root_size = @rails_root.to_s.size
|
15
|
-
@gem_path = defined?(Gem.path) ? Gem.path : []
|
16
|
-
@denylisted_fingerprint = denylisted_fingerprint
|
17
12
|
|
18
13
|
super(file)
|
19
14
|
end
|
@@ -121,36 +116,7 @@ module Lorekeeper
|
|
121
116
|
# Cleaner defaults to newrelic, active_support/callbacks, zipkin-tracer, opentelemetry, web servers,
|
122
117
|
# and stdlib now but can be configured by using LOREKEEPER_DENYLIST env var.
|
123
118
|
def clean_backtrace(backtrace)
|
124
|
-
|
125
|
-
@backtrace_cleaner&.clean(backtrace) || backtrace
|
126
|
-
end
|
127
|
-
|
128
|
-
def filter_rails_root_backtrace(backtrace)
|
129
|
-
return backtrace unless @rails_root
|
130
|
-
|
131
|
-
last_index = nil
|
132
|
-
result = []
|
133
|
-
backtrace.each_with_index do |line, idx|
|
134
|
-
if line.start_with?(@rails_root) && @gem_path.none? { |path| line.start_with?(path) }
|
135
|
-
result << line[@rails_root_size..]
|
136
|
-
last_index = idx
|
137
|
-
else
|
138
|
-
result << line
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
last_index ? result[..last_index] : result
|
143
|
-
end
|
144
|
-
|
145
|
-
def set_backtrace_cleaner
|
146
|
-
return nil unless defined?(ActiveSupport::BacktraceCleaner)
|
147
|
-
|
148
|
-
cleaner = ActiveSupport::BacktraceCleaner.new
|
149
|
-
cleaner.remove_silencers!
|
150
|
-
cleaner.add_silencer do |line|
|
151
|
-
line.match?(@denylisted_fingerprint) || line.start_with?(RbConfig::CONFIG['rubylibdir'])
|
152
|
-
end
|
153
|
-
cleaner
|
119
|
+
Lorekeeper::BacktraceCleaner.instance.clean(backtrace)
|
154
120
|
end
|
155
121
|
|
156
122
|
THREAD_KEY = 'lorekeeper_jsonlogger_key' # Shared by all threads but unique by thread
|
@@ -161,14 +127,6 @@ module Lorekeeper
|
|
161
127
|
EXCEPTION = 'exception'
|
162
128
|
STACK = 'stack'
|
163
129
|
DATA = 'data'
|
164
|
-
DENYLISTED_FINGERPRINT =
|
165
|
-
%r{newrelic_rpm|active_support/callbacks.rb|zipkin-tracer|puma|phusion_passenger|opentelemetry}.freeze
|
166
|
-
|
167
|
-
def denylisted_fingerprint
|
168
|
-
return DENYLISTED_FINGERPRINT unless ENV.key?('LOREKEEPER_DENYLIST')
|
169
|
-
|
170
|
-
/#{ENV.fetch('LOREKEEPER_DENYLIST').split(',').map(&:strip).join('|')}/
|
171
|
-
end
|
172
130
|
|
173
131
|
def with_extra_fields(fields)
|
174
132
|
state[:extra_fields] = fields
|
data/lib/lorekeeper/version.rb
CHANGED
data/lib/lorekeeper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lorekeeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordi Polo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- bin/console
|
224
224
|
- bin/setup
|
225
225
|
- lib/lorekeeper.rb
|
226
|
+
- lib/lorekeeper/backtrace_cleaner.rb
|
226
227
|
- lib/lorekeeper/fast_logger.rb
|
227
228
|
- lib/lorekeeper/json_logger.rb
|
228
229
|
- lib/lorekeeper/multi_logger.rb
|