diff --git a/contrib/cloud.google.com/go/pubsub.v1/tracing.go b/contrib/cloud.google.com/go/pubsub.v1/tracing.go index 604f9ceefa..4f38879d68 100644 --- a/contrib/cloud.google.com/go/pubsub.v1/tracing.go +++ b/contrib/cloud.google.com/go/pubsub.v1/tracing.go @@ -118,7 +118,7 @@ func TraceReceiveFunc(s Subscription, opts ...Option) func(ctx context.Context, opts = append(opts, tracer.Measured()) } // If there are span links as a result of context extraction, add them as a StartSpanOption - if parentSpanCtx.SpanLinks() != nil { + if parentSpanCtx != nil && parentSpanCtx.SpanLinks() != nil { opts = append(opts, tracer.WithSpanLinks(parentSpanCtx.SpanLinks())) } span, ctx := tracer.StartSpanFromContext(ctx, cfg.receiveSpanName, opts...)