feat: trace httpapi.{Read,Write} (#4134)

This commit is contained in:
Colin Adler
2022-09-21 17:07:00 -05:00
committed by GitHub
parent 1bf2dc0cc3
commit 5de6f86959
45 changed files with 919 additions and 774 deletions

View File

@ -24,11 +24,12 @@ func RequestID(r *http.Request) uuid.UUID {
func AttachRequestID(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rid := uuid.New()
ridString := rid.String()
ctx := context.WithValue(r.Context(), requestIDContextKey{}, rid)
ctx = slog.With(ctx, slog.F("request_id", rid))
rw.Header().Set("X-Coder-Request-Id", rid.String())
rw.Header().Set("X-Coder-Request-Id", ridString)
next.ServeHTTP(rw, r.WithContext(ctx))
})
}