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
Feature request: convenience reset_state method in Logger #4134
As a customer who uses canonical logging - aka wide logging - I would like to be able to clear any key I might have appended to the Logger instance regardless of me using the default formatter or the decorator - both of which either expose a method along these lines or can be configured to automatically clear state.
Hello @heitorlessa and @dreamorosi! I noticed in the issue aws-powertools/powertools-lambda-typescript#2337 that you two discussed how to resolve a "conceptual" bug with our current method names (persistent vs non-persistent) and their behavior. I see that some things are marked as deprecated to be removed in the next major release. As we're about to release Powertools for AWS Lambda (Python) v3, we have an opportunity to review this here.
My idea is:
1 - Create a new method and call it add_persistent_keys so that those keys will persist even the clear_state() method is invoked. This method will allow developers to explicitly define the keys that should remain until the Logger instance is destroyed.
2 - Regarding the current append_keys method, I don't think we need to change its functionality. However, we should improve the documentation and potentially add a workflow example to clarify that this method behaves like a "temporary keys" mechanism. The keys added through append_keys will be removed when clear_state() is called, as it is currently designed.
I might be misunderstanding something regarding the TypeScript issue, and please correct me if this is the case. If not, and you agree with my proposal, I think we can proceed with implementing this change for Powertools for AWS Lambda (Python) v3.
Hey Leo, I'm unsure on how to move forward with that feature and even more unsure whether to recommend that you skip it entirely in Python or not.
The clear_state method is fine, but the persistent/temporary distinction is a bit messy due to how it was naively implemented in our repo.
With Heitor we already hashed out the new API and wording (my second to last comment in the PR), but now there are some questions on how to actually implement it as fixing the implementation requires a different merging strategy for the attributes. I plan on fixing this later next week, or the week after once I'm done with the Madrid Summit.
It's important to highlight here that this distinction between persistent and temporary attributes was added to TS as a deviation by the original implementer and not in response to customer demand, at least afaik.
While there are valid use cases for this type of feature, I don't know that we have evidence of customers actually needing/using it, so the decision to add it to Python is up to you.
Hello @dreamorosi! Thank you for your always valuable insights! I'm going to leave this here on hold until you make progress on the TypeScript PR and see if we can adopt the same in Python. If possible, it's good because we can start to reduce the differences in language implementations, if not I'll move forward and implement only the clear_state method.
changed the title [-]Feature request: convenience `clear_state` method in Logger[/-][+]Feature request: convenience `reset_state` method in Logger[/+]on Jun 9, 2024
Activity
rubenfonseca commentedon Apr 15, 2024
Awesome, thank you for opening this @dreamorosi ! We'll work on this tomorrow
heitorlessa commentedon May 9, 2024
Meanwhile we don't submit a PR for a top level method, this is possible today like this:
The top level method should delegate to formatter
leandrodamascena commentedon May 29, 2024
Hello @heitorlessa and @dreamorosi! I noticed in the issue aws-powertools/powertools-lambda-typescript#2337 that you two discussed how to resolve a "conceptual" bug with our current method names (persistent vs non-persistent) and their behavior. I see that some things are marked as deprecated to be removed in the next major release. As we're about to release Powertools for AWS Lambda (Python) v3, we have an opportunity to review this here.
My idea is:
1 - Create a new method and call it
add_persistent_keysso that those keys will persist even theclear_state()method is invoked. This method will allow developers to explicitly define the keys that should remain until theLoggerinstance is destroyed.2 - Regarding the current
append_keysmethod, I don't think we need to change its functionality. However, we should improve the documentation and potentially add a workflow example to clarify that this method behaves like a "temporary keys" mechanism. The keys added throughappend_keyswill be removed whenclear_state()is called, as it is currently designed.I might be misunderstanding something regarding the TypeScript issue, and please correct me if this is the case. If not, and you agree with my proposal, I think we can proceed with implementing this change for Powertools for AWS Lambda (Python) v3.
dreamorosi commentedon May 29, 2024
Hey Leo, I'm unsure on how to move forward with that feature and even more unsure whether to recommend that you skip it entirely in Python or not.
The
clear_statemethod is fine, but the persistent/temporary distinction is a bit messy due to how it was naively implemented in our repo.With Heitor we already hashed out the new API and wording (my second to last comment in the PR), but now there are some questions on how to actually implement it as fixing the implementation requires a different merging strategy for the attributes. I plan on fixing this later next week, or the week after once I'm done with the Madrid Summit.
It's important to highlight here that this distinction between persistent and temporary attributes was added to TS as a deviation by the original implementer and not in response to customer demand, at least afaik.
While there are valid use cases for this type of feature, I don't know that we have evidence of customers actually needing/using it, so the decision to add it to Python is up to you.
leandrodamascena commentedon May 31, 2024
Hello @dreamorosi! Thank you for your always valuable insights! I'm going to leave this here on hold until you make progress on the TypeScript PR and see if we can adopt the same in Python. If possible, it's good because we can start to reduce the differences in language implementations, if not I'll move forward and implement only the
clear_statemethod.[-]Feature request: convenience `clear_state` method in Logger[/-][+]Feature request: convenience `reset_state` method in Logger[/+]github-actions commentedon Jan 31, 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 Feb 11, 2025
This is now released under 3.6.0 version!