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

Async Support for the threading Local Request store #779

Open
g4borg opened this issue Aug 28, 2023 · 0 comments
Open

Async Support for the threading Local Request store #779

g4borg opened this issue Aug 28, 2023 · 0 comments
Assignees
Labels
api: logging Issues related to the googleapis/python-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@g4borg
Copy link

g4borg commented Aug 28, 2023

At this moment the code in https://github.com/googleapis/python-logging/blob/main/google/cloud/logging_v2/handlers/middleware/request.py uses a threading.Local to store the latest request for usage with the structured Logging.

This global singleton approach does not seem safe for Async Code, where one would either rather use contextvars library, or even easier for the current codebase do something along this:

try:
    from asgiref.local import Local
except ImportError:
    from threading import local as Local

_thread_locals = Local()

Sidenote: every code I see using this technique imports threading on top anyway, I am not sure if this has some deeper significance, so I omitted it.

I do think, that to support async correctly in newer Django Versions, this change should be made, or it might ending up sending wrong logs in certain situations.

@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/python-logging API. label Aug 28, 2023
@daniel-sanche daniel-sanche removed their assignment Oct 20, 2023
@gkevinzheng gkevinzheng added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Jan 9, 2024
@gkevinzheng gkevinzheng self-assigned this Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/python-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants