ignore not okay context decoding

This commit is contained in:
A.Unger
2020-03-06 16:34:18 +01:00
committed by Ilja Neumann
parent 6c8e3ffc77
commit 2dcddd2286

View File

@@ -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))
}