Created
February 8, 2023 23:10
-
-
Save yurishkuro/7d00baca7e5745394ddb1843dd41c25b to your computer and use it in GitHub Desktop.
HotROD external baggage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (tm *TracedServeMux) AddHandler(pattern string, handler http.Handler) { | |
middleware := nethttp.Middleware(tm.tracer, handler, | |
nethttp.MWSpanObserver(func(span opentracing.Span, r *http.Request) { | |
if !tm.copyBaggage { | |
return | |
} | |
bag := baggage.FromContext(r.Context()) | |
for _, m := range bag.Members() { | |
span.SetBaggageItem(m.Key(), m.Value()) | |
} | |
}), | |
) | |
} | |
func otelBaggageExtractor(next http.Handler) http.Handler { | |
propagator := propagation.Baggage{} | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
carrier := propagation.HeaderCarrier(r.Header) | |
ctx := propagator.Extract(r.Context(), carrier) | |
r = r.WithContext(ctx) | |
next.ServeHTTP(w, r) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment