railyard/apps/relay/crates/relay-traces/deploy/relay-traces-retention.service
caelum0x ab9e54a189 feat(relay): per-key trace view and OD-RY2 trace retention (RY-RL3)
Implements OSS9. New relay-traces crate reads chat/json inferences by the
GIN-indexed tensorzero::api_key_public_id tag, joined with model_inferences
for model, provider, tokens, latency, cost and finish reason.

- GET /relay/traces: caller's own traces, newest first, keyset paging,
  window bounded (1-2160 h). Operator keys may use scope=all and key=.
- GET /relay/traces/{inference_id}: model calls plus stored bodies; a trace
  owned by another key returns 404, same as a missing one.
- relay-traces-retention: 14 d bodies, 90 d metadata (OD-RY2 defaults, env
  overridable), batched deletes against one cutoff, dry-run mode. Shipped in
  the relay image; systemd service/timer in crates/relay-traces/deploy (not
  installed).
- Relay UI: /observability/keys list (live refresh on the first page) and
  detail page; sidebar "Key Traces".
- No new tables or migrations.

Tests: 8 unit tests; live test on a scratch copy of the inference tables
proves key isolation, operator scope, paging and window-exact retention;
UI vitest 7/7, tsc and eslint clean; cargo check -p gateway clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 02:12:42 +03:00

19 lines
755 B
Desktop File

# Trace retention for Relay (RY-RL3, owner decision OD-RY2).
# Keeps full prompt/output bodies 14 days and trace metadata 90 days.
# Install on box 2 next to the Relay gateway; not enabled by this repo.
[Unit]
Description=Relay trace retention (14 d bodies, 90 d metadata)
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
# Runs inside the Relay container, which already has TENSORZERO_POSTGRES_URL
# from /etc/products/relay.env and reaches `postgres` on products-net.
# Windows are overridable per run; the defaults are the OD-RY2 values.
ExecStart=/usr/bin/docker compose -p railyard exec -T \
-e RELAY_TRACE_BODY_RETENTION_DAYS=14 \
-e RELAY_TRACE_METADATA_RETENTION_DAYS=90 \
relay relay-traces-retention
Nice=10