From 2dcddd2286637036302a3dcc0661082bb01e57ac Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 6 Mar 2020 16:34:18 +0100 Subject: [PATCH] ignore not okay context decoding --- pkg/service/v0/tracing.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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)) }