-
Notifications
You must be signed in to change notification settings - Fork 248
HTTP Method always blank in "Backend Performance"Β #923
Copy link
Copy link
Closed
Description
I configured Sentry to record performance. Overall this works reasonably well, but the HTTP method is always blank:
Try as I might, I just can't get it to show up; my little middleware:
func metrics() func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Get path from router, so "/api/2/roles/4" shows up as "/api/2/roles/{role_id}"
rctx := chi.RouteContext(r.Context())
p := rctx.RoutePath
if p == "" && len(rctx.RoutePatterns) > 0 {
p = rctx.RoutePatterns[0]
}
if p == "" {
p = r.URL.Path
}
if r.Method == "" {
r.Method = "GET"
}
tx := sentry.StartTransaction(r.Context(), r.Method+" "+p,
sentry.WithOpName("http.server"),
sentry.ContinueFromRequest(r),
sentry.WithTransactionSource(sentry.SourceRoute))
tx.Data = map[string]any{
"http.method": r.Method,
"httpmethod": r.Method,
"http_method": r.Method,
"method": r.Method,
}
tx.Tags = map[string]string{
"http.method": r.Method,
"httpmethod": r.Method,
"http_method": r.Method,
"method": r.Method,
}
defer tx.Finish()
*r = *r.WithContext(tx.Context())
next.ServeHTTP(w, r)
type statusWriter interface{ Status() int }
ww, ok := w.(statusWriter)
if ok && ww.Status() > 0 {
tx.Status = sentry.HTTPtoSpanStatus(ww.Status())
}
})
}
}
Those Data and Tags fields get recorded, but not as the method:
I suppose just GET /api/2/collections/{collection_id} is workable, but it looks very odd.
I'm not sure if I'm doing anything wrong or if it's a bug in the Go library?
Using 0.30.0 of this library. With Go 1.23.4.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
No status


