GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-python

Looking for support: Setup logging for async function with http.aio

オープン
#398 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る
documentation P2
主要言語
Python
スター
968
フォーク
128
PR マージ指標
30日以内にマージされた PR はありません

説明

Hello.
My goal is to see the **logs of an async CloudRun function in the CloudRun logs console**.
Does anybody has experience how to set this up correctly?

### Background
So far, for synchronous CloudRun function, I always used the google [python-logging](https://github.com/googleapis/python-logging) library, which is also recommended in the [Google Cloud documentation](https://cloud.google.com/logging/docs/setup/python) and is really simple.

However, the same is not working when I switch to the async function, there I never receive any logs. Here the sample code:
```python
from starlette.requests import Request
from starlette.responses import Response, JSONResponse
import aiohttp
import functions_framework.aio

import google.cloud.logging

# logging handler
client = google.cloud.logging.Client()
client.setup_logging(log_level=logging.DEBUG)

@functions_framework.aio.http
async def llm_emulator(request: Request):
logging.log(msg="hello world", level=logging.DEBUG) #-> this log never reaches CloudRun log console

```
I did some experimentation, my assumptions so far:
- async uses a different setup, not Flask+uvicorn but starlette under the hood. This might require some different initialisation of the logging
- maybe data is logged into a different thread/coroutine, I tried ```client.flash_handlers()``` but this has no effect.

Does anyone use logs in an async function and has experience, how to set it up correctly? (with or without any library)
I would be grateful for any hints or links to available documentation. Thanks a lot.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。