-
Notifications
You must be signed in to change notification settings - Fork 400
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
Lambda context data is excluded when using custom formatter and flag clear_state on inject_lambda_context #1042
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Thanks a lot for reporting this @jacobdarrossi - it sounds like an issue on our side, if all you're doing is overriding that method. We'll look into it on Monday as soon as we can, and make a patch release if we manage to reproduce it. |
Forgot to ask, could you provide before/after log outputs too? That will speed up reproducing it on our side, or quickly detecting whether that's intended behaviour. Thank you!! |
Thanks for replying so fast. First block of logs, with Formatter. Code:
Logs with formatter:
Logs without formatter:
|
Thanks a lot @jacobdarrossi - That doesn't seem right at all. Got side tracked with customer activities, but will be looking into it this week |
@heitorlessa Funnily we had the exact same issue days ago, we're also using our own formatter which inherits the We think the issue is here: If a formatter already exists it wont be reallocated and defaulted to the standard keys, it will just reuse the existing object. Feels like the only way to not introduce a breaking change to this is to add a new parameter to pass a formatter factory or meta class that will recreate our own new formatter rather than reuse the existing one. Something like formatter = self.logger_formatter_factory(**log_keys) or self.logger_formatter or LambdaPowertoolsFormatter(**log_keys) # type: ignore |
ugh thanks a lot @ilias-at-adarma! @jacobdarrossi and @ilias-at-adarma, would it be too much of a blocker for you if I start looking at a solution this coming Monday? I'd like to look into this clear headed, and with enough time to make an emergency release as soon as I get a fix. I can start looking as soon as possible if this can't be worked around (e.g. no clear_state=True). |
@heitorlessa, no problem. We wait. Thank you very much. |
Had my first look into this bug and the more I look the more interesting it becomes. @ilias-at-adarma I like your idea about factory, but I suspect we can solve it by transparently introducing a It's something I've been meaning to do for ages. Most of it came due to the original implementation that outgrew a tiny library we originally vended. Now it's a good opportunity to further break down With a Next. I blocked tomorrow morning and a few slots in the afternoon to work on tests for this. My resolve is to have a fix by the end of the week (latest), and send a few implementation ideas here in case I get blocked. Meantime, I'm gonna make a patch release today to introduce non-related fixes elsewhere. I appreciate your patience while we investigate all trade-offs here. |
@jacobdarrossi @ilias-at-adarma we've got a fix - It'll be transparent to you as you're inheriting from For folks using Logger in non-Lambda environments, where they end up creating an entirely new Logger Formatter to use with Powertools, we decided to use a Next. I'm work on improving the documentation on the edge case, and continue to emphasize If I'm mistaken and you are in fact inheriting from Thank you for your patience :) |
@heitorlessa, I tested with #1072's branch, works exactly as expected without any change on our side as you said. We are indeed inheriting from Cheers |
Perfect. I'll complete the missing parts and make a release tomorrow |
@heitorlessa, we also tested it and it works as expected. Let's wait for release. Thanks |
This is now released under 1.25.3 version! |
PyPi and SAR App have the fix. Kicking the Lambda Layer update (version 13) across all AWS commercial regions we support - might take a few hours. cc @am29d |
@heitorlessa and the whole aws-lambda-powertools team, thank you all |
Lambda Layer version 13 is now live on all regions -- Rebuilding docs and it should reflect the latest ARN in a few minutes arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:13 |
When we use a custom formatter, inject_lambda_context with clear_state=True stopped having effect
Expected Behavior
The keys appended should be removed in clear_state=True and the context data should be kept. The custom Formatter should not impact this behavior
Current Behavior
When we use a custom formatter to obfuscate sensitive data in our logs, the flag clear_state=True stopped having effect, the context data is no longer logged and the keys appended was not removed in next hot execution. If clear_state is removed, the context data is logged normally
Steps to Reproduce (for bugs)
Environment
The text was updated successfully, but these errors were encountered: