googleapis / googleapis/google-cloud-python

Async Support for the threading Local Request store

Đang mở
#15,413 3 bình luận 3 reaction 1 người được giao Được @gkevinzheng nhận Xem trên GitHub
api: logging priority: p3 type: question
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

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:

```python
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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.