From 5db48b5b610f46ee04b4317cab63aad7bb75358e Mon Sep 17 00:00:00 2001 From: Mya Pitzeruse Date: Mon, 19 Dec 2022 12:15:52 -0600 Subject: [PATCH] minor edits to http constants to support future spec compliance --- http/instrumentation.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/http/instrumentation.go b/http/instrumentation.go index efa7bb1..0f2e6a4 100644 --- a/http/instrumentation.go +++ b/http/instrumentation.go @@ -28,10 +28,10 @@ import ( ) const ( - // TraceIDHeader is a string constant that defines a common key used to propagate an okit trace. - TraceIDHeader = "x-okit-trace-id" - // SpanIDHeader is a string constant that defines a common key used to propagate the parent span. - SpanIDHeader = "x-okit-span-id" + // OkitTraceIDHeader is a string constant that defines a common key used to propagate an okit trace. + OkitTraceIDHeader = "x-okit-trace-id" + // OkitSpanIDHeader is a string constant that defines a common key used to propagate the parent span. + OkitSpanIDHeader = "x-okit-span-id" ) // InstrumentClient updates the provided http.Client to use an instrumented http.RoundTripper. If the provided @@ -66,10 +66,12 @@ func (r *roundTripper) RoundTrip(req *http.Request) (resp *http.Response, err er defer okit.Trace(&ctx, tags...).Done() // propagate to server + // TODO: support spec compliant propagation + if v := ctx.Value(okit.SpanKey); v != nil { if span, ok := v.(okit.Span); ok { - req.Header.Set(TraceIDHeader, span.TraceID) - req.Header.Set(SpanIDHeader, span.ID) + req.Header.Set(OkitTraceIDHeader, span.TraceID) + req.Header.Set(OkitSpanIDHeader, span.ID) } } @@ -98,8 +100,8 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx := r.Context() // propagation from client - traceID := r.Header.Get(TraceIDHeader) - spanID := r.Header.Get(SpanIDHeader) + traceID := r.Header.Get(OkitTraceIDHeader) + spanID := r.Header.Get(OkitSpanIDHeader) if traceID != "" && spanID != "" { ctx = context.WithValue(ctx, okit.SpanKey, okit.Span{ TraceID: traceID,