From 5c58ad5edf461f0510f5283073300d1bd354171b Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 28 Aug 2023 10:25:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0=E9=93=BE=E8=B7=AF?= =?UTF-8?q?=E8=BF=BD=E8=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/curl/client_resty.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utils/curl/client_resty.go b/utils/curl/client_resty.go index 6cb0423f..022892b1 100644 --- a/utils/curl/client_resty.go +++ b/utils/curl/client_resty.go @@ -9,6 +9,10 @@ import ( "github.com/go-resty/resty/v2" "github.com/zeromicro/go-zero/core/logc" "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/core/trace" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/propagation" + oteltrace "go.opentelemetry.io/otel/trace" ) func NewClient(ctx context.Context, c *Config) Client { @@ -18,6 +22,21 @@ func NewClient(ctx context.Context, c *Config) Client { // 设置超时时间为 5 分钟 client.SetTimeout(5 * time.Minute) + /* 传输链路 */ + tracer := otel.GetTracerProvider().Tracer(trace.TraceName) + spanCtx, span := tracer.Start( + ctx, + "client_resty_send", + oteltrace.WithSpanKind(oteltrace.SpanKindClient), + ) + carrier := &propagation.HeaderCarrier{} + otel.GetTextMapPropagator().Inject(spanCtx, carrier) + for _, cacarrierKey := range carrier.Keys() { + client.SetHeader(cacarrierKey, carrier.Get(cacarrierKey)) + } + defer span.End() + /* 传输链路 */ + if c.HeaderData != nil { for k, v := range c.HeaderData { client = client.SetHeader(k, v)