-
Notifications
You must be signed in to change notification settings - Fork 421
Bug: logger.remove_keys("xray_trace_id") is not removing xray_trace_id field for lambdas #2835
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
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @bandapatideepak - that's expected behaviour. If you don't want that key despite having X-Ray enabled, you can remove it at Logger initialisation, as described in our documentation: https://docs.powertools.aws.dev/lambda/python/latest/core/logger/#overriding-log-records logger = Logger(xray_trace_id=None) Why doesn't remove_keys work? Because xray_trace_id and other keys are added during log record creation. remove_keys would remove existing keys registered via append_keys, or during Logger initialisation. Thank you for taking the time to create an issue regardless. Feel free to reopen if this doesn't work for you. |
|
Hi @heitorlessa import json def lambda_handler(event, context): { you can quickly copy paste and add below link for lambda layer which is aws lambda power tools lambda layer |
@bandapatideepak sorry to hear that. I'll look into it today |
confirmed, sending a fix shortly and sending a quick workaround you can use until we make the release. |
Done. Until we make a release (we do every two weeks), you can use the following custom formatter: from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter
from aws_lambda_powertools.logging.types import LogRecord
class CustomFormatter(LambdaPowertoolsFormatter):
def serialize(self, log: LogRecord) -> str:
"""Serialize final structured log dict to JSON str"""
log.pop("xray_trace_id", None) # removes X-Ray Trace ID key until PR #2852 is released
return self.json_serializer(log)
logger = Logger(service="payment", xray_trace_id=None, logger_formatter=CustomFormatter())
logger.info("blah") After the release, you can get rid of this custom formatter and simply use: from aws_lambda_powertools import Logger
logger = Logger(service="payment", xray_trace_id=None)
logger.info("blah") Thank you for your patience and truly appreciate you coming back to report it was still an issue @bandapatideepak |
Automation didn't kick in somehow - this was released last week. @bandapatideepak please let us know if you still find that in production in the latest release: https://github.com/aws-powertools/powertools-lambda-python/releases/tag/v2.22.0 |
|
This is now released under 2.23.0 version! |
Expected Behaviour
should not have xray_trace_id property when add it in logger.remove_keys
Current Behaviour
xray_trace_id property is dispalyed in the object even though it is added in logger.remove_keys
Code snippet
Possible Solution
exclude xray_trace_id value
Steps to Reproduce
print the coed snippet in any aws lambda
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.7
Packaging format used
Lambda Layers, PyPi
Debugging logs
The text was updated successfully, but these errors were encountered: