rename SetTraceID to WithTraceID for package gtrace

This commit is contained in:
John Guo 2021-12-17 01:27:24 +08:00
parent b6d60fc209
commit f583f28953
2 changed files with 5 additions and 5 deletions

View File

@ -144,14 +144,14 @@ func GetBaggageVar(ctx context.Context, key string) *gvar.Var {
return NewBaggage(ctx).GetVar(key)
}
// SetTraceID injects custom trace id into context to propagate.
func SetTraceID(ctx context.Context, traceID trace.TraceID) context.Context {
// WithTraceID injects custom trace id into context to propagate.
func WithTraceID(ctx context.Context, traceID trace.TraceID) context.Context {
sc := trace.SpanContextFromContext(ctx)
if !sc.HasTraceID() {
var (
span trace.Span
)
ctx, span = NewSpan(ctx, "gtrace.SetTraceID")
ctx, span = NewSpan(ctx, "gtrace.WithTraceID")
defer span.End()
sc = trace.SpanContextFromContext(ctx)
}

View File

@ -46,7 +46,7 @@ func Test_Client_Server_Tracing(t *testing.T) {
})
}
func Test_SetTraceID(t *testing.T) {
func Test_WithTraceID(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
p := 8889
s := g.Server(p)
@ -61,7 +61,7 @@ func Test_SetTraceID(t *testing.T) {
time.Sleep(100 * time.Millisecond)
ctx := gtrace.SetTraceID(context.TODO(), traceID)
ctx := gtrace.WithTraceID(context.TODO(), traceID)
prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
client := g.Client()