diff --git a/pkg/util/export/merge_test.go b/pkg/util/export/merge_test.go index 2453fb4cab68..bf8e0994ef78 100644 --- a/pkg/util/export/merge_test.go +++ b/pkg/util/export/merge_test.go @@ -316,6 +316,8 @@ func TestMergeTaskExecutorFactory(t *testing.T) { ts, err := time.Parse("2006-01-02 15:04:05", targetDate+" 00:00:00") require.Nil(t, err) + ctx := trace.Generate(context.TODO()) + type args struct { ctx context.Context opts []MergeOption @@ -329,7 +331,7 @@ func TestMergeTaskExecutorFactory(t *testing.T) { { name: "normal", args: args{ - ctx: context.Background(), + ctx: ctx, opts: []MergeOption{WithFileService(fs)}, task: task.Task{ Metadata: task.TaskMetadata{ diff --git a/pkg/util/trace/noop_trace.go b/pkg/util/trace/noop_trace.go index f99bf5de668c..fddeeb80d8c2 100644 --- a/pkg/util/trace/noop_trace.go +++ b/pkg/util/trace/noop_trace.go @@ -46,8 +46,18 @@ func (t NoopTracer) Start(ctx context.Context, name string, opts ...SpanStartOpt if _, ok := span.(NoopSpan); !ok { // span is likely already a NoopSpan, but let's be sure span = NoopSpan{} + return ContextWithSpan(ctx, span), span + } else if len(opts) > 0 { + var sc = SpanConfig{} + for _, opt := range opts { + opt.ApplySpanStart(&sc) + } + if sc.NewRoot { + span = NoopSpan{} + return ContextWithSpan(ctx, span), span + } } - return ContextWithSpan(ctx, span), span + return ctx, span } func (t NoopTracer) Debug(ctx context.Context, name string, opts ...SpanStartOption) (context.Context, Span) { diff --git a/pkg/util/trace/noop_trace_test.go b/pkg/util/trace/noop_trace_test.go index 17edd22b6d40..7365ce9b60fd 100644 --- a/pkg/util/trace/noop_trace_test.go +++ b/pkg/util/trace/noop_trace_test.go @@ -200,6 +200,17 @@ func Test_NoopTracer_Start(t1 *testing.T) { want: ContextWithSpan(context.Background(), NoopSpan{}), want1: NoopSpan{}, }, + { + name: "empty", + args: args{ + ctx: context.Background(), + name: "NoopTracer_Start", + in2: []SpanStartOption{}, + endIn: []SpanEndOption{}, + }, + want: context.Background(), + want1: NoopSpan{}, + }, { name: "NonRecording", args: args{