You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
API Gateway : Debug mode - print in multiple lines instead of a single one #972
Hey @filol thanks a lot for raising this - first time I'm seeing a debug entry like this, since we're sending all of this as a string to avoid this already.
Hello @heitorlessa I also want to specify that if I print the event manually via logger.info at the beginning of my function, it is displayed on one and the same line
I'll try to reproduce it on Thursday. I suspect despite being a single string, print is adding a new line by default, and CloudWatch Logs is interpreting it differently - if that's the case, we can solve it easily
The extra indentation adds a newline for each key which CloudWatch Logs Console interprets it differently compared to logger.info or simply print(json.dumps(event)) as \n is only added at the end of the string, not per key.
Verdict
UPDATE: Spoke to @jaredcnance from CloudWatch team and they can't know if the next newline is related hence creating a new entry. Since this will incur in additional charges for customers it doesn't conform with our tenets, we will remove indentation.
I'm tempted to keep this under "it's a feature, not a bug". In the meantime, I believe we should do two things unless you @filol strongly disagree with it:
Reach out to CloudWatch Logs team and ask whether this could be improved on their side (this will also happen with Chalice and any other frameworks with debugging enabled)
Re-emphasize in our docs that this is optimized for local development
To demonstrate its value as-is, this is how local dev looks like - 1st line is a log_event/logger.info and the 2nd line is the debug mode with the indentation:
Activity
heitorlessa commentedon Jan 24, 2022
Hey @filol thanks a lot for raising this - first time I'm seeing a debug entry like this, since we're sending all of this as a string to avoid this already.
https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/aws_lambda_powertools/event_handler/api_gateway.py#L499
Unsure whether CloudWatch is interpreting longer strings any differently, but we'll setup a dummy project to try reproducing it.
Thank you!
filol commentedon Jan 24, 2022
Hello @heitorlessa I also want to specify that if I print the event manually via logger.info at the beginning of my function, it is displayed on one and the same line
heitorlessa commentedon Jan 25, 2022
I'll try to reproduce it on Thursday. I suspect despite being a single string,
printis adding a new line by default, and CloudWatch Logs is interpreting it differently - if that's the case, we can solve it easilymichaelbrewer commentedon Jan 29, 2022
i will have a look too
heitorlessa commentedon Jan 31, 2022
Diagnosis
Confirmed. It's the extra indentation added for local debugging purposes (SAM CLI, local tests, Postman) but breaks in the Console.
https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/aws_lambda_powertools/event_handler/api_gateway.py#L451:L451
The extra indentation adds a newline for each key which CloudWatch Logs Console interprets it differently compared to
logger.infoor simplyprint(json.dumps(event))as\nis only added at the end of the string, not per key.Verdict
UPDATE: Spoke to @jaredcnance from CloudWatch team and they can't know if the next newline is related hence creating a new entry. Since this will incur in additional charges for customers it doesn't conform with our tenets, we will remove indentation.
Thank you again for bringing this up @filol
I'm tempted to keep this under "it's a feature, not a bug". In the meantime, I believe we should do two things unless you @filol strongly disagree with it:Reach out to CloudWatch Logs team and ask whether this could be improved on their side (this will also happen with Chalice and any other frameworks with debugging enabled)Re-emphasize in our docs that this is optimized for local developmentTo demonstrate its value as-is, this is how local dev looks like - 1st line is alog_event/logger.infoand the 2nd line is the debug mode with the indentation:heitorlessa commentedon Jan 31, 2022
Done, should be available in the next release.
github-actions commentedon Feb 9, 2022
This is now released under 1.25.0 version!