minor edits to http constants to support future spec compliance

This commit is contained in:
Mya 2022-12-19 12:15:52 -06:00
parent 1c628d975c
commit 5db48b5b61
No known key found for this signature in database
GPG Key ID: C3ECFA648DAD27FA

@ -28,10 +28,10 @@ import (
) )
const ( const (
// TraceIDHeader is a string constant that defines a common key used to propagate an okit trace. // OkitTraceIDHeader is a string constant that defines a common key used to propagate an okit trace.
TraceIDHeader = "x-okit-trace-id" OkitTraceIDHeader = "x-okit-trace-id"
// SpanIDHeader is a string constant that defines a common key used to propagate the parent span. // OkitSpanIDHeader is a string constant that defines a common key used to propagate the parent span.
SpanIDHeader = "x-okit-span-id" OkitSpanIDHeader = "x-okit-span-id"
) )
// InstrumentClient updates the provided http.Client to use an instrumented http.RoundTripper. If the provided // 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() defer okit.Trace(&ctx, tags...).Done()
// propagate to server // propagate to server
// TODO: support spec compliant propagation
if v := ctx.Value(okit.SpanKey); v != nil { if v := ctx.Value(okit.SpanKey); v != nil {
if span, ok := v.(okit.Span); ok { if span, ok := v.(okit.Span); ok {
req.Header.Set(TraceIDHeader, span.TraceID) req.Header.Set(OkitTraceIDHeader, span.TraceID)
req.Header.Set(SpanIDHeader, span.ID) req.Header.Set(OkitSpanIDHeader, span.ID)
} }
} }
@ -98,8 +100,8 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
// propagation from client // propagation from client
traceID := r.Header.Get(TraceIDHeader) traceID := r.Header.Get(OkitTraceIDHeader)
spanID := r.Header.Get(SpanIDHeader) spanID := r.Header.Get(OkitSpanIDHeader)
if traceID != "" && spanID != "" { if traceID != "" && spanID != "" {
ctx = context.WithValue(ctx, okit.SpanKey, okit.Span{ ctx = context.WithValue(ctx, okit.SpanKey, okit.Span{
TraceID: traceID, TraceID: traceID,