[Logger] Add structured log context filtering - #386
Open
RedZapdos123 wants to merge 2 commits into
Open
Conversation
Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Issue #370 asked for a built-in way to filter sensitive values from Rage's structured log context.
This PR adds
config.filter_parameters, which applies Rails-style case-insensitive partial matching to structured context keys and replaces matching values with[FILTERED]before the log entry is written.The implementation stays inside Rage's own logger code and applies consistently to
with_context, inline logger context, request log context added throughappend_info_to_payload, globalconfig.log_context, and dynamic external loggercontextpayloads.As discussed in the issue, this PR only filters structured
context. It does not changerequest_info.It also adds regression specs for logger filtering, configuration wiring, nested structured context, and the unchanged
request_infobehavior for dynamic external loggers.Closes #370.
Checklist:
bundle exec rubocop lib/rage/logger/logger.rb lib/rage/configuration.rb spec/logger_spec.rb spec/configuration_spec.rb.bundle exec rspec spec/logger_spec.rb spec/configuration_spec.rb.bundle exec ruby -c lib/rage/logger/logger.rb && bundle exec ruby -c lib/rage/configuration.rb.Before the fix:
Sensitive keys in structured log context were written as-is.
Rage did not have a built-in filtering mechanism for
with_context, inline logger context, or request log context merged throughappend_info_to_payload.Example:
After the fix:
config.filter_parametersfilters matching structured context keys before log emission.Matching is case-insensitive and partial, so keys like
password_confirmationandAUTH_TOKENare filtered.Nested hashes and arrays are filtered recursively.
Dynamic external loggers receive filtered
contextand unchangedrequest_info.Example: