lorekeeper 2.5.0 → 2.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: b28b160e67e8d9321eebfb99ba3ade77f7409633ae3977b43abe5cdcdf62cb15
4
- data.tar.gz: d2446915f9a3dd36ce5051316557816b884b33ea7ebbb3a3eeac8cb96ce528fc
3
+ metadata.gz: 9b1a026f727609772af1e77fb5423768e621b9db70c7efef8baa1b49cdb9642e
4
+ data.tar.gz: 7b966039ef152e8ec18256f4c76cda69bc221ec52d9e67fd11013f733a8eb60a
5
5
  SHA512:
6
- metadata.gz: 23d9b597ad2cc8cd4a5bc411f63a70f30930c066289aa17258319ddb8e9fdd68f092d8706ace0f5ce468e4ebfe4c8037b67007cb7e3accdf4489f11c6647dc11
7
- data.tar.gz: 482721d054b7631906058eacf6c07db16235964ab7cf658e49ba92e8ed979beb05223240284d72267fe694aec6e66a576769bb862bfeba9d9f8ccf834e8d8187
6
+ metadata.gz: aa4a33eccd5e1494b4c667f2566dfd34c4720a6fece96a8ecdb215d5c77da195c45640fb349979c7e21cc3e2cc2a31eb6c31f75533932a794fda4e915af9bee5
7
+ data.tar.gz: e204ea9b3158aa7ee5d8315a8b4068555a7913fe6ef36ec24b0fdabf5b4e64dabad9e5518c1193f1383345888332504495d3edd481fa3e097b76d455f599fe1d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 2.6.0
2
+ * Expose Lorekeeper::BacktraceCleaner
3
+
1
4
  # 2.5.0
2
5
  * Update the backtrace cleaner in JSONLogger to remove web server and stdlib lines, and to strip the Rails.root prefix
3
6
 
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', '~> 1.7'
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,61 @@
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
+ backtrace = filter_rails_root_backtrace(backtrace)
19
+ @backtrace_cleaner&.clean(backtrace) || backtrace
20
+ end
21
+
22
+ private
23
+
24
+ DENYLISTED_FINGERPRINT =
25
+ %r{newrelic_rpm|active_support/callbacks.rb|zipkin-tracer|puma|phusion_passenger|opentelemetry}.freeze
26
+
27
+ def denylisted_fingerprint
28
+ return DENYLISTED_FINGERPRINT unless ENV.key?('LOREKEEPER_DENYLIST')
29
+
30
+ /#{ENV.fetch('LOREKEEPER_DENYLIST').split(',').map(&:strip).join('|')}/
31
+ end
32
+
33
+ def filter_rails_root_backtrace(backtrace)
34
+ return backtrace unless @rails_root
35
+
36
+ last_index = nil
37
+ result = []
38
+ backtrace.each_with_index do |line, idx|
39
+ if line.start_with?(@rails_root) && @gem_path.none? { |path| line.start_with?(path) }
40
+ result << line[@rails_root_size..]
41
+ last_index = idx
42
+ else
43
+ result << line
44
+ end
45
+ end
46
+
47
+ last_index ? result[..last_index] : result
48
+ end
49
+
50
+ def set_backtrace_cleaner
51
+ return nil unless defined?(ActiveSupport::BacktraceCleaner)
52
+
53
+ cleaner = ActiveSupport::BacktraceCleaner.new
54
+ cleaner.remove_silencers!
55
+ cleaner.add_silencer do |line|
56
+ line.match?(@denylisted_fingerprint) || line.start_with?(RbConfig::CONFIG['rubylibdir'])
57
+ end
58
+ cleaner
59
+ end
60
+ end
61
+ 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
- backtrace = filter_rails_root_backtrace(backtrace)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lorekeeper
4
- VERSION = '2.5.0'
4
+ VERSION = '2.6.0'
5
5
  end
data/lib/lorekeeper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'lorekeeper/version'
4
+ require 'lorekeeper/backtrace_cleaner'
4
5
  require 'lorekeeper/fast_logger'
5
6
  require 'lorekeeper/simple_logger'
6
7
  require 'lorekeeper/json_logger'
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.5.0
4
+ version: 2.6.0
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-03 00:00:00.000000000 Z
11
+ date: 2023-05-04 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