mirror of https://github.com/coder/coder.git
feat: add `request_id` to HTTP trace spans (#10145)
This commit is contained in:
parent
2881b8b252
commit
3bbfcc593e
|
@ -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))
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue