我正在尝试使用 Cloud Logging API Cloud 客户端库将日志从 Python 应用程序写入 Logging,其“执行 ID”与 google 的默认值相同。
记录器设置:
from google.cloud import logging
from google.cloud.logging.resource import Resource
log_client = logging.Client()
# This is the resource type of the log
log_name = 'cloudfunctions.googleapis.com%2Fcloud-functions'
# Inside the resource, nest the required labels specific to the resource type
res = Resource(type="cloud_function",
labels={
"function_name": "my-function",
"region": "asia-east2"
})
logger = log_client.logger(log_name.format("my-project"))
写入日志:
logger.log_struct({"message": request.remote_addr}, resource=res, severity='INFO')
最佳答案
目前无法仅使用云函数框架本身来执行此操作,但您可以尝试使用以下命令从请求本身中提取 executionId
:
request.headers.get('function-execution-id')
我在 Cloud Functions Github 中发现一个问题,跟踪获取这些值的 native 方法的实现,您可以关注 this thread如果您愿意,可以获取更新。
关于python-3.x - 如何获取 HTTP 触发的 Google Cloud Functions 的执行 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66326539/