Skip to content

Async Support for the threading Local Request store #779

Open
@g4borg

Description

@g4borg

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.

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.priority: p3Desirable enhancement or fix. May not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy