Skip to content

Bug: Logger custom formatters not receiving standard keys #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
heitorlessa opened this issue Jun 24, 2022 · 3 comments
Closed

Bug: Logger custom formatters not receiving standard keys #1263

heitorlessa opened this issue Jun 24, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@heitorlessa
Copy link
Contributor

Expected Behaviour

As per documentation, using a custom logging formatter should bring standard keys like service. Lambda context keys and custom keys are working just fine.

Example provided demonstrates that service key no longer appears in the first output.

Current Behaviour

When using a custom logging formatter, Powertools Logger standard keys are not being included.

This was identified when re-creating examples, outputs, and improving code snippets in #1262.

Code snippet

from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter


class CustomFormatter(LambdaPowertoolsFormatter):
    def serialize(self, log: dict) -> str:
        """Serialize final structured log dict to JSON str"""
        log["event"] = log.pop("message")  # rename message key to event
        return self.json_serializer(log)  # use configured json serializer


logger = Logger(service="payment", logger_formatter=CustomFormatter())
logger.info("hello")

logger_two = Logger(service="payment")
logger_two.info("hello")

Possible Solution

No response

Steps to Reproduce

Execute the code snippet locally, no need to deploy a Lambda function.

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.9

Packaging format used

Lambda Layers

Debugging logs

No response

@heitorlessa heitorlessa added bug Something isn't working triage Pending triage from maintainers area/logger and removed triage Pending triage from maintainers labels Jun 24, 2022
@heitorlessa
Copy link
Contributor Author

heitorlessa commented Jun 24, 2022

This was introduced here when fixing clear_state: #1042

cc @jacobdarrossi @ilias-at-adarma for awareness, unless I misinterpret something

@heitorlessa
Copy link
Contributor Author

Fix is up. I'll wait to hear from two customers familiar with the original change until next week before merging.

@heitorlessa heitorlessa added the pending-release Fix or implementation already in dev waiting to be released label Jul 4, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2022

This is now released under 1.26.3 version!

@github-actions github-actions bot closed this as completed Jul 4, 2022
@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant