Repository navigation
fix(logger): match suppressed loggers by hierarchy - #8835
Open
roonakyadav wants to merge 1 commit into
Open
roonakyadav wants to merge 1 commit into
roonakyadav wants to merge 1 commit into
Conversation
SuppressFilter matched loggers via substring (`self.logger not in record.name`),
which unintentionally suppressed unrelated third-party loggers whose names
contained the service name (e.g. `botocore` when service was `core`).
Change the matching logic to match either the exact logger name or child
loggers prefixed with `{self.logger}.`. Add functional regression tests.
Closes aws-powertools#8821
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
This branch has not been deployed
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.



Closes #8821
Summary
Changes
aws_lambda_powertools/logging/filters.py, updateSuppressFilter.filter()to match the exact logger name or child loggers prefixed with{self.logger}., rather than checking substring membership (self.logger not in logger).tests/functional/logger/required_dependencies/test_logger.py, add functional testtest_suppress_filter_does_not_suppress_unrelated_logger_containing_service_namevalidating that unrelated loggers containing the service name (e.g.botocorewhen service iscore) are not suppressed, while genuine child loggers remain suppressed from root handlers.Root cause
SuppressFilter.filter()checkedself.logger not in record.name. When a Powertools logger was initialized withservice="core", this substring test matched any third-party logger whose name contained"core"(such asbotocore). As a result,botocorerecords propagating to the runtime root handler were unintentionally dropped from CloudWatch logs.User experience
Logger(service="core")caused unrelated loggers containing"core"(likebotocorewarnings) to be swallowed and never reach the Lambda root handler.record.name == "core") or its children (record.name.startswith("core.")) are suppressed from the root handler. Unrelated loggers likebotocoreare preserved and emitted as expected.Verification
I used an AI assistant to prepare this fix and ran all validations locally:
developwherebotocorewarnings were suppressed (AssertionError: botocore was unexpectedly suppressed!).uv run pytest tests/functional/logger/required_dependencies/test_logger.py -k test_suppress_filter_does_not_suppress_unrelated_logger_containing_service_name -v->
1 passed, 89 deselected in 0.11suv run pytest tests/functional/logger/ tests/unit/logger/->
205 passed, 7 warnings in 0.72smake lint(ruff format + ruff check) ->1417 files left unchanged,All checks passed!make mypy->Success: no issues found in 963 source filesgit diff --check-> Clean, 0 errors.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.