diff --git a/go.mod b/go.mod index 1ef3d5c..287c3a9 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 github.com/dgraph-io/badger/v4 v4.2.0 github.com/dustin/go-humanize v1.0.1 + github.com/felixge/httpsnoop v1.0.4 github.com/ipfs-shipyard/nopfs v0.0.12 github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a github.com/ipfs/boxo v0.17.1-0.20240126101119-fdfcfcc0708a @@ -59,7 +60,6 @@ require ( github.com/dgraph-io/ristretto v0.1.1 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/felixge/httpsnoop v1.0.4 // indirect github.com/flynn/noise v1.0.1 // indirect github.com/francoispqt/gojay v1.2.13 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect diff --git a/handlers.go b/handlers.go index 58eb320..2178d82 100644 --- a/handlers.go +++ b/handlers.go @@ -13,6 +13,7 @@ import ( _ "embed" _ "net/http/pprof" + "github.com/felixge/httpsnoop" "github.com/ipfs/boxo/gateway" "github.com/ipfs/boxo/path" servertiming "github.com/mitchellh/go-server-timing" @@ -83,9 +84,8 @@ func withConnect(next http.Handler) http.Handler { func withRequestLogger(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - goLog.Infow(r.Method, "url", r.URL, "host", r.Host) - // TODO: if debug is enabled, show more? goLog.Infow("request received", "url", r.URL, "host", r.Host, "method", r.Method, "ua", r.UserAgent(), "referer", r.Referer()) - next.ServeHTTP(w, r) + m := httpsnoop.CaptureMetrics(next, w, r) + goLog.Infow(r.Method, "url", r.URL, "host", r.Host, "code", m.Code, "duration", m.Duration, "written", m.Written, "ua", r.UserAgent(), "referer", r.Referer()) }) }