diff --git a/sdk/trace/tracer.go b/sdk/trace/tracer.go index f4a1f96f3d6..b0c0e6ef361 100644 --- a/sdk/trace/tracer.go +++ b/sdk/trace/tracer.go @@ -37,6 +37,11 @@ var _ trace.Tracer = &tracer{} func (tr *tracer) Start(ctx context.Context, name string, options ...trace.SpanStartOption) (context.Context, trace.Span) { config := trace.NewSpanStartConfig(options...) + // If ctx is nil, set to context.Background() as context.WithValue will panic on a nil value. + if ctx == nil { + ctx = context.Background() + } + // For local spans created by this SDK, track child span count. if p := trace.SpanFromContext(ctx); p != nil { if sdkSpan, ok := p.(*recordingSpan); ok {