powertools-lambda-python icon indicating copy to clipboard operation
powertools-lambda-python copied to clipboard

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

Open leandrodamascena opened this issue 2 weeks ago • 3 comments

[!WARNING] For contributors, human or agent. Comment here to claim this issue and wait for the assignment before opening a PR; if two PRs show up, the assignee's stays. AI-assisted work is welcome, say so in the PR and tell us how you verified it: run the tests yourself and paste what you saw, do not describe runs you did not do. Read AGENTS.md first, it has the commands and the rules the CI enforces. This goes into 3.42.0.

Expected Behaviour

Powertools adds a SuppressFilter(service) to the root handlers so the Powertools logger's own records are not printed twice. Only records from that logger, or its children, should be filtered.

Current Behaviour

SuppressFilter.filter does self.logger not in record.name, a substring test. Any third-party logger whose name contains the service string is dropped from the root handlers, which in Lambda is the runtime's own handler. With Logger(service="core"), botocore warnings never reach CloudWatch while urllib3 ones do. service="s" would silence almost everything.

Code snippet

import logging
from aws_lambda_powertools import Logger

logger = Logger(service="core")
logging.getLogger("botocore").warning("credentials expire soon")  # gone
logging.getLogger("urllib3").warning("retrying")                  # printed

Possible Solution

In aws_lambda_powertools/logging/filters.py, match the logger itself or its children: record.name == self.logger or record.name.startswith(f"{self.logger}."). Add a functional test in tests/functional/logger/required_dependencies/ with a root handler on a StringIO: a logger whose name contains the service string must still print, a child of the Powertools logger must still be suppressed.

Item 1 of the Logger audit in #8730, re-verified on develop today. Functional tests go through the public Logger API only.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

No response

leandrodamascena avatar Nov 15 '26 15:11 leandrodamascena

[!note] For those interested in contributing, please leave a comment below so that we can assign the issue to you and make sure we don't duplicate efforts. If you have any further questions, please don't hesitate to ask below or on our Discord server.

Hi maintainers, I would like to take this issue. Could you please assign it to me? Thank you!

roonakyadav avatar Nov 15 '26 15:11 roonakyadav

It's yours @roonakyadav, together with #8823. Two per person is the limit for this batch, so #8826 stays with @eminfikret who asked first. This one is a one-line fix with a two-case test; the important part is the test, see the issue text.

leandrodamascena avatar Nov 15 '26 15:11 leandrodamascena

[!warning] This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either reopen the issue, or open a new issue referencing this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.