Skip to content

feat(tracing): persist bounded trace histories - #11203

Merged
mudler merged 2 commits into
masterfrom
bot/issue-9308-persist-traces
Jul 30, 2026
Merged

feat(tracing): persist bounded trace histories#11203
mudler merged 2 commits into
masterfrom
bot/issue-9308-persist-traces

Conversation

@localai-org-maint-bot

Copy link
Copy Markdown
Collaborator

Description

This PR fixes #9308.

API and backend trace histories now persist under the configured data path and are restored across LocalAI restarts. Persistence keeps the existing independent tracing_max_items bounds, advances restored numeric IDs to avoid collisions, skips corrupt records without blocking startup, and serializes clear operations with the asynchronous trace consumers so memory and disk are cleared together.

Notes for Reviewers

  • Uses bounded per-record JSON files under traces/api and traces/backend, so this works with or without authentication and adds no database dependency.
  • Trace writes remain off request/backend execution paths. API restore occurs when middleware is constructed; backend storage is configured at application startup and initialized when tracing is used.
  • Added Ginkgo coverage for bounded eviction, corrupt-record recovery, restoration/ID advancement, and clear barriers.
  • Verified with go test -count=1 ./core/trace/tracepersist ./core/trace ./core/http/middleware ./core/application and go vet for the same packages.

Signed commits

  • Yes, I signed my commits.
  • Documentation updated (docs/content/) for user-facing changes, or not applicable

Assisted-by: Codex:gpt-5

Retain API and backend traces below the data path, restore them at initialization, and serialize clears with asynchronous consumers.

Assisted-by: Codex:gpt-5
}
records := make([]T, 0, len(files))
for _, name := range files {
data, err := os.ReadFile(filepath.Join(s.dir, name))
Document why persisted filenames cannot escape the trace directory and explicitly ignore the best-effort temporary-file cleanup result.

Assisted-by: Codex:gpt-5 [golangci-lint]
@mudler
mudler merged commit 1189c68 into master Jul 30, 2026
10 of 23 checks passed
@mudler
mudler deleted the bot/issue-9308-persist-traces branch July 30, 2026 10:20
@localai-bot localai-bot added the enhancement New feature or request label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traces are lost when restarting the service

4 participants