package contextutil import ( "context" "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/consts" "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/log" "github.com/google/uuid" ) func MakeTraceCtx(ctx context.Context, keysAndValues ...interface{}) context.Context { requestId := uuid.NewString() ctx = context.WithValue(ctx, consts.TraceIDHeader, requestId) keysAndValues = append([]interface{}{consts.TraceIDHeader, requestId}, keysAndValues...) ctxLog := log.WithValues(keysAndValues...) ctx = context.WithValue(ctx, log.GetContextKey(), ctxLog) return ctx }