koderift-rails 2.1.0 → 2.1.1

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: b77962b847bf6127f3029ab4cab2eb3f71ae3cf0d0041c6d2df6ad1108449c7e
4
- data.tar.gz: cc0a1ab9373ca3544bf3d9b48bf08ea1afa269236d4385e9873a139ea258fb0f
3
+ metadata.gz: 41b72b93e0b7252313779b2cdaab30897ae9929b00e12fcc2b7d4f308fa655df
4
+ data.tar.gz: 5e25c8a220e8aba44ea3f9a623da6f646e3e7564e1c4a44be6583549a51c4156
5
5
  SHA512:
6
- metadata.gz: 274e3e08f2d325ef30063547658668b955eb32607c6705829c5de531b8ac40d63701d199a3fffb9d537f3298a29816dd491ba897a0ec93dc0237eebaa2964b24
7
- data.tar.gz: d409cd77d3f77b28d86fb526ddff9b096314b8b12e4af3e1e687b281a98d811fabcb775b164eed5a785433ee6455697faabd1a25c3cb5953a8c8fadd3ccb1425
6
+ metadata.gz: 488980d844b621356cd3b2b13519f763f8d66970cb1c5be3ee95127b61a80cbb6cade2f601682146d7d090d3bcfc89447f67eb57de375595c00fc3a9ff029d8c
7
+ data.tar.gz: bbc7c57849bf2f59a1b47b2568afd990ce64c5f210f41423d5a50a5a274a25ef119ed014841529c13e39ce9c4701f09bc714cfebd58d13caeb5557f7a1a4b38e
data/CHANGELOG.md CHANGED
@@ -6,6 +6,29 @@ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
  Releases before 1.3.4 were installed from git and were never published to
7
7
  RubyGems; they are listed for continuity.
8
8
 
9
+ ## [2.1.1] - 2026-11-12
10
+
11
+ Fixes missing request data in apps where another gem defines `Object#logger`.
12
+
13
+ ### Fixed
14
+ - Request data no longer goes missing when another gem defines a public
15
+ `logger` method on every object. data-anonymization does this when it
16
+ is loaded at boot. That method shadowed `config.lograge.logger`, so lograge
17
+ took the other gem's logger. The Koderift JSON request line went to STDOUT
18
+ instead of the log the agent tails, and nothing warned. At boot the gem now
19
+ points lograge back at what your app configured (`Rails.logger`, unless you
20
+ set `config.lograge.logger`), and logs one warning naming the module and file
21
+ that define the method.
22
+
23
+ ### Notes
24
+ - The same method usually redirects `ActionController::Base.logger`,
25
+ `ActiveRecord::Base.logger` and Rails' own "Processing by", "Completed" and
26
+ SQL lines too. Koderift does not change those. Fix them by not loading that
27
+ gem at boot, for example `gem 'data-anonymization', require: false`.
28
+ - If that gem also defines `logger=` (data-anonymization does), a
29
+ `config.lograge.logger` you set was handed to the gem and never reached
30
+ lograge, so lograge now uses `Rails.logger`.
31
+
9
32
  ## [2.1.0] - 2026-11-06
10
33
 
11
34
  Security fix: the Browser RUM meta tag no longer publishes your project token.
@@ -45,6 +45,66 @@ module Koderift
45
45
  end
46
46
  end
47
47
 
48
+ # Some gems give every object a public `logger` method, usually through a
49
+ # top-level `include` of a module that defines one. data-anonymization
50
+ # 0.9.1 does this, and its logger writes to STDOUT. OrderedOptions reads
51
+ # its keys through method_missing, so a real method always wins, and
52
+ # `config.lograge.logger` returns that gem's logger whether or not the app
53
+ # set one. Lograge.setup copies it into Lograge.logger, and the JSON
54
+ # request line goes wherever it writes instead of to the log the agent
55
+ # tails. Nothing else warns.
56
+ #
57
+ # Called after Lograge.setup. Points Lograge.logger back at the value the
58
+ # app stored in config.lograge.logger. When the app stored none, that is
59
+ # nil, and lograge falls back to Rails.logger as it normally would. Does
60
+ # nothing unless a real method shadows the key and Lograge.logger holds
61
+ # something other than the stored value.
62
+ def self.release_hijacked_logger(app)
63
+ return unless defined?(Lograge)
64
+
65
+ options = app.config.lograge
66
+ hijacker = shadowing_logger_method(options)
67
+ return if hijacker.nil?
68
+
69
+ configured = options[:logger]
70
+ return if Lograge.logger.equal?(configured)
71
+
72
+ Lograge.logger = configured
73
+ log_warning(hijacked_logger_warning(hijacker, configured))
74
+ end
75
+
76
+ def self.shadowing_logger_method(options)
77
+ return nil unless options.is_a?(ActiveSupport::OrderedOptions)
78
+ return nil unless options.class.public_method_defined?(:logger)
79
+
80
+ options.class.instance_method(:logger)
81
+ end
82
+
83
+ def self.hijacked_logger_warning(hijacker, configured)
84
+ owner = hijacker.owner.name || hijacker.owner.inspect
85
+ location = hijacker.source_location&.join(':')
86
+ source = location ? "#{owner} (#{location})" : owner
87
+ target = configured.nil? ? 'Rails.logger' : 'the logger set in config.lograge.logger'
88
+
89
+ "[Koderift] #{source} defines a public `logger` method on every object. " \
90
+ 'ActiveSupport::OrderedOptions lets that method shadow its own keys, so ' \
91
+ 'config.lograge.logger returned that logger, and Koderift JSON request ' \
92
+ 'lines went to it instead of the log the Koderift agent tails. Koderift ' \
93
+ "has pointed lograge back at #{target}. ActionController::Base.logger, " \
94
+ "ActiveRecord::Base.logger and Rails' own request lines (Processing by, " \
95
+ 'Completed, SQL) are probably redirected to that logger too, and Koderift ' \
96
+ 'does not change those. Stop the gem that defines it from loading at ' \
97
+ 'boot, for example with `require: false` in the Gemfile.'
98
+ end
99
+
100
+ def self.log_warning(message)
101
+ return unless defined?(::Rails) && ::Rails.respond_to?(:logger)
102
+
103
+ ::Rails.logger&.warn(message)
104
+ rescue StandardError
105
+ nil
106
+ end
107
+
48
108
  def self.format_backtrace(exception)
49
109
  format_frames(exception&.backtrace)
50
110
  end
@@ -12,6 +12,14 @@ module Koderift
12
12
 
13
13
  require 'koderift/rails/lograge_config'
14
14
  Koderift::Rails::LogrageConfig.apply(app)
15
+
16
+ # Lograge.setup runs in lograge's own after_initialize hook, which is
17
+ # registered when lograge is first required. That has happened by now,
18
+ # because lograge_config requires it. Hooks run in registration order,
19
+ # so registering this one here makes it run after Lograge.setup.
20
+ app.config.after_initialize do |application|
21
+ Koderift::Rails::LogrageConfig.release_hijacked_logger(application)
22
+ end
15
23
  end
16
24
 
17
25
  # Include the controller concern into ActionController::Base
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Koderift
4
4
  module Rails
5
- VERSION = '2.1.0'
5
+ VERSION = '2.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koderift-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koderift