使用 Go 的 Azure ServiceBus 队列的 OpenTelemetry 传播问题

发布于 2025-01-09 06:28:23 字数 289 浏览 0 评论 0原文

我有三个服务,它们订阅并发布到天蓝色服务总线上的单独队列。我刚刚为这些服务添加了开放遥测,但它似乎并未在服务之间传播跟踪 ID。

例如,单个跟踪理想地包括服务之间的流:

服务 1 -> 服务 2。队列1 ->服务2->队列2 ->服务 3

看起来我应该在服务之间注入/提取此信息,但关于如何执行此操作的文档/示例似乎有限,因为显然它应该使用 W3C 跟踪上下文“正常工作”?

如果有人能够提供任何见解或指示,告诉我应该做什么才能达到预期的结果,我将不胜感激。

非常感谢。

I have three services which subscribe and publish to separate queues on azure service bus. I've just added open telemetry for these services and it doesn't appear to propagate the trace ID between services.

For example, a single trace would ideally include the flow between services:

Service 1 -> Queue1 -> Service 2 -> Queue2 -> Service 3

It looks like I'm supposed to Inject/Extract this information between services, but there appears to be limited documentation/examples on how to do this, because apparently it's supposed to "just work" using the W3C Trace Context?

If anyone can provide any insight or pointers into exactly what I should be doing in order to achieve the desired outcome, that would be greatly appreciated.

Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我还不会笑 2025-01-16 06:28:23

我记得当我需要在多个 GRPC 服务之间传播跟踪时,我对 OpenCensus 跟踪库做了类似的事情。我获取现有的跟踪范围,将其馈送到 Binary 函数,获取字节,将其设置为传出上下文中的数据,然后在接收端,我从传入上下文中提取跟踪范围并将其馈送到trace.StartSpanWithRemoteParent。

这是向上下文添加跟踪的 util 的实现:

package grpcutil

import (
    "context"
    "encoding/base64"

    "github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"
    "go.opencensus.io/trace"
    "go.opencensus.io/trace/propagation"
    "google.golang.org/grpc/metadata"
)

const TraceContextMDKey = "trace_ctx"

func NewTraceableContext(ctx context.Context, span *trace.Span) context.Context {
    return metadata.AppendToOutgoingContext(
        ctx,
        TraceContextMDKey, base64.StdEncoding.EncodeToString(propagation.Binary(span.SpanContext())),
    )
}

func GetRemoteTraceContext(ctx context.Context) (trace.SpanContext, bool) {
    var traceCtx []byte
    extCtx := metautils.ExtractIncoming(ctx).Get(TraceContextMDKey)
    if len(extCtx) > 0 {
        traceCtx, _ = base64.StdEncoding.DecodeString(extCtx)
    }
    return propagation.FromBinary(traceCtx)
}

它在接收端的外观:

remoteTraceCtx, _ := grpcutil.GetRemoteTraceContext(ctx)
_, span := trace.StartSpanWithRemoteParent(ctx, "name", remoteTraceCtx)
defer span.End()

希望这能为您指明正确的方向。

I remember doing something similar with OpenCensus trace library when I needed to propagate traces between multiple GRPC services. I took the existing trace span, fed it to Binary function, got the bytes, set it as data on the outgoing context, then on the receiving side I extracted the trace span from the incoming context and fed it to trace.StartSpanWithRemoteParent.

This is the implementation of the util that was adding trace to context:

package grpcutil

import (
    "context"
    "encoding/base64"

    "github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"
    "go.opencensus.io/trace"
    "go.opencensus.io/trace/propagation"
    "google.golang.org/grpc/metadata"
)

const TraceContextMDKey = "trace_ctx"

func NewTraceableContext(ctx context.Context, span *trace.Span) context.Context {
    return metadata.AppendToOutgoingContext(
        ctx,
        TraceContextMDKey, base64.StdEncoding.EncodeToString(propagation.Binary(span.SpanContext())),
    )
}

func GetRemoteTraceContext(ctx context.Context) (trace.SpanContext, bool) {
    var traceCtx []byte
    extCtx := metautils.ExtractIncoming(ctx).Get(TraceContextMDKey)
    if len(extCtx) > 0 {
        traceCtx, _ = base64.StdEncoding.DecodeString(extCtx)
    }
    return propagation.FromBinary(traceCtx)
}

How it looked on the receiving side:

remoteTraceCtx, _ := grpcutil.GetRemoteTraceContext(ctx)
_, span := trace.StartSpanWithRemoteParent(ctx, "name", remoteTraceCtx)
defer span.End()

Hope this points you in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文