diff --git a/pkg/service/v0/tracing.go b/pkg/service/v0/tracing.go index e9f2240ffd..73a8487c40 100644 --- a/pkg/service/v0/tracing.go +++ b/pkg/service/v0/tracing.go @@ -1,6 +1,7 @@ package svc import ( + "context" "net/http" "go.opencensus.io/plugin/ochttp/propagation/tracecontext" @@ -20,11 +21,14 @@ type tracing struct { // ServeHTTP implements the Service interface. func (t tracing) ServeHTTP(w http.ResponseWriter, r *http.Request) { + var ctx context.Context + var span *trace.Span tp := tracecontext.HTTPFormat{} - sc, _ := tp.SpanContextFromRequest(r) - - ctx, span := trace.StartSpanWithRemoteParent(r.Context(), r.URL.String(), sc) - defer span.End() + sc, ok := tp.SpanContextFromRequest(r) + if ok { + ctx, span = trace.StartSpanWithRemoteParent(r.Context(), r.URL.String(), sc) + defer span.End() + } t.next.ServeHTTP(w, r.WithContext(ctx)) }