mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-10 18:37:00 +00:00
feat(middleware): use trace_id as correlation id, if available
Co-authored-by: sindrerh2 <sindre.rodseth.hansen@nav.no>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
chi_middleware "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/google/uuid"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func CorrelationIDHandler(next http.Handler) http.Handler {
|
||||
@@ -16,6 +17,11 @@ func CorrelationIDHandler(next http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
span := trace.SpanFromContext(ctx)
|
||||
if span.SpanContext().HasTraceID() {
|
||||
id = span.SpanContext().TraceID().String()
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, chi_middleware.RequestIDKey, id)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user