lorekeeper 2.4.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: 8099634bb3a3f3d4d348737b0c9634a3a70743c1d868ebec42c194865df7a13c
4
- data.tar.gz: c216efb9f7f6c2e06c357aee59d1f0ad8299445c5becc0d8fc4f2d444e5193ec
3
+ metadata.gz: 9b1a026f727609772af1e77fb5423768e621b9db70c7efef8baa1b49cdb9642e
4
+ data.tar.gz: 7b966039ef152e8ec18256f4c76cda69bc221ec52d9e67fd11013f733a8eb60a
5
5
  SHA512:
6
- metadata.gz: 93af9f7d3142bdc8166a14e2324b71fe3e51c3f150ea2fccee8557fc2d17b92517b3d6214e8021ed86bdbf632bed836b12027bf438f4bba0099ef1bbaed32e63
7
- data.tar.gz: d81128b6905c1f70e7946bf7be63bf35923d40056d9c9ab7274397b7ff8726da582109f83c0c2905768c0c694ac48c2fa8574dd894f10a0b60d6c3b0ac28dfbb
6
+ metadata.gz: aa4a33eccd5e1494b4c667f2566dfd34c4720a6fece96a8ecdb215d5c77da195c45640fb349979c7e21cc3e2cc2a31eb6c31f75533932a794fda4e915af9bee5
7
+ data.tar.gz: e204ea9b3158aa7ee5d8315a8b4068555a7913fe6ef36ec24b0fdabf5b4e64dabad9e5518c1193f1383345888332504495d3edd481fa3e097b76d455f599fe1d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.6.0
2
+ * Expose Lorekeeper::BacktraceCleaner
3
+
4
+ # 2.5.0
5
+ * Update the backtrace cleaner in JSONLogger to remove web server and stdlib lines, and to strip the Rails.root prefix
6
+
1
7
  # 2.4.0
2
8
  * Add `#with_level` method support added to the stdlib's Logger in [#85](https://github.com/ruby/logger/issues/85)
3
9
  * Support symbol log level setting
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:
@@ -20,6 +20,15 @@ bundle
20
20
  ```
21
21
 
22
22
 
23
+ ## Configuration
24
+
25
+ Configuration is set through environment variables.
26
+
27
+ - `LOREKEEPER_DENYLIST`
28
+ - A comma separated list of keywords/phrases that will be excluded from the clean backtrace.
29
+ - default: `newrelic_rpm, active_support/callbacks.rb, zipkin-tracer, puma, phusion_passenger, opentelemetry`
30
+
31
+
23
32
  ## Usage
24
33
 
25
34
  ### Normal logging methods
@@ -201,6 +210,14 @@ end
201
210
  ```
202
211
 
203
212
 
213
+ ### Backtrace Cleaner
214
+
215
+ The backtrace cleaner can be used independently:
216
+
217
+ ```ruby
218
+ Lorekeeper::BacktraceCleaner.instance.clean(backtrace)
219
+ ```
220
+
204
221
 
205
222
  ## License
206
223
 
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
@@ -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,7 +9,7 @@ module Lorekeeper
9
9
  def initialize(file)
10
10
  reset_state
11
11
  @base_fields = { TIMESTAMP => '', MESSAGE => '', LEVEL => '' }
12
- @backtrace_cleaner = set_backtrace_cleaner
12
+
13
13
  super(file)
14
14
  end
15
15
 
@@ -113,19 +113,10 @@ module Lorekeeper
113
113
 
114
114
  # Some instrumentation libraries pollute the stacktrace and create a large output which may
115
115
  # cause problems with certain logging backends.
116
- # Hardcording newrelic, active_support/callbacks and zipkin-tracer now here.
117
- # In the future if this list grows, we may make it configurable.
116
+ # Cleaner defaults to newrelic, active_support/callbacks, zipkin-tracer, opentelemetry, web servers,
117
+ # and stdlib now but can be configured by using LOREKEEPER_DENYLIST env var.
118
118
  def clean_backtrace(backtrace)
119
- @backtrace_cleaner&.clean(backtrace) || backtrace
120
- end
121
-
122
- def set_backtrace_cleaner
123
- return nil unless defined?(ActiveSupport::BacktraceCleaner)
124
-
125
- cleaner = ActiveSupport::BacktraceCleaner.new
126
- cleaner.remove_silencers!
127
- cleaner.add_silencer { |line| line.match?(BLACKLISTED_FINGERPRINT) }
128
- cleaner
119
+ Lorekeeper::BacktraceCleaner.instance.clean(backtrace)
129
120
  end
130
121
 
131
122
  THREAD_KEY = 'lorekeeper_jsonlogger_key' # Shared by all threads but unique by thread
@@ -136,7 +127,6 @@ module Lorekeeper
136
127
  EXCEPTION = 'exception'
137
128
  STACK = 'stack'
138
129
  DATA = 'data'
139
- BLACKLISTED_FINGERPRINT = %r{newrelic_rpm|active_support/callbacks.rb|zipkin-tracer}.freeze
140
130
 
141
131
  def with_extra_fields(fields)
142
132
  state[:extra_fields] = fields
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lorekeeper
4
- VERSION = '2.4.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.4.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordi Polo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-06 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
@@ -233,7 +234,7 @@ homepage: https://github.com/JordiPolo/lorekeeper
233
234
  licenses:
234
235
  - MIT
235
236
  metadata: {}
236
- post_install_message:
237
+ post_install_message:
237
238
  rdoc_options: []
238
239
  require_paths:
239
240
  - lib
@@ -248,8 +249,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
248
249
  - !ruby/object:Gem::Version
249
250
  version: '0'
250
251
  requirements: []
251
- rubygems_version: 3.0.3.1
252
- signing_key:
252
+ rubygems_version: 3.2.15
253
+ signing_key:
253
254
  specification_version: 4
254
255
  summary: Very fast JSON logger
255
256
  test_files: []