mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 11:07:40 +01:00
feat(system): Recent telemetry card surfaces debug_logs on /system
I've been writing every failure/heartbeat into debug_logs across five
sources (api/inject, api/orchestration/run, api/control/dispatch,
api/crons/prune-debug-logs, auth) but the user had no UI to see any of
it — would have to SQL the table by hand.
Mount a Suspense-wrapped server-component card at the bottom of /system:
- Last 10 rows via getRecentDebugLogs
- Per-row: relative time · source · level icon · truncated message
- Header right-side counter: "N errors" in red OR "all clear" in muted
- EmptyState when no telemetry yet
- LEVEL_TONE map for icon + color (error red, warn amber, info muted)
- title attribute on message for hover-to-see-full-text on desktop
No client poll — the card re-renders on PullToRefresh / RefreshOnFocus
gestures which we already wired earlier. Pivoted away from the previous
session next: (Edge-middleware → Node forwarder for cookie-401 telemetry)
because the forensics value is marginal — the user-facing failure is
already visible via 9c2525c — and the forwarder adds a real DoS-amplification
surface (bots probing /api/* would spam debug_logs through it). Better
spend: make the telemetry I already have visible.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2 files changed
+69
No files matched your search
@@ -3,6 +3,7 @@ import { PageLayout } from "@/components/ui/page-layout";
|
||||
import { SystemStats } from "@/components/system/SystemStats";
|
||||
import { AutopilotCard } from "@/components/system/AutopilotCard";
|
||||
import { MemorySummaryCard } from "@/components/system/MemorySummaryCard";
|
||||
import { RecentFailuresCard } from "@/components/system/RecentFailuresCard";
|
||||
import { CardSkeleton } from "@/components/ui/card";
|
||||
import { readCronJobs } from "@/lib/crons";
|
||||
import { PullToRefresh } from "@/components/shared/PullToRefresh";
|
||||
@@ -20,6 +21,9 @@ export default function SystemPage() {
|
||||
<Suspense fallback={<CardSkeleton />}>
|
||||
<MemorySummaryCard />
|
||||
</Suspense>
|
||||
<Suspense fallback={<CardSkeleton />}>
|
||||
<RecentFailuresCard />
|
||||
</Suspense>
|
||||
</PageLayout>
|
||||
</PullToRefresh>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { AlertCircle, AlertTriangle, Info } from "lucide-react";
|
||||
import { Card, CardHeader } from "@/components/ui/card";
|
||||
import { EmptyState } from "@/components/ui/empty-state";
|
||||
import { getRecentDebugLogs } from "@/db/queries/debug-logs";
|
||||
import { compactRelativeDate } from "@/lib/dates";
|
||||
|
||||
/**
|
||||
* Surfaces the last ~10 debug_logs rows on /system so the user can see live
|
||||
* telemetry without querying the DB manually. Sources currently emitting:
|
||||
* - api/inject (unknown tab, route-level 401, exec failure)
|
||||
* - api/orchestration/run (claude/codex/gemini inject + openclaw worker)
|
||||
* - api/control/dispatch (Groq fallback)
|
||||
* - api/crons/prune-debug-logs (daily janitor heartbeat)
|
||||
* - auth (Auth.js signIn errors and org-bootstrap fails)
|
||||
*
|
||||
* Server-component reads — no client poll, no fetch — re-renders whenever
|
||||
* the page revalidates (PullToRefresh or RefreshOnFocus).
|
||||
*/
|
||||
|
||||
const LEVEL_TONE: Record<string, { icon: typeof Info; cls: string }> = {
|
||||
error: { icon: AlertCircle, cls: "text-status-negative" },
|
||||
warn: { icon: AlertTriangle, cls: "text-status-warning" },
|
||||
info: { icon: Info, cls: "text-text-tertiary" },
|
||||
};
|
||||
|
||||
export async function RecentFailuresCard() {
|
||||
const rows = await getRecentDebugLogs(10).catch(() => []);
|
||||
const errorCount = rows.filter((r) => r.level === "error").length;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader
|
||||
icon={AlertCircle}
|
||||
title="Recent telemetry"
|
||||
right={
|
||||
errorCount > 0
|
||||
? <span className="text-xs font-medium text-status-negative">{errorCount} error{errorCount === 1 ? "" : "s"}</span>
|
||||
: <span className="text-xs text-text-tertiary">all clear</span>
|
||||
}
|
||||
/>
|
||||
{rows.length === 0 ? (
|
||||
<EmptyState>No recent telemetry events</EmptyState>
|
||||
) : (
|
||||
<ul className="space-y-1.5">
|
||||
{rows.map((row) => {
|
||||
const tone = LEVEL_TONE[row.level] ?? LEVEL_TONE.info;
|
||||
const Icon = tone.icon;
|
||||
return (
|
||||
<li key={row.id} className="flex items-start gap-2 text-xs">
|
||||
<Icon className={`mt-0.5 h-3 w-3 shrink-0 ${tone.cls}`} />
|
||||
<span className="shrink-0 font-mono text-text-tertiary">
|
||||
{compactRelativeDate(row.createdAt)}
|
||||
</span>
|
||||
<span className="shrink-0 text-text-muted">{row.source}</span>
|
||||
<span className="min-w-0 flex-1 truncate text-text-secondary" title={row.message}>
|
||||
{row.message}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user