【发布时间】:2021-08-04 08:33:30
【问题描述】:
我的 Go gRPC 服务器配备了
-
Google 跟踪跨度导出器:
import texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace" ... gcp, err := texporter.NewExporter() ... tracer := trace.NewTracerProvider(trace.WithSyncer(traceExporter), trace.WithSampler(trace.AlwaysSample())) otel.SetTracerProvider(tracer) -
在 gRPC 服务器上注册的 otelgrpc 拦截器。
unaryInterceptors := grpc_middleware.WithUnaryServerChain( otelgrpc.UnaryServerInterceptor(), ) streamInterceptors := grpc_middleware.WithStreamServerChain( otelgrpc.StreamServerInterceptor(), )
现在我尝试在 RPC 实现中创建一个跟踪跨度,以便我可以为该方法创建子跨度,例如:
func (s *srv) Test(ctx context.Context, req *pb.Request) (*pb.TestResponse, error) {
// create a span here
span1 := [??????].Start()
doWork1()
span1.End()
span2 := [??????].Start()
doWork2()
span2.End()
...
}
但目前还不清楚from the OpenTelemetry docs 是如何做到这一点的。
我得到的最接近的是otel.GetTracerProvider().Tracer("some string here???"),提供了Start(ctx)(ctx,Span)。但我不清楚这里要提供什么字符串(我的出口商没有文档指出的 url),这似乎很不方便。
我在想某处有类似otelgrpc.SpanFromCtx(ctx) 的方法可以拉动示踪剂+使用我没有找到的rpc ctx 创建一个跨度。遗憾的是,OT+gRPC+Go 的文档非常缺乏。
【问题讨论】:
标签: grpc open-telemetry google-cloud-trace