mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: add request_id
to HTTP trace spans (#10145)
This commit is contained in:
@ -5,6 +5,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"cdr.dev/slog"
|
||||
)
|
||||
@ -29,6 +31,9 @@ func AttachRequestID(next http.Handler) http.Handler {
|
||||
ctx := context.WithValue(r.Context(), requestIDContextKey{}, rid)
|
||||
ctx = slog.With(ctx, slog.F("request_id", rid))
|
||||
|
||||
trace.SpanFromContext(ctx).
|
||||
SetAttributes(attribute.String("request_id", rid.String()))
|
||||
|
||||
rw.Header().Set("X-Coder-Request-Id", ridString)
|
||||
next.ServeHTTP(rw, r.WithContext(ctx))
|
||||
})
|
||||
|
Reference in New Issue
Block a user