Skip to content

fix(logger): exclude asyncio task name from log lines - #8840

Open
eminfikret wants to merge 1 commit into
aws-powertools:developfrom
eminfikret:fix/8826-asyncio-taskname-leaks-into-log-lines
Open

eminfikret wants to merge 1 commit into
aws-powertools:developfrom
eminfikret:fix/8826-asyncio-taskname-leaks-into-log-lines

Conversation

@eminfikret

Copy link
Copy Markdown

Issue number: closes #8826

Summary

Python 3.12 added taskName to LogRecord. It wasn't in RESERVED_LOG_ATTRS, so the formatter added it to every log line emitted inside an asyncio task. This removes it.

Changes

  • Added taskName to RESERVED_LOG_ATTRS in aws_lambda_powertools/logging/formatter.py.
  • Added test_log_dict_task_name_is_not_present_when_inside_asyncio_task in tests/functional/logger/required_dependencies/test_logger_powertools_formatter.py.

User experience

  • Before: on Python 3.12+, logs inside an asyncio task included "taskName": "Task-1".
  • After: log lines no longer contain taskName, so they have the same keys inside and outside an asyncio task.

Verification

  • The new test fails on develop and passes with the fix (Python 3.13.5).
  • make pr passes.

I used an AI assistant (Claude) as a tutor and reviewer; I wrote and ran the change and the tests myself.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Python 3.12+ added taskName to LogRecord, so every log emitted inside
an asyncio task carried an unwanted taskName key.

- add taskName to RESERVED_LOG_ATTRS
- add a test that logs inside asyncio.run and asserts taskName is absent

Closes aws-powertools#8826
Signed-off-by: Emin Fikret <emin.n.fikret@gmail.com>
Assisted-by: Claude Opus 5.5
@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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 15, 2026
@sonarqubecloud

Copy link
Copy Markdown

@eminfikret
eminfikret marked this pull request as ready for review November 15, 2026 20:07
@eminfikret
eminfikret requested a review from a team as a code owner November 15, 2026 20:07
@eminfikret
eminfikret requested a review from svozza November 15, 2026 20:07
@eminfikret

Copy link
Copy Markdown
Author

@leandrodamascena, I added taskName to RESERVED_LOG_ATTRS since it's the simpler fix, and I'm new to the repo.

I might look into the derived-list approach later on.

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/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant