python-3.x - 如何获取 HTTP 触发的 Google Cloud Functions 的执行 ID?

标签 python-3.x logging google-cloud-functions

我正在尝试使用 Cloud Logging API Cloud 客户端库将日志从 Python 应用程序写入 Logging,其“执行 ID”与 google 的默认值相同。

enter image description here

记录器设置:

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/

相关文章:

python - 使用 python selenium 单击查看联系人后,我无法获取相同的检查输出,从而无法抓取手机号码

javascript - Chrome控制台到文件

linux - 如何在日志中发送错误,在 shell 脚本中添加日期?

security - Google Cloud Function 通过内部 IP 连接到 Google Compute Engine

javascript - Firebase 云函数计划 : Function returned undefined, 预期 promise 或值

python - Pandas : Is there a way to count the number of occurrences of values in a given column which contains dictionaries values in the cells?

python - 尝试在网站中查找 ID 并出现 'chrome not reachable' 错误

mysql - 我无法使用 Python3 向 MYSQL 插入变量

flash - 开发flex应用程序时如何将一些日志输出到控制台?

firebase - 有没有办法向正在运行的 Firebase 模拟器添加/修改功能?