google-cloud-platform - 如何在单独的 Cloud Run 请求中手动指定 X-Cloud-Trace-Context header 值并关联和跟踪日志?

标签 google-cloud-platform google-cloud-run google-cloud-logging google-cloud-tasks google-cloud-trace

我正在使用 Cloud Run 和 Cloud Tasks 对 webhook 进行一些异步处理。当我收到对我的 Cloud Run 服务的请求时,我会在我的 Cloud Tasks 队列中排队一个任务并立即从我的服务返回响应。然后 Cloud Tasks 将再次触发我的服务(不同的端点)并进行一些处理。我想通过使用相同的跟踪 ID 关联这些步骤中的所有日志,但它不起作用。
在 Cloud Tasks 中创建任务时,我要求它发送 X-Cloud-Trace-Context header ,我用原始请求的 X-Cloud-Trace-Context 填充它 header 值。理论上,当请求从 Cloud Tasks 发送到我的 Cloud Run 服务时,它应该具有此 header 值,并且我的所有日​​志都将正确关联。但是,当第二个请求到来时,看起来 Cloud Run 正在使用新的跟踪 ID 覆盖 header 。
有没有办法防止这种情况发生?如果不是,在上述步骤中关联所有日志(由服务代码生成以及由 GCP 自动生成的日志)的推荐解决方案是什么?
谢谢您的帮助!

最佳答案

我认为您不能覆盖 Cloud Tasks 设置的 HTTP header ,但您可以覆盖 trace发送到 Stack Driver 的日志记录中的成员。
因此,您可以在任务负载中包含原始跟踪 ID,然后覆盖 trace在执行实际工作的 Cloud Run 端点生成的日志中。

关于google-cloud-platform - 如何在单独的 Cloud Run 请求中手动指定 X-Cloud-Trace-Context header 值并关联和跟踪日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66845805/

相关文章:

windows - 无法在 Windows 的 stackdriver Monitoring 中查看内存使用情况

kubernetes - 如何在 GKE 中创建具有 ReadWriteMany 访问权限的动态持久卷声明?

google-cloud-platform - 如何获取发送到 Google Cloud Logging 的所有 stderr 日志的通知?

kubernetes - 存储桶中的GCP堆栈驱动程序日志记录日志格式已从每个容器的文件夹更改为stdout\stderr

google-cloud-platform - 在 Google Cloud Platform ML Engine 中创建新版本时出现 403 Forbidden

kubernetes - GCP-如何使用Ingress在负载均衡器上服务多个应用程序?

google-cloud-platform - 无法列出 Cloud Run 部署中的容器镜像

Firebase 托管缓存 ​​Google Cloud Run 请求

postgresql - 将 hasura 与 Google Cloud Run 和 Google Cloud SQL 结合使用

google-cloud-logging - 谷歌云日志 : show lines above and below the matched lines