diff --git a/internal/api/handler.go b/internal/api/handler.go index 76d948551..ba961fe4a 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -676,8 +676,8 @@ func NewHandler(staticDir fs.FS, jsSettings JSSettings, showInvisible bool, chV1 return h, nil } -func (h *Handler) savePanic(err any, stack []byte) { - v := error500{time.Now(), err, stack} +func (h *Handler) savePanic(requestURI string, err any, stack []byte) { + v := error500{time: time.Now(), requestURI: requestURI, what: err, stack: stack} h.errorsMu.Lock() h.errors[h.errorX] = v h.errorX = (h.errorX + 1) % len(h.errors) @@ -2031,7 +2031,7 @@ func (h *requestHandler) queryBadges(ctx context.Context, req seriesRequest, met defer func() { var code int if r := recover(); r != nil { - h.savePanic(r, debug.Stack()) + h.savePanic("/api/badges", r, debug.Stack()) code = 500 } else { code = httpCode(err) diff --git a/internal/api/http_router.go b/internal/api/http_router.go index 3889044de..160e67d2e 100644 --- a/internal/api/http_router.go +++ b/internal/api/http_router.go @@ -47,9 +47,10 @@ type httpResponseWriter struct { } type error500 struct { - time time.Time - what any - stack []byte + time time.Time + requestURI string + what any + stack []byte } func NewHTTPRouter(h *Handler) httpRouter { @@ -132,7 +133,7 @@ func (r *httpRoute) handle(w http.ResponseWriter, req *http.Request) { if !h.w.statusCodeSent { http.Error(&h.w, fmt.Sprint(err), http.StatusInternalServerError) } - h.savePanic(err, debug.Stack()) + h.savePanic(req.RequestURI, err, debug.Stack()) } h.endpointStat.report(h.w.statusCode, format.BuiltinMetricNameAPIResponseTime) }() @@ -154,6 +155,7 @@ func DumpInternalServerErrors(r *httpRequestHandler) { defer r.errorsMu.RUnlock() for i := 0; i < len(r.errors) && r.errors[i].what != nil; i++ { w.Write([]byte("# \n")) + w.Write([]byte("# " + r.errors[i].requestURI + " \n")) w.Write([]byte(fmt.Sprintf("# %s \n", r.errors[i].what))) w.Write([]byte("# " + r.errors[i].time.Format(time.RFC3339) + " \n")) w.Write([]byte("# \n")) diff --git a/internal/api/rpc_handler.go b/internal/api/rpc_handler.go index 911bea95a..9fba4f6dd 100644 --- a/internal/api/rpc_handler.go +++ b/internal/api/rpc_handler.go @@ -70,7 +70,7 @@ func (h *rpcRouter) Handle(ctx context.Context, hctx *rpc.HandlerContext) (err e defer func() { var code int // "0" means "success" if r := recover(); r != nil { - w.savePanic(r, debug.Stack()) + w.savePanic(hctx.RequestFunctionName, r, debug.Stack()) code = rpc.TlErrorInternal err = &rpc.Error{Code: rpc.TlErrorInternal} } else if err != nil {