1 Star 0 Fork 0

SasukeBo/go-micro

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
helper.go 968 Bytes
Copy Edit Raw Blame History
汪波 authored 2023-02-23 10:27 . fix: 替换包名
package datadog
import (
"context"
log "gitee.com/sasukebo/go-micro/v4/logger"
"gitee.com/sasukebo/go-micro/v4/metadata"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
// StartSpanFromContext returns a new span with the given operation name and options. If a span
// is found in the context, it will be used as the parent of the resulting span.
func StartSpanFromContext(ctx context.Context, operationName string, opts ...tracer.StartSpanOption) (tracer.Span, context.Context) {
md, ok := metadata.FromContext(ctx)
if !ok {
md = make(map[string]string)
}
if spanCtx, err := tracer.Extract(tracer.TextMapCarrier(md)); err == nil {
opts = append(opts, tracer.ChildOf(spanCtx))
}
span, ctx := tracer.StartSpanFromContext(ctx, operationName, opts...)
if err := tracer.Inject(span.Context(), tracer.TextMapCarrier(md)); err != nil {
log.Errorf("error while injecting trace to context: %s\n", err)
}
return span, metadata.NewContext(ctx, md)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sasukebo/go-micro.git
git@gitee.com:sasukebo/go-micro.git
sasukebo
go-micro
go-micro
6e18eb58b836

Search