Repository navigation
Description
Expected Behaviour
I would expected the output to be
AWS logger
NoneType: None
Current Behaviour
--- Logging error ---
Traceback (most recent call last):
File "/Users/kevin.flathers/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/logging/__init__.py", line 1160, in emit
msg = self.format(record)
^^^^^^^^^^^^^^^^^^^
File "/Users/kevin.flathers/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/logging/__init__.py", line 999, in format
return fmt.format(record)
^^^^^^^^^^^^^^^^^^
File "/Users/kevin.flathers/codebase/cz-common-python/.venv/lib/python3.12/site-packages/aws_lambda_powertools/logging/formatter.py", line 197, in format
extracted_exception, extracted_exception_name = self._extract_log_exception(log_record=record)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kevin.flathers/codebase/cz-common-python/.venv/lib/python3.12/site-packages/aws_lambda_powertools/logging/formatter.py", line 391, in _extract_log_exception
return self.formatException(log_record.exc_info), log_record.exc_info[0].__name__ # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?
Call stack:
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/kevin.flathers/codebase/cz-common-python/z.py", line 10, in <module>
aws_logger.warning('AWS logger', exc_info=True)
File "/Users/kevin.flathers/codebase/cz-common-python/.venv/lib/python3.12/site-packages/aws_lambda_powertools/logging/logger.py", line 544, in warning
return self._logger.warning(
Message: 'AWS logger'
Arguments: ()
Code snippet
import logging
from aws_lambda_powertools import Logger
python_logger = logging.getLogger(__name__)
aws_logger = Logger()
python_logger.warning('Python logger', exc_info=True)
print('\n\n')
aws_logger.warning('AWS logger', exc_info=True)Possible Solution
It appears like AWS Power Tools Logger is throwing an error somewhere when exc_info is set to True, but an exception was not raised. This is counter to how the Python logger works, where it just prints NoneType: None
Steps to Reproduce
Run the provided script
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.12
Packaging format used
PyPi
Debugging logs
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsShipped
Activity
boring-cyborg commentedon Mar 27, 2025
Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link
leandrodamascena commentedon Mar 27, 2025
Thank you for raising this issue to improve the developer experience @flatherskevin!
You're correct. This behavior occurs in Powertools because setting
exc_infotriggers the addition of exception information to the logging message.To clarify:
exc_infois set, Powertools attempts to include exception details in the log.I agree that we should test if an exception occurs before adding this key, but I'm curious to hear from you in which scenarios you want to log warning with
exc_info=Truewithout a real exception.Thanks.
flatherskevin commentedon Mar 27, 2025
@leandrodamascena the use case was mostly just we migrated from the Python logger to the AWS PowerTools Logger, and this situation showed up and started failing. We have fixed the line in our code because using
exc_infooutside of an exception is not necessarily useful, but I wanted to raise it here as it is a breaking bug from the core Python logging behavior.leandrodamascena commentedon Mar 27, 2025
Hi @flatherskevin! Thanks a lot for clarifying the use case and I agree that sense for us to fix this.
If you have some bandwidth, I'd be more than happy to have your input here. But if not, don't worry, I can fix this in the next release, which will be in 15 days.
waffleshop commentedon Mar 28, 2025
I encountered the same issue when code defers exceptions by storing them in a list, logging them later, then raising them together as an ExceptionGroup.
leandrodamascena commentedon Mar 28, 2025
Hey @waffleshop! Can you share a snippet that I can reproduce this error?
waffleshop commentedon Mar 28, 2025
@leandrodamascena Here is a vague snippet that reproduces my code's situation. I was able to work around the issue by using
asyncio.as_completed()instead ofasyncio.gather().waffleshop commentedon Mar 28, 2025
This is my workaround with
asyncio.as_completed():leandrodamascena commentedon Apr 7, 2025
Hey @flatherskevin and @waffleshop thanks for all the explanation! I'm working in a PR to fix this and release tomorrow.
github-actions commentedon Apr 7, 2025
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 tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
github-actions commentedon Apr 8, 2025
This is now released under 3.10.0 version!