create span regardless of a context or not

This commit is contained in:
A.Unger
2020-03-09 15:35:02 +01:00
parent 7e0d3cab34
commit 855a3e006e

View File

@@ -14,10 +14,15 @@ func Trace(next http.Handler) http.Handler {
var span *trace.Span
tc := tracecontext.HTTPFormat{}
sc, ok := tc.SpanContextFromRequest(r)
if ok {
// reconstruct span context from request
if sc, ok := tc.SpanContextFromRequest(r); ok {
// if there is one, add it to the new span
ctx, span = trace.StartSpanWithRemoteParent(r.Context(), r.URL.String(), sc)
defer span.End()
} else {
// create a new span if there is no context
ctx, span = trace.StartSpan(r.Context(), r.URL.String())
defer span.End()
}
next.ServeHTTP(w, r.WithContext(ctx))