使用 Pub/Sub 在 Google Cloud 中跟踪传播

问题描述 投票:0回答:1

我需要能够通过 pub sub 将跟踪从发布者传播到订阅者,而不在消息中包含任何内容。也就是说,它必须能够在不向消息中插入任何内容的情况下进行传播。仅在标题中。 我尝试了所有可能的方法,但我无法让两者出现在同一个跟踪中: https://google-cloud-opentelemetry.readthedocs.io/en/latest/examples/cloud_trace_propagator/README.html

https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/tree/main/opentelemetry-propagator-gcp

我非常感谢任何贡献。 非常感谢!

第一种方式:

set_global_textmap(CloudTraceFormatPropagator())

第二种方式:

data = get_json()
trace_id_str = data['traceid']
carrier = {'traceparent': trace_id_str}

ctx = TraceContextTextMapPropagator().extract(carrier=carrier)
with tracer.start_as_current_span("/api/doit", ctx) as span:
google-cloud-platform trace open-telemetry
1个回答
0
投票

我自己最近一直在研究这个问题,虽然我认为使用 Google Python PubSub SDK 本身不可能(在撰写本文时),但您可能必须自己进行检测。如果您不想更改实际的消息正文,我想到的是尝试向 PubSub 消息添加一个属性。

您可以添加位于消息元数据中的自定义属性,您可以在下游应用程序中使用该属性。

publisher_client.publish(topic=MY_TOPIC, data=MESSAGE_BODY, traceId=trace_id)
© www.soinside.com 2019 - 2024. All rights reserved.