-
Notifications
You must be signed in to change notification settings - Fork 899
feat: tracing improvements #4988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f1affbe
032f1cf
d892c21
7383e8c
343e27d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package httpmw | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
|
@@ -12,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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's runtime, right? Isn't it risky to panic here? I understand that you assume that it will be recovered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The response writer will always be a We also already do this exact panic in the tracing middleware too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I admit that I'm not a fan of it, but I understand why it's safe here 👍 |
||
} | ||
|
||
httplog := log.With( | ||
slog.F("host", httpapi.RequestHost(r)), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will trace every static HTTP file... is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a filter within the middleware itself (and a test) to ensure that this is skipped on non-API routes.