Skip to content

fix(logger): match suppressed loggers by hierarchy - #8835

Open
roonakyadav wants to merge 1 commit into
aws-powertools:developfrom
roonakyadav:fix/8821-suppress-filter-logger-hierarchy
Open

roonakyadav wants to merge 1 commit into
aws-powertools:developfrom
roonakyadav:fix/8821-suppress-filter-logger-hierarchy

Conversation

@roonakyadav

Copy link
Copy Markdown

Closes #8821

Summary

Changes

  • In aws_lambda_powertools/logging/filters.py, update SuppressFilter.filter() to match the exact logger name or child loggers prefixed with {self.logger}., rather than checking substring membership (self.logger not in logger).
  • In tests/functional/logger/required_dependencies/test_logger.py, add functional test test_suppress_filter_does_not_suppress_unrelated_logger_containing_service_name validating that unrelated loggers containing the service name (e.g. botocore when service is core) are not suppressed, while genuine child loggers remain suppressed from root handlers.

Root cause

SuppressFilter.filter() checked self.logger not in record.name. When a Powertools logger was initialized with service="core", this substring test matched any third-party logger whose name contained "core" (such as botocore). As a result, botocore records propagating to the runtime root handler were unintentionally dropped from CloudWatch logs.

User experience

  • Before: Logger(service="core") caused unrelated loggers containing "core" (like botocore warnings) to be swallowed and never reach the Lambda root handler.
  • After: Only records from the Powertools logger itself (record.name == "core") or its children (record.name.startswith("core.")) are suppressed from the root handler. Unrelated loggers like botocore are preserved and emitted as expected.

Verification

I used an AI assistant to prepare this fix and ran all validations locally:

  1. Reproduction & regression verification:
    • Confirmed failure on develop where botocore warnings were suppressed (AssertionError: botocore was unexpectedly suppressed!).
    • Ran newly added regression test:
      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.11s
  2. Full logger test suite:
    • uv run pytest tests/functional/logger/ tests/unit/logger/
      -> 205 passed, 7 warnings in 0.72s
  3. Linting and formatting:
    • make lint (ruff format + ruff check) -> 1417 files left unchanged, All checks passed!
  4. Static type checking:
    • make mypy -> Success: no issues found in 963 source files
  5. Diff hygiene:
    • git 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.

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
@roonakyadav
roonakyadav requested a review from a team as a code owner November 15, 2026 16:09
@roonakyadav
roonakyadav requested a review from hjgraca November 15, 2026 16:09
@boring-cyborg

boring-cyborg Bot commented Nov 15, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 15, 2026
@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena leandrodamascena added this to the 3.42.0 milestone Nov 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logger size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SuppressFilter hides unrelated loggers whose name contains the service name

2 participants