@@ -26,19 +26,28 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
26
26
slog .F ("path" , r .URL .Path ),
27
27
slog .F ("proto" , r .Proto ),
28
28
slog .F ("remote_addr" , r .RemoteAddr ),
29
+ // Include the start timestamp in the log so that we have the
30
+ // source of truth. There is at least a theoretical chance that
31
+ // there can be a delay between `next.ServeHTTP` ending and us
32
+ // actually logging the request. This can also be useful when
33
+ // filtering logs that started at a certain time (compared to
34
+ // trying to compute the value).
35
+ slog .F ("start" , start ),
29
36
)
30
37
31
38
next .ServeHTTP (sw , r )
32
39
40
+ end := time .Now ()
41
+
33
42
// Don't log successful health check requests.
34
43
if r .URL .Path == "/api/v2" && sw .Status == http .StatusOK {
35
44
return
36
45
}
37
46
38
47
httplog = httplog .With (
39
- slog .F ("took" , time . Since (start )),
48
+ slog .F ("took" , end . Sub (start )),
40
49
slog .F ("status_code" , sw .Status ),
41
- slog .F ("latency_ms" , float64 (time . Since (start )/ time .Millisecond )),
50
+ slog .F ("latency_ms" , float64 (end . Sub (start )/ time .Millisecond )),
42
51
)
43
52
44
53
// For status codes 400 and higher we
0 commit comments