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

Bug: taskName leaks into log lines emitted inside asyncio tasks on Python 3.12+

Open leandrodamascena opened this issue 2 weeks ago • 5 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

Log lines have the same keys inside and outside an asyncio task.

Current Behaviour

Python 3.12 added LogRecord.taskName. It is not in RESERVED_LOG_ATTRS, so every log emitted inside a task carries "taskName": "Task-1".

Code snippet

import asyncio
from aws_lambda_powertools import Logger

logger = Logger(service="x")

async def main():
    logger.info("in task")  # {"level": "INFO", ..., "taskName": "Task-1"}

asyncio.run(main())

Possible Solution

In aws_lambda_powertools/logging/formatter.py, add taskName to RESERVED_LOG_ATTRS, or derive the list from the attributes of a fresh logging.LogRecord so the next stdlib addition does not leak either. Test: log inside asyncio.run, assert taskName is absent.

Item 9 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.

Hello @leandrodamascena, I would like to work on this issue. Could you assign it to me? Thank you.

eminfikret avatar Nov 15 '26 15:11 eminfikret

It's yours @eminfikret. Small one: add the attribute to the reserved list, or derive the list from a fresh LogRecord so the next stdlib addition is covered too, and a test that logs inside asyncio.run. Go ahead.

leandrodamascena avatar Nov 15 '26 15:11 leandrodamascena

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

roonakyadav avatar Nov 15 '26 15:11 roonakyadav

@leandrodamascena, thank you for assigning it to me and for the notes.

eminfikret avatar Nov 15 '26 16:11 eminfikret

[!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.