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

Use ContextVar instead of threading.local #74

Open
Azmisov opened this issue Dec 9, 2024 · 4 comments
Open

Use ContextVar instead of threading.local #74

Azmisov opened this issue Dec 9, 2024 · 4 comments

Comments

@Azmisov
Copy link

Azmisov commented Dec 9, 2024

I believe switching to using contextvar lib would allow tracking request ID through asynchronous contexts, like when using Daphne + ASGI

@Azmisov
Copy link
Author

Azmisov commented Dec 9, 2024

@j4mie
Copy link
Member

j4mie commented Dec 10, 2024

Hi,

We're already using asgiref.local.Local where available (asgiref is now a dependency of all supported versions of Django). See https://github.com/dabapps/django-log-request-id/blob/master/log_request_id/__init__.py#L7

asgiref uses contextvars internally: https://github.com/django/asgiref/blob/main/asgiref/local.py

@j4mie j4mie closed this as completed Dec 10, 2024
@Azmisov
Copy link
Author

Azmisov commented Dec 10, 2024

Okay, you can update your README. It still says you're using threading.local and asks for suggestions

@j4mie
Copy link
Member

j4mie commented Dec 10, 2024

Oh good catch!

@j4mie j4mie reopened this Dec 10, 2024
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

No branches or pull requests

2 participants