-
Notifications
You must be signed in to change notification settings - Fork 408
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
Feature request: logger apppend_key context manager #5864
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hello @jusdino ! Thank you so much for opening this feature request. If I understood it correctly, this can already be achieved using the Arguments passed via the |
Hi @anafalcao! Sorry for being unclear. My intent was to describe a feature that applies across multiple log messages, not just one. It could work similarly to Make sense? I actually spoke with @dreamorosi about this at re:Invent, if you need more context - maybe he remembers 😆 . |
Hey @jusdino thanks for opening this feature resquest and responding @anafalcao's comment with the experience you expect. We have 2 other issues related to this (#3719, #2062) and we need to move forward with implementing them. I personally vote for the latter, because I can imagine many scenarios where using the context manager for additional keys could be beneficial, like 1/ transaction workflows, 2/ calling internal functions, and so on. We also support child logger is someone wants to create a separate That said, I think we need to decide a few things: 1 - What is the name of this new method to use the context manager? People have suggested 2 - We also support 3 - We would love to have your PR here to add this support, can you submit a PR? Again, thanks a lot for spending time and making the developer experience even better with Powertools. |
Oh, I should have looked for those other tickets - my bad. I agree on the new vs existing instance - modifying the existing instance makes more sense because we want to augment logs within internal functions, without having to send a special logger instance into an internal chain of functions. I'm sure it'll be really common for a dev to realize that they should tack on a new key to a whole branch of their flow after it's been written. Being to simply wrap it into a
|
Hi @jusdino! Thank you for providing such a detailed explanation. The scope of the problem is well defined. And no problem at all, we understand that everyone is facing time constraints at the moment. We will then proceed with creating a PR to address this. We'll do our best to include this feature in our upcoming release. If you have any further questions or concerns, please don't hesitate to reach out! |
|
This is now released under 3.5.0 version! |
Use case
There are a lot of cases where it could be useful to log extra context-specific keys such as identifiers in a way that is protected from contaminating across other execution contexts. Uses could include looping over a number of jobs, or even enhancing some branch-specific logic with an key that doesn't make sense when the branch didn't execute. In those cases, it would be really handy to be able to concisely and safely manage log keys in a context manager style.
Solution/User Experience
We could enhance the logger interface to include a standard python context manager so use could look something like:
I'm not sure modifying the actual
append_keys
method makes sense as an interface, but some method/attribute/whatever on theLogger
based on your judgement would probably serve equally as well.Alternative solutions
Acknowledgment
The text was updated successfully, but these errors were encountered: