mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: tracing improvements (#4988)
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
package httpmw
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@ -11,9 +13,13 @@ import (
|
||||
|
||||
func Logger(log slog.Logger) func(next http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
sw := &tracing.StatusWriter{ResponseWriter: w}
|
||||
|
||||
sw, ok := rw.(*tracing.StatusWriter)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("ResponseWriter not a *tracing.StatusWriter; got %T", rw))
|
||||
}
|
||||
|
||||
httplog := log.With(
|
||||
slog.F("host", httpapi.RequestHost(r)),
|
||||
@ -51,7 +57,11 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
|
||||
logLevelFn = httplog.Warn
|
||||
}
|
||||
|
||||
logLevelFn(r.Context(), r.Method)
|
||||
// We already capture most of this information in the span (minus
|
||||
// the response body which we don't want to capture anyways).
|
||||
tracing.RunWithoutSpan(r.Context(), func(ctx context.Context) {
|
||||
logLevelFn(ctx, r.Method)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user