-
-
Notifications
You must be signed in to change notification settings - Fork 945
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
Update request-id recipe to use contextvars
instead of threading.local()
#2260
Comments
I don't think there is any need to use threadlocal or contextvar. just use re-reading all that page it proposes several approaches. so yes, context var is better than threadlocal |
Indeed, using global thread-locals is usually not a very bright idea and it leads to a spaghetti code base. But sometimes, particularly when working with a code base migrated from another framework that builds on this paradigm, or when very deep inside nested code, it might be a useful escape hatch. |
Hello, I would like to work on this issue. Please let me know if there is any information that I should know before proceeding. Thank you. |
Hi @EricGoulart! We are glad to hear, sure, go ahead! Regarding the issue itself, I hope the description is clear enough, but just ask here or on Gitter if you run into any problems. You can render out the docs with |
Migrate the request-id handling from threading.local() to contextvars to improve compatibility with async coroutines and avoid issues with threading. This change ensures that request-id is properly tracked in asynchronous environments, providing more robust handling in both sync and async contexts. Previously, threading.local() was used, which does not handle coroutines effectively. By using contextvars, we ensure that the request-id remains consistent across async calls. Closes falconry#2260
Add tests to verify that request_id is unique per request and correctly set in response headers. Tests include checks for isolation in async calls and persistence in synchronous requests. Related to issue falconry#2260
Add tests to verify that request_id is unique per request and correctly set in response headers. Tests include checks for isolation in async calls and persistence in synchronous requests. Related to issue falconry#2260
Hello, just wanto to say sorry about that, It`s my first time contribuiting to a public repository and I am making some mistakes. |
contextvars
is a newer module in the stdlib (3.7+) that is more advanced thantheading.local()
as it not only understand threads, but alsoasyncio
coroutines, etc.Update the Request ID Logging recipe to use
contextvars
.Edit: also add tests for this recipe.
The text was updated successfully, but these errors were encountered: