Skip to content
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

refactor: update request-id recipe to use contextvars #2404

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

EricGoulart
Copy link

Summary of Changes

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.

Related Issues

Closes #2260.

EricGoulart and others added 10 commits October 20, 2024 14:19
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
@EricGoulart
Copy link
Author

I wanted to apologize for the confusion with my pull request. This is my first time contributing to a public repository, and I made a mistake with the process. I had previously opened a PR with the changes, but I accidentally closed it and am unable to reopen it.

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.27%. Comparing base (b765b25) to head (7c371e8).

Additional details and impacted files
@@             Coverage Diff             @@
##            master    #2404      +/-   ##
===========================================
- Coverage   100.00%   98.27%   -1.73%     
===========================================
  Files           64       64              
  Lines         7726     7726              
  Branches      1071     1071              
===========================================
- Hits          7726     7593     -133     
- Misses           0      115     +115     
- Partials         0       18      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update request-id recipe to use contextvars instead of threading.local()
2 participants