Skip to content

Commit ecf85fd

Browse files
pjbrzozowskiPawel Brzozowski
andauthored
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 <paul@ontux.net> Co-authored-by: Pawel Brzozowski <paul@ontux.net>
1 parent 6480715 commit ecf85fd

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

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"
@@ -1458,24 +1457,5 @@ func RegisterUIAPIRoutes(app *echo.Echo, cl *config.ModelConfigLoader, ml *model
14581457
app.POST("/api/settings", localai.UpdateSettingsEndpoint(applicationInstance), adminMiddleware)
14591458
}
14601459

1461-
// Logs API (admin only)
1462-
app.GET("/api/traces", func(c echo.Context) error {
1463-
if !appConfig.EnableTracing {
1464-
return c.JSON(503, map[string]any{
1465-
"error": "Tracing disabled",
1466-
})
1467-
}
1468-
traces := middleware.GetTraces()
1469-
return c.JSON(200, map[string]any{
1470-
"traces": traces,
1471-
})
1472-
}, adminMiddleware)
1473-
1474-
app.POST("/api/traces/clear", func(c echo.Context) error {
1475-
middleware.ClearTraces()
1476-
return c.JSON(200, map[string]any{
1477-
"message": "Traces cleared",
1478-
})
1479-
}, adminMiddleware)
14801460
}
14811461

0 commit comments

Comments
 (0)