From ecf85fde9e212ef839da7d84c12f48a0cc2fa270 Mon Sep 17 00:00:00 2001 From: pjbrzozowski Date: Mon, 20 Apr 2026 18:44:49 +0200 Subject: [PATCH] fix(api): remove duplicate /api/traces endpoint that broke React UI (#9427) The API Traces tab in /app/traces always showed (0) traces despite requests being recorded. The /api/traces endpoint was registered in both localai.go and ui_api.go. The ui_api.go version wrapped the response as {"traces": [...]} instead of the flat []APIExchange array that both the React UI (Traces.jsx) and the legacy Alpine.js UI (traces.html) expect. Because Echo matched the ui_api.go handler, Array.isArray(apiData) always returned false, making the API Traces tab permanently empty. Remove the duplicate endpoints from ui_api.go so only the correct flat-array version in localai.go is served. Also use mime.ParseMediaType for the Content-Type check in the trace middleware so requests with parameters (e.g. application/json; charset=utf-8) are still traced. Signed-off-by: Pawel Brzozowski Co-authored-by: Pawel Brzozowski --- core/http/middleware/trace.go | 4 +++- core/http/routes/ui_api.go | 20 -------------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/core/http/middleware/trace.go b/core/http/middleware/trace.go index 71a12d976..ef3dd891d 100644 --- a/core/http/middleware/trace.go +++ b/core/http/middleware/trace.go @@ -3,6 +3,7 @@ package middleware import ( "bytes" "io" + "mime" "net/http" "slices" "sync" @@ -94,7 +95,8 @@ func TraceMiddleware(app *application.Application) echo.MiddlewareFunc { initializeTracing(app.ApplicationConfig().TracingMaxItems) - if c.Request().Header.Get("Content-Type") != "application/json" { + ct, _, _ := mime.ParseMediaType(c.Request().Header.Get("Content-Type")) + if ct != "application/json" { return next(c) } diff --git a/core/http/routes/ui_api.go b/core/http/routes/ui_api.go index 8d089f873..159b535f5 100644 --- a/core/http/routes/ui_api.go +++ b/core/http/routes/ui_api.go @@ -23,7 +23,6 @@ import ( "github.com/mudler/LocalAI/core/gallery" "github.com/mudler/LocalAI/core/http/auth" "github.com/mudler/LocalAI/core/http/endpoints/localai" - "github.com/mudler/LocalAI/core/http/middleware" "github.com/mudler/LocalAI/core/p2p" "github.com/mudler/LocalAI/core/services/galleryop" "github.com/mudler/LocalAI/pkg/model" @@ -1458,24 +1457,5 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model app.POST("/api/settings", localai.UpdateSettingsEndpoint(applicationInstance), adminMiddleware) } - // Logs API (admin only) - app.GET("/api/traces", func(c echo.Context) error { - if !appConfig.EnableTracing { - return c.JSON(503, map[string]any{ - "error": "Tracing disabled", - }) - } - traces := middleware.GetTraces() - return c.JSON(200, map[string]any{ - "traces": traces, - }) - }, adminMiddleware) - - app.POST("/api/traces/clear", func(c echo.Context) error { - middleware.ClearTraces() - return c.JSON(200, map[string]any{ - "message": "Traces cleared", - }) - }, adminMiddleware) }