Skip to content

Commit 65309c9

Browse files
author
Pawel Brzozowski
committed
fix(api): remove duplicate /api/traces endpoint that broke React UI
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 <paul@ontux.net>
1 parent 884bfb8 commit 65309c9

2 files changed

Lines changed: 3 additions & 21 deletions

File tree

core/http/middleware/trace.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package middleware
33
import (
44
"bytes"
55
"io"
6+
"mime"
67
"net/http"
78
"slices"
89
"sync"
@@ -94,7 +95,8 @@ func TraceMiddleware(app *application.Application) echo.MiddlewareFunc {
9495

9596
initializeTracing(app.ApplicationConfig().TracingMaxItems)
9697

97-
if c.Request().Header.Get("Content-Type") != "application/json" {
98+
ct, _, _ := mime.ParseMediaType(c.Request().Header.Get("Content-Type"))
99+
if ct != "application/json" {
98100
return next(c)
99101
}
100102

core/http/routes/ui_api.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/mudler/LocalAI/core/gallery"
2424
"github.com/mudler/LocalAI/core/http/auth"
2525
"github.com/mudler/LocalAI/core/http/endpoints/localai"
26-
"github.com/mudler/LocalAI/core/http/middleware"
2726
"github.com/mudler/LocalAI/core/p2p"
2827
"github.com/mudler/LocalAI/core/services/galleryop"
2928
"github.com/mudler/LocalAI/pkg/model"
@@ -1397,24 +1396,5 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model
13971396
app.POST("/api/settings", localai.UpdateSettingsEndpoint(applicationInstance), adminMiddleware)
13981397
}
13991398

1400-
// Logs API (admin only)
1401-
app.GET("/api/traces", func(c echo.Context) error {
1402-
if !appConfig.EnableTracing {
1403-
return c.JSON(503, map[string]any{
1404-
"error": "Tracing disabled",
1405-
})
1406-
}
1407-
traces := middleware.GetTraces()
1408-
return c.JSON(200, map[string]any{
1409-
"traces": traces,
1410-
})
1411-
}, adminMiddleware)
1412-
1413-
app.POST("/api/traces/clear", func(c echo.Context) error {
1414-
middleware.ClearTraces()
1415-
return c.JSON(200, map[string]any{
1416-
"message": "Traces cleared",
1417-
})
1418-
}, adminMiddleware)
14191399
}
14201400

0 commit comments

Comments
 (0)