Open History to see the last commit
1import {
2 AlertTriangleIcon,
3 ChevronDownIcon,
4 ChevronRightIcon,
5 CopyIcon,
6 FolderOpenIcon,
7 InfoIcon,
8 RefreshCwIcon,
9} from "lucide-react";
10import { useAtomValue } from "@effect/atom-react";
11import {
12 isAtomCommandInterrupted,
13 squashAtomCommandFailure,
14} from "@t3tools/client-runtime/state/runtime";
15import { useCallback, useMemo, useRef, useState, type ReactNode } from "react";
16import type {
17 ServerProcessDiagnosticsEntry,
18 ServerProcessResourceHistorySummary,
19 ServerProcessSignal,
20} from "@t3tools/contracts";
21import * as DateTime from "effect/DateTime";
22import * as Option from "effect/Option";
23
24import { cn } from "../../lib/utils";
25import { ensureLocalApi } from "../../localApi";
26import { resolveAndPersistPreferredEditor } from "../../editorPreferences";
27import { formatRelativeTimeLabel, getRelativeTimeState } from "../../timestampFormat";
28import { useEnvironmentQuery } from "../../state/query";
29import {
30 primaryServerAvailableEditorsAtom,
31 primaryServerObservabilityAtom,
32 serverEnvironment,
33} from "../../state/server";
34import { shellEnvironment } from "../../state/shell";
35import { usePrimaryEnvironment } from "../../state/environments";
36import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
37import { Button } from "../ui/button";
38import { ScrollArea } from "../ui/scroll-area";
39import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
40import { toastManager } from "../ui/toast";
41import { ResourceTelemetryDiagnostics } from "./ResourceTelemetryDiagnostics";
42import { SettingsPageContainer, SettingsSection, useRelativeTimeTick } from "./settingsLayout";
43import { useAtomCommand } from "../../state/use-atom-command";
44
45const NUMBER_FORMAT = new Intl.NumberFormat();
46
47function formatCount(value: number): string {
48 return NUMBER_FORMAT.format(value);
49}
50
51function formatDuration(value: number): string {
52 if (value < 1_000) return `${Math.round(value)} ms`;
53 return `${(value / 1_000).toFixed(value >= 10_000 ? 1 : 2)} s`;
54}
55
56function formatBytes(value: number): string {
57 if (value < 1024) return `${value} B`;
58 const units = ["KB", "MB", "GB"] as const;
59 let unitIndex = -1;
60 let next = value;
61 do {
62 next /= 1024;
63 unitIndex += 1;
64 } while (next >= 1024 && unitIndex < units.length - 1);
65 return `${next.toFixed(next >= 10 ? 1 : 2)} ${units[unitIndex]}`;
66}
67
68function formatRelative(value: DateTime.Utc | null): string {
69 if (!value) return "No trace records";
70 return formatRelativeTimeLabel(DateTime.formatIso(value));
71}
72
73function formatRelativeNoWrap(value: DateTime.Utc | null): string {
74 return formatRelative(value).replaceAll(" ", "\u00a0");
75}
76
77function shortenTraceId(traceId: string): string {
78 if (traceId.length <= 32) return traceId;
79 return `${traceId.slice(0, 18)}...${traceId.slice(-10)}`;
80}
81
82function isStaleProcessSignalMessage(message: string | undefined): boolean {
83 return message?.includes("not a live descendant") ?? false;
84}
85
86function StatBlock({
87 label,
88 value,
89 tooltip,
90 tone = "default",
91}: {
92 label: string;
93 value: string;
94 tooltip?: ReactNode;
95 tone?: "default" | "warning" | "danger";
96}) {
97 return (
98 <div className="min-w-0 border-border/60 px-4 py-3 sm:px-5">
99 <div className="flex min-w-0 items-center gap-1.5 text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground/70">
100 <span className="min-w-0 truncate">{label}</span>
101 {tooltip ? (
102 <Tooltip>
103 <TooltipTrigger
104 render={
105 <button
106 type="button"
107 className="cursor-pointer inline-flex size-3.5 shrink-0 items-center justify-center rounded-sm text-muted-foreground/60 hover:text-foreground"
108 aria-label={`${label} details`}
109 >
110 <InfoIcon className="size-3" />
111 </button>
112 }
113 />
114 <TooltipPopup
115 side="top"
116 className="max-w-[min(300px,calc(100vw-2rem))] whitespace-normal text-left text-[11px] leading-relaxed text-wrap"
117 >
118 {tooltip}
119 </TooltipPopup>
120 </Tooltip>
121 ) : null}
122 </div>
123 <div
124 className={cn(
125 "mt-1 truncate font-mono text-lg font-semibold tabular-nums text-foreground",
126 tone === "warning" && "text-amber-600 dark:text-amber-400",
127 tone === "danger" && "text-destructive",
128 )}
129 >
130 {value}
131 </div>
132 </div>
133 );
134}
135
136function StatsGrid({ children }: { children: ReactNode }) {
137 return (
138 <div className="relative grid grid-cols-2 sm:grid-cols-4">
139 <span
140 className="pointer-events-none absolute inset-y-0 left-1/2 w-px bg-border/60"
141 aria-hidden
142 />
143 <span
144 className="pointer-events-none absolute inset-x-0 top-1/2 h-px bg-border/60 sm:hidden"
145 aria-hidden
146 />
147 <span
148 className="pointer-events-none absolute inset-y-0 left-1/4 hidden w-px bg-border/60 sm:block"
149 aria-hidden
150 />
151 <span
152 className="pointer-events-none absolute inset-y-0 left-3/4 hidden w-px bg-border/60 sm:block"
153 aria-hidden
154 />
155 {children}
156 </div>
157 );
158}
159
160function EmptyRows({ label }: { label: string }) {
161 return <div className="px-4 py-4 text-xs text-muted-foreground sm:px-5">{label}</div>;
162}
163
164function ExpandableText({
165 text,
166 className,
167 collapsedClassName = "line-clamp-3",
168 expandLabel = "Show full error",
169}: {
170 text: string;
171 className?: string;
172 collapsedClassName?: string;
173 expandLabel?: string;
174}) {
175 const [expanded, setExpanded] = useState(false);
176 const canExpand = text.length > 180 || text.includes("\n");
177
178 return (
179 <div className={cn("min-w-0", className)}>
180 <div
181 className={cn(
182 "whitespace-pre-wrap break-words",
183 !expanded && canExpand ? collapsedClassName : null,
184 )}
185 >
186 {text}
187 </div>
188 {canExpand ? (
189 <button
190 type="button"
191 className="cursor-pointer mt-1 text-[11px] font-medium text-foreground/70 underline-offset-2 hover:text-foreground hover:underline"
192 onClick={() => setExpanded((value) => !value)}
193 >
194 {expanded ? "Show less" : expandLabel}
195 </button>
196 ) : null}
197 </div>
198 );
199}
200
201function DiagnosticsTable({
202 headers,
203 children,
204 minTableWidth = "min-w-[640px]",
205 columnWidths,
206}: {
207 headers: ReadonlyArray<string>;
208 children: ReactNode;
209 minTableWidth?: string;
210 columnWidths?: ReadonlyArray<string>;
211}) {
212 return (
213 <ScrollArea
214 chainVerticalScroll
215 scrollFade
216 hideScrollbars
217 className="w-full max-w-full rounded-none"
218 >
219 <table
220 className={cn("w-full text-left text-xs", minTableWidth, columnWidths && "table-fixed")}
221 >
222 {columnWidths ? (
223 <colgroup>
224 {headers.map((header, index) => (
225 <col key={header} className={columnWidths[index]} />
226 ))}
227 </colgroup>
228 ) : null}
229 <thead className="border-b border-border/60 text-[11px] uppercase tracking-[0.08em] text-muted-foreground/70">
230 <tr>
231 {headers.map((header, index) => (
232 <th
233 key={header}
234 className={cn(
235 "whitespace-nowrap px-4 py-2.5 font-semibold first:sm:pl-5 last:sm:pr-5",
236 !columnWidths && index === headers.length - 1 && "w-px",
237 )}
238 >
239 {header.replaceAll(" ", "\u00a0")}
240 </th>
241 ))}
242 </tr>
243 </thead>
244 <tbody className="divide-y divide-border/60">{children}</tbody>
245 </table>
246 </ScrollArea>
247 );
248}
249
250function TraceIdCell({ traceId }: { traceId: string }) {
251 const { copyToClipboard, isCopied: copied } = useCopyToClipboard({
252 target: "trace ID",
253 timeout: 1_200,
254 });
255
256 return (
257 <div className="flex w-full min-w-0 max-w-full items-center gap-2">
258 <Tooltip>
259 <TooltipTrigger
260 render={
261 <span className="min-w-0 flex-1 truncate font-mono text-[11px]">
262 {shortenTraceId(traceId)}
263 </span>
264 }
265 />
266 <TooltipPopup
267 side="top"
268 className="max-w-[min(520px,calc(100vw-2rem))] break-all font-mono text-[11px]"
269 >
270 {traceId}
271 </TooltipPopup>
272 </Tooltip>
273 <Tooltip>
274 <TooltipTrigger
275 render={
276 <Button
277 size="icon-micro"
278 variant="ghost-muted"
279 aria-label={copied ? "Copied trace ID" : "Copy trace ID"}
280 onClick={() => copyToClipboard(traceId)}
281 >
282 <CopyIcon className="size-3" />
283 </Button>
284 }
285 />
286 <TooltipPopup side="top">{copied ? "Copied" : "Copy full trace ID"}</TooltipPopup>
287 </Tooltip>
288 </div>
289 );
290}
291
292function formatProcessName(command: string): string {
293 const firstToken = command.trim().split(/\s+/)[0];
294 if (!firstToken) return command;
295 const normalized = firstToken.replace(/^['"]|['"]$/g, "");
296 const segments = normalized.split(/[\\/]/).filter(Boolean);
297 return segments.at(-1) ?? normalized;
298}
299
300function formatProcessType(process: ServerProcessDiagnosticsEntry): string {
301 if (process.depth > 0) return "Subprocess";
302 if (/\b(codex|claude|opencode|cursor)\b/i.test(process.command)) return "Agent";
303 return "Process";
304}
305
306function ProcessNameCell({
307 process,
308 isExpanded,
309 onToggle,
310}: {
311 process: ServerProcessDiagnosticsEntry;
312 isExpanded: boolean;
313 onToggle: (pid: number) => void;
314}) {
315 const name = formatProcessName(process.command);
316 const hasChildren = process.childPids.length > 0;
317 const ChevronIcon = isExpanded ? ChevronDownIcon : ChevronRightIcon;
318
319 return (
320 <div
321 className="grid min-w-0 grid-cols-[1.25rem_0.375rem_minmax(0,1fr)] items-center gap-2"
322 style={{ paddingLeft: `${Math.min(process.depth, 6) * 10}px` }}
323 >
324 {hasChildren ? (
325 <Button
326 size="icon-micro"
327 variant="ghost-muted"
328 aria-label={isExpanded ? `Collapse ${name}` : `Expand ${name}`}
329 onClick={() => onToggle(process.pid)}
330 >
331 <ChevronIcon className="size-3.5" />
332 </Button>
333 ) : (
334 <span className="size-5 shrink-0" aria-hidden="true" />
335 )}
336 <span className="size-1.5 shrink-0 rounded-full bg-emerald-500/80" />
337 <Tooltip>
338 <TooltipTrigger
339 render={<span className="min-w-0 truncate font-medium text-foreground">{name}</span>}
340 />
341 <TooltipPopup
342 side="top"
343 className="max-w-[min(440px,calc(100vw-2rem))] whitespace-normal break-words text-left font-mono text-[11px] leading-relaxed text-wrap"
344 >
345 {process.command}
346 </TooltipPopup>
347 </Tooltip>
348 </div>
349 );
350}
351
352function ProcessSignalActions({
353 process,
354 isSignaling,
355 onSignal,
356}: {
357 process: ServerProcessDiagnosticsEntry;
358 isSignaling: boolean;
359 onSignal: (pid: number, signal: ServerProcessSignal) => void;
360}) {
361 return (
362 <div className="flex items-center justify-end gap-1.5">
363 <Tooltip>
364 <TooltipTrigger
365 render={
366 <button
367 type="button"
368 disabled={isSignaling}
369 className="cursor-pointer text-[11px] font-medium text-muted-foreground underline-offset-2 hover:text-foreground hover:underline disabled:pointer-events-none disabled:opacity-50"
370 onClick={() => onSignal(process.pid, "SIGINT")}
371 >
372 INT
373 </button>
374 }
375 />
376 <TooltipPopup side="top">Send SIGINT</TooltipPopup>
377 </Tooltip>
378 <Tooltip>
379 <TooltipTrigger
380 render={
381 <button
382 type="button"
383 disabled={isSignaling}
384 className="cursor-pointer text-[11px] font-medium text-destructive underline-offset-2 hover:underline disabled:pointer-events-none disabled:opacity-50"
385 onClick={() => onSignal(process.pid, "SIGKILL")}
386 >
387 KILL
388 </button>
389 }
390 />
391 <TooltipPopup side="top">Send SIGKILL</TooltipPopup>
392 </Tooltip>
393 </div>
394 );
395}
396
397function ProcessDiagnosticsTable({
398 processes,
399 signalingPid,
400 onSignal,
401 emptyLabel,
402}: {
403 processes: ReadonlyArray<ServerProcessDiagnosticsEntry>;
404 signalingPid: number | null;
405 onSignal: (pid: number, signal: ServerProcessSignal) => void;
406 emptyLabel?: string;
407}) {
408 const [collapsedPids, setCollapsedPids] = useState<ReadonlySet<number>>(() => new Set());
409 const visibleProcesses = useMemo(() => {
410 const visible: ServerProcessDiagnosticsEntry[] = [];
411 let hiddenChildDepth: number | null = null;
412
413 for (const process of processes) {
414 if (hiddenChildDepth !== null) {
415 if (process.depth > hiddenChildDepth) continue;
416 hiddenChildDepth = null;
417 }
418
419 visible.push(process);
420 if (collapsedPids.has(process.pid)) {
421 hiddenChildDepth = process.depth;
422 }
423 }
424
425 return visible;
426 }, [collapsedPids, processes]);
427
428 const toggleProcess = useCallback((pid: number) => {
429 setCollapsedPids((previous) => {
430 const next = new Set(previous);
431 if (next.has(pid)) {
432 next.delete(pid);
433 } else {
434 next.add(pid);
435 }
436 return next;
437 });
438 }, []);
439
440 return (
441 <ScrollArea
442 chainVerticalScroll
443 scrollFade
444 hideScrollbars
445 className="max-h-[min(64vh,44rem)] w-full max-w-full rounded-none border-t border-border/60"
446 >
447 <table className="w-full min-w-[1040px] table-fixed text-left text-xs">
448 <colgroup>
449 <col className="w-[24%]" />
450 <col className="w-[8%]" />
451 <col className="w-[10%]" />
452 <col className="w-[33%]" />
453 <col className="w-[8%]" />
454 <col className="w-[11%]" />
455 <col className="w-[6%]" />
456 </colgroup>
457 <thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-[11px] uppercase tracking-[0.08em] text-muted-foreground/70">
458 <tr>
459 <th className="px-4 py-2 font-semibold sm:pl-5">Name</th>
460 <th className="px-3 py-2 text-right font-semibold">CPU</th>
461 <th className="px-3 py-2 text-right font-semibold">Memory</th>
462 <th className="px-3 py-2 font-semibold">Command</th>
463 <th className="px-3 py-2 text-right font-semibold">PID</th>
464 <th className="px-3 py-2 font-semibold">Type</th>
465 <th className="p-2 text-right font-semibold sm:pr-4">Kill</th>
466 </tr>
467 </thead>
468 <tbody className="divide-y divide-border/50">
469 {visibleProcesses.length === 0 ? (
470 <tr>
471 <td colSpan={7} className="px-4 py-4 text-xs text-muted-foreground sm:px-5">
472 {emptyLabel ?? "No live descendant processes found."}
473 </td>
474 </tr>
475 ) : null}
476 {visibleProcesses.map((process) => (
477 <tr key={process.pid} className="hover:bg-muted/20">
478 <td className="px-4 py-2 align-middle sm:pl-5">
479 <ProcessNameCell
480 process={process}
481 isExpanded={!collapsedPids.has(process.pid)}
482 onToggle={toggleProcess}
483 />
484 </td>
485 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
486 {process.cpuPercent.toFixed(1)}%
487 </td>
488 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
489 {formatBytes(process.rssBytes)}
490 </td>
491 <td className="px-3 py-2 align-middle text-muted-foreground">
492 <Tooltip>
493 <TooltipTrigger
494 render={<span className="block truncate">{process.command}</span>}
495 />
496 <TooltipPopup
497 side="top"
498 className="max-w-[min(440px,calc(100vw-2rem))] whitespace-normal break-words text-left font-mono text-[11px] leading-relaxed text-wrap"
499 >
500 {process.command}
501 </TooltipPopup>
502 </Tooltip>
503 </td>
504 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums text-muted-foreground">
505 {process.pid}
506 </td>
507 <td className="truncate px-3 py-2 align-middle text-muted-foreground">
508 {formatProcessType(process)}
509 </td>
510 <td className="p-2 align-middle sm:pr-4">
511 <ProcessSignalActions
512 process={process}
513 isSignaling={signalingPid === process.pid}
514 onSignal={onSignal}
515 />
516 </td>
517 </tr>
518 ))}
519 </tbody>
520 </table>
521 </ScrollArea>
522 );
523}
524
525const RESOURCE_HISTORY_WINDOWS = [
526 { label: "5m", windowMs: 5 * 60_000, bucketMs: 30_000 },
527 { label: "15m", windowMs: 15 * 60_000, bucketMs: 60_000 },
528 { label: "30m", windowMs: 30 * 60_000, bucketMs: 2 * 60_000 },
529 { label: "1h", windowMs: 60 * 60_000, bucketMs: 5 * 60_000 },
530] as const;
531
532function formatCpuTime(seconds: number): string {
533 if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 1 : 2)}s`;
534 const minutes = seconds / 60;
535 if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2)}m`;
536 return `${(minutes / 60).toFixed(2)}h`;
537}
538
539function formatShortProcessName(command: string): string {
540 const name = formatProcessName(command);
541 return name.length > 42 ? `${name.slice(0, 39)}...` : name;
542}
543
544function ResourceHistoryProcessNameCell({
545 process,
546 visualDepth,
547}: {
548 process: ServerProcessResourceHistorySummary;
549 visualDepth: number;
550}) {
551 const name = formatShortProcessName(process.command);
552
553 return (
554 <div
555 className="grid min-w-0 grid-cols-[1.25rem_0.375rem_minmax(0,1fr)] items-center gap-2"
556 style={{ paddingLeft: `${Math.min(visualDepth, 6) * 10}px` }}
557 aria-label={`${process.isServerRoot ? "Root" : "Child"} process ${name}`}
558 >
559 <span className="size-5 shrink-0" aria-hidden="true" />
560 <span
561 className={cn(
562 "size-1.5 shrink-0 rounded-full",
563 process.isServerRoot ? "bg-amber-500/90" : "bg-emerald-500/80",
564 )}
565 />
566 <Tooltip>
567 <TooltipTrigger
568 render={<span className="min-w-0 truncate font-medium text-foreground">{name}</span>}
569 />
570 <TooltipPopup
571 side="top"
572 className="max-w-[min(440px,calc(100vw-2rem))] whitespace-normal break-words text-left font-mono text-[11px] leading-relaxed text-wrap"
573 >
574 {process.command}
575 </TooltipPopup>
576 </Tooltip>
577 </div>
578 );
579}
580
581function ProcessResourceHistoryChart({
582 buckets,
583}: {
584 buckets: ReadonlyArray<{
585 readonly startedAt: DateTime.Utc;
586 readonly avgCpuPercent: number;
587 readonly maxCpuPercent: number;
588 }>;
589}) {
590 const maxCpuPercent = Math.max(1, ...buckets.map((bucket) => bucket.maxCpuPercent));
591
592 return (
593 <div className="border-t border-border/60 px-4 py-3 sm:px-5">
594 <div className="flex h-28 items-end gap-1 overflow-hidden rounded-sm bg-muted/10 p-2">
595 {buckets.map((bucket) => {
596 const peakHeight = Math.max(2, (bucket.maxCpuPercent / maxCpuPercent) * 100);
597 const averageHeight = Math.max(2, (bucket.avgCpuPercent / maxCpuPercent) * 100);
598 return (
599 <Tooltip key={DateTime.formatIso(bucket.startedAt)}>
600 <TooltipTrigger
601 render={
602 <div className="flex h-full min-w-1 flex-1 items-end">
603 <div
604 className="relative h-full w-full"
605 aria-label={`Average CPU ${bucket.avgCpuPercent.toFixed(1)}%, peak CPU ${bucket.maxCpuPercent.toFixed(1)}%`}
606 >
607 <div
608 className="absolute inset-x-0 bottom-0 rounded-t-sm bg-foreground/15 transition-colors"
609 style={{ height: `${peakHeight}%` }}
610 />
611 <div
612 className="absolute inset-x-0 bottom-0 rounded-t-sm bg-foreground/60 transition-colors"
613 style={{ height: `${averageHeight}%` }}
614 />
615 </div>
616 </div>
617 }
618 />
619 <TooltipPopup side="top">
620 Avg {bucket.avgCpuPercent.toFixed(1)}%, peak {bucket.maxCpuPercent.toFixed(1)}%
621 </TooltipPopup>
622 </Tooltip>
623 );
624 })}
625 </div>
626 </div>
627 );
628}
629
630function ResourceHistoryWindowSelector({
631 selectedWindowMs,
632 onSelect,
633}: {
634 selectedWindowMs: number;
635 onSelect: (windowMs: number) => void;
636}) {
637 return (
638 <div className="flex items-center rounded-md border border-border/60 p-0.5">
639 {RESOURCE_HISTORY_WINDOWS.map((option) => (
640 <button
641 key={option.windowMs}
642 type="button"
643 className={cn(
644 "cursor-pointer h-6 rounded-sm px-2 text-[11px] font-medium text-muted-foreground hover:text-foreground",
645 selectedWindowMs === option.windowMs && "bg-muted text-foreground",
646 )}
647 onClick={() => onSelect(option.windowMs)}
648 >
649 {option.label}
650 </button>
651 ))}
652 </div>
653 );
654}
655
656function ProcessResourceHistoryTable({
657 processes,
658 emptyLabel,
659}: {
660 processes: ReadonlyArray<ServerProcessResourceHistorySummary>;
661 emptyLabel: string;
662}) {
663 const shallowestChildDepth = processes.reduce<number | null>((minDepth, process) => {
664 if (process.isServerRoot) return minDepth;
665 return minDepth === null ? process.depth : Math.min(minDepth, process.depth);
666 }, null);
667
668 return (
669 <ScrollArea
670 chainVerticalScroll
671 scrollFade
672 hideScrollbars
673 className="max-h-[min(64vh,44rem)] w-full max-w-full border-t border-border/60"
674 >
675 <table className="w-full min-w-[980px] table-fixed text-left text-xs">
676 <colgroup>
677 <col className="w-[24%]" />
678 <col className="w-[10%]" />
679 <col className="w-[10%]" />
680 <col className="w-[10%]" />
681 <col className="w-[10%]" />
682 <col className="w-[10%]" />
683 <col className="w-[16%]" />
684 <col className="w-[10%]" />
685 </colgroup>
686 <thead className="sticky top-0 z-10 border-b border-border/60 bg-card text-[11px] uppercase tracking-[0.08em] text-muted-foreground/70">
687 <tr>
688 <th className="px-4 py-2 font-semibold sm:pl-5">Process</th>
689 <th className="px-3 py-2 text-right font-semibold">CPU Time</th>
690 <th className="px-3 py-2 text-right font-semibold">Current</th>
691 <th className="px-3 py-2 text-right font-semibold">Average</th>
692 <th className="px-3 py-2 text-right font-semibold">Peak</th>
693 <th className="px-3 py-2 text-right font-semibold">Max Mem</th>
694 <th className="px-3 py-2 font-semibold">Command</th>
695 <th className="px-3 py-2 text-right font-semibold sm:pr-5">PID</th>
696 </tr>
697 </thead>
698 <tbody className="divide-y divide-border/50">
699 {processes.length === 0 ? (
700 <tr>
701 <td colSpan={8} className="px-4 py-4 text-xs text-muted-foreground sm:px-5">
702 {emptyLabel}
703 </td>
704 </tr>
705 ) : null}
706 {processes.map((process) => (
707 <tr key={process.processKey} className="hover:bg-muted/20">
708 <td className="px-4 py-2 align-middle sm:pl-5">
709 <ResourceHistoryProcessNameCell
710 process={process}
711 visualDepth={
712 process.isServerRoot || shallowestChildDepth === null
713 ? 0
714 : Math.max(1, process.depth - shallowestChildDepth + 1)
715 }
716 />
717 </td>
718 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
719 {formatCpuTime(process.cpuSecondsApprox)}
720 </td>
721 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
722 {process.currentCpuPercent.toFixed(1)}%
723 </td>
724 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
725 {process.avgCpuPercent.toFixed(1)}%
726 </td>
727 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
728 {process.maxCpuPercent.toFixed(1)}%
729 </td>
730 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums">
731 {formatBytes(process.maxRssBytes)}
732 </td>
733 <td className="px-3 py-2 align-middle text-muted-foreground">
734 <Tooltip>
735 <TooltipTrigger
736 render={<span className="block truncate">{process.command}</span>}
737 />
738 <TooltipPopup
739 side="top"
740 className="max-w-[min(440px,calc(100vw-2rem))] whitespace-normal break-words text-left font-mono text-[11px] leading-relaxed text-wrap"
741 >
742 {process.command}
743 </TooltipPopup>
744 </Tooltip>
745 </td>
746 <td className="px-3 py-2 text-right align-middle font-mono tabular-nums text-muted-foreground sm:pr-5">
747 {process.pid}
748 </td>
749 </tr>
750 ))}
751 </tbody>
752 </table>
753 </ScrollArea>
754 );
755}
756
757function DiagnosticsLastChecked({ checkedAt }: { checkedAt: DateTime.Utc | null }) {
758 useRelativeTimeTick();
759 const relative = getRelativeTimeState(checkedAt ? DateTime.formatIso(checkedAt) : null);
760
761 if (relative.status === "missing") {
762 return <span className="text-[11px] text-muted-foreground/50">Checking</span>;
763 }
764
765 if (relative.status === "invalid") {
766 return <span className="text-[11px] text-muted-foreground/50">Checked unavailable</span>;
767 }
768
769 return (
770 <span className="text-[11px] text-muted-foreground/60">
771 {relative.suffix ? (
772 <>
773 Checked <span className="font-mono tabular-nums">{relative.value}</span> {relative.suffix}
774 </>
775 ) : (
776 <>Checked {relative.value}</>
777 )}
778 </span>
779 );
780}
781
782function DiagnosticsRefreshButton({
783 isPending,
784 label,
785 onClick,
786}: {
787 isPending: boolean;
788 label: string;
789 onClick: () => void;
790}) {
791 return (
792 <Tooltip>
793 <TooltipTrigger
794 render={
795 <Button
796 size="icon-micro"
797 variant="ghost-muted"
798 disabled={isPending}
799 onClick={onClick}
800 aria-label={label}
801 >
802 <RefreshCwIcon className={cn("size-3", isPending && "animate-spin")} />
803 </Button>
804 }
805 />
806 <TooltipPopup side="top">{label}</TooltipPopup>
807 </Tooltip>
808 );
809}
810
811export function DiagnosticsSettingsPanel() {
812 const observability = useAtomValue(primaryServerObservabilityAtom);
813 const availableEditors = useAtomValue(primaryServerAvailableEditorsAtom);
814 const primaryEnvironment = usePrimaryEnvironment();
815 const environmentId = primaryEnvironment?.environmentId ?? null;
816 const signalServerProcess = useAtomCommand(serverEnvironment.signalProcess, {
817 reportFailure: false,
818 });
819 const openInEditor = useAtomCommand(shellEnvironment.openInEditor, {
820 reportFailure: false,
821 });
822 const [resourceWindowMs, setResourceWindowMs] = useState(15 * 60_000);
823 const selectedResourceWindow =
824 RESOURCE_HISTORY_WINDOWS.find((option) => option.windowMs === resourceWindowMs) ??
825 RESOURCE_HISTORY_WINDOWS[1];
826 const { data, error, isPending, refresh } = useEnvironmentQuery(
827 environmentId === null
828 ? null
829 : serverEnvironment.traceDiagnostics({ environmentId, input: {} }),
830 );
831 const {
832 data: processData,
833 error: processError,
834 isPending: isProcessPending,
835 refresh: refreshProcesses,
836 } = useEnvironmentQuery(
837 environmentId === null
838 ? null
839 : serverEnvironment.processDiagnostics({ environmentId, input: {} }),
840 );
841 const {
842 data: resourceData,
843 error: resourceError,
844 isPending: isResourcePending,
845 refresh: refreshResources,
846 } = useEnvironmentQuery(
847 environmentId === null
848 ? null
849 : serverEnvironment.processResourceHistory({
850 environmentId,
851 input: {
852 windowMs: selectedResourceWindow.windowMs,
853 bucketMs: selectedResourceWindow.bucketMs,
854 },
855 }),
856 );
857 const [isOpeningLogsDirectory, setIsOpeningLogsDirectory] = useState(false);
858 const [openLogsDirectoryError, setOpenLogsDirectoryError] = useState<string | null>(null);
859 const [signalingPid, setSignalingPid] = useState<number | null>(null);
860 const signalingPidRef = useRef<number | null>(null);
861 const environmentIdRef = useRef(environmentId);
862 const processDataRef = useRef(processData);
863 environmentIdRef.current = environmentId;
864 processDataRef.current = processData;
865
866 const openLogsDirectory = useCallback(() => {
867 const logsDirectoryPath = observability?.logsDirectoryPath ?? null;
868 if (!logsDirectoryPath) return;
869
870 const editor = resolveAndPersistPreferredEditor(availableEditors ?? []);
871 if (!editor) {
872 setOpenLogsDirectoryError("No available editors found.");
873 return;
874 }
875 if (environmentId === null) {
876 setOpenLogsDirectoryError("No environment is selected.");
877 return;
878 }
879
880 setIsOpeningLogsDirectory(true);
881 setOpenLogsDirectoryError(null);
882 void (async () => {
883 const result = await openInEditor({
884 environmentId,
885 input: {
886 cwd: logsDirectoryPath,
887 editor,
888 },
889 });
890 setIsOpeningLogsDirectory(false);
891 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
892 const error = squashAtomCommandFailure(result);
893 setOpenLogsDirectoryError(
894 error instanceof Error ? error.message : "Unable to open logs folder.",
895 );
896 }
897 })();
898 }, [availableEditors, environmentId, observability?.logsDirectoryPath, openInEditor]);
899
900 const isInitialLoading = isPending && data === null;
901 const isProcessInitialLoading = isProcessPending && processData === null;
902 const signalProcess = useCallback(
903 async (pid: number, signal: ServerProcessSignal) => {
904 if (signalingPidRef.current !== null) return;
905 signalingPidRef.current = pid;
906 setSignalingPid(pid);
907 const clearSignaling = () => {
908 signalingPidRef.current = null;
909 setSignalingPid(null);
910 };
911 if (signal === "SIGKILL") {
912 let confirmed = false;
913 try {
914 confirmed = await ensureLocalApi().dialogs.confirm(
915 `Send SIGKILL to process ${pid}? This cannot be handled by the process.`,
916 { variant: "destructive" },
917 );
918 } catch (error) {
919 clearSignaling();
920 toastManager.add({
921 type: "error",
922 title: "Could not confirm signal",
923 description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
924 });
925 return;
926 }
927 if (!confirmed) {
928 clearSignaling();
929 return;
930 }
931 }
932 const currentEnvironmentId = environmentIdRef.current;
933 if (currentEnvironmentId === null) {
934 clearSignaling();
935 return;
936 }
937 const process = processDataRef.current?.processes.find((entry) => entry.pid === pid);
938 if (process === undefined) {
939 clearSignaling();
940 return;
941 }
942
943 try {
944 const result = await signalServerProcess({
945 environmentId: currentEnvironmentId,
946 input: { pid, startTimeMs: process.startTimeMs, signal },
947 });
948 if (result._tag === "Failure") {
949 if (!isAtomCommandInterrupted(result)) {
950 const error = squashAtomCommandFailure(result);
951 toastManager.add({
952 type: "error",
953 title: `Could not send ${signal}`,
954 description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
955 });
956 }
957 return;
958 }
959 if (!result.value.signaled) {
960 const message = Option.getOrUndefined(result.value.message);
961 refreshProcesses();
962 if (isStaleProcessSignalMessage(message)) {
963 toastManager.add({
964 type: "info",
965 title: "Process already exited",
966 description:
967 "The process is not a child of the T3 Server. It might already have exited.",
968 });
969 return;
970 }
971
972 toastManager.add({
973 type: "error",
974 title: `Could not send ${signal}`,
975 description: message ?? `Failed to send ${signal}.`,
976 });
977 return;
978 }
979 refreshProcesses();
980 } finally {
981 clearSignaling();
982 }
983 },
984 [refreshProcesses, signalServerProcess],
985 );
986
987 const processDiagnosticsError = processData ? Option.getOrNull(processData.error) : null;
988 const processResourceError = resourceData ? Option.getOrNull(resourceData.error) : null;
989 const traceDiagnosticsError = data ? Option.getOrNull(data.error) : null;
990 const traceDiagnosticsPartialFailure = data
991 ? Option.getOrElse(data.partialFailure, () => false)
992 : false;
993
994 return (
995 <SettingsPageContainer width="expanded" className="gap-10">
996 <ResourceTelemetryDiagnostics />
997
998 <SettingsSection
999 title="Live Processes"
1000 headerAction={
1001 <div className="flex items-center gap-1.5">
1002 <DiagnosticsLastChecked checkedAt={processData?.readAt ?? null} />
1003 <DiagnosticsRefreshButton
1004 isPending={isProcessPending}
1005 label="Refresh process diagnostics"
1006 onClick={refreshProcesses}
1007 />
1008 </div>
1009 }
1010 >
1011 <StatsGrid>
1012 <StatBlock
1013 label="Child Processes"
1014 value={processData ? formatCount(processData.processCount) : "..."}
1015 />
1016 <StatBlock
1017 label="CPU"
1018 value={processData ? `${processData.totalCpuPercent.toFixed(1)}%` : "..."}
1019 tooltip="Total CPU across live child processes of the current server process. The desktop shell and other parent processes are not included."
1020 />
1021 <StatBlock
1022 label="Memory"
1023 value={processData ? formatBytes(processData.totalRssBytes) : "..."}
1024 tooltip="Total resident memory across live child processes of the current server process. The desktop shell and other parent processes are not included."
1025 />
1026 <StatBlock
1027 label="Server PID"
1028 value={processData ? String(processData.serverPid) : "..."}
1029 />
1030 </StatsGrid>
1031 {processDiagnosticsError || processError ? (
1032 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
1033 {processDiagnosticsError ? (
1034 <div className="flex items-start gap-2 text-destructive">
1035 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1036 <span>{processDiagnosticsError.message}</span>
1037 </div>
1038 ) : null}
1039 {processError ? (
1040 <div className="flex items-start gap-2 text-destructive">
1041 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1042 <span>{processError}</span>
1043 </div>
1044 ) : null}
1045 </div>
1046 ) : null}
1047 <ProcessDiagnosticsTable
1048 processes={processData?.processes ?? []}
1049 signalingPid={signalingPid}
1050 onSignal={signalProcess}
1051 emptyLabel={
1052 isProcessInitialLoading
1053 ? "Loading live processes..."
1054 : "No live descendant processes found."
1055 }
1056 />
1057 </SettingsSection>
1058
1059 <SettingsSection
1060 title="Resource History"
1061 headerAction={
1062 <div className="flex items-center gap-1.5">
1063 <ResourceHistoryWindowSelector
1064 selectedWindowMs={resourceWindowMs}
1065 onSelect={setResourceWindowMs}
1066 />
1067 <DiagnosticsLastChecked checkedAt={resourceData?.readAt ?? null} />
1068 <DiagnosticsRefreshButton
1069 isPending={isResourcePending}
1070 label="Refresh resource history"
1071 onClick={refreshResources}
1072 />
1073 </div>
1074 }
1075 >
1076 <StatsGrid>
1077 <StatBlock
1078 label="CPU Time"
1079 value={resourceData ? formatCpuTime(resourceData.totalCpuSecondsApprox) : "..."}
1080 tooltip="Approximate active CPU time for the T3 server root process and its descendants during the selected window. It grows only while sampled processes use CPU and older samples leave as the window moves."
1081 />
1082 <StatBlock
1083 label="Samples"
1084 value={resourceData ? formatCount(resourceData.retainedSampleCount) : "..."}
1085 tooltip="In-memory process samples retained by the server. This resets when the server restarts."
1086 />
1087 <StatBlock
1088 label="Interval"
1089 value={resourceData ? formatDuration(resourceData.sampleIntervalMs) : "..."}
1090 />
1091 <StatBlock
1092 label="Processes"
1093 value={resourceData ? formatCount(resourceData.topProcesses.length) : "..."}
1094 />
1095 </StatsGrid>
1096 {processResourceError || resourceError ? (
1097 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
1098 {processResourceError ? (
1099 <div className="flex items-start gap-2 text-destructive">
1100 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1101 <span>{processResourceError.message}</span>
1102 </div>
1103 ) : null}
1104 {resourceError ? (
1105 <div className="flex items-start gap-2 text-destructive">
1106 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1107 <span>{resourceError}</span>
1108 </div>
1109 ) : null}
1110 </div>
1111 ) : null}
1112 <ProcessResourceHistoryChart buckets={resourceData?.buckets ?? []} />
1113 <ProcessResourceHistoryTable
1114 processes={resourceData?.topProcesses ?? []}
1115 emptyLabel={
1116 isResourcePending && resourceData === null
1117 ? "Collecting process resource samples..."
1118 : "No process resource samples found for this window."
1119 }
1120 />
1121 </SettingsSection>
1122
1123 <SettingsSection
1124 title="Trace Diagnostics"
1125 headerAction={
1126 <div className="flex items-center gap-1.5">
1127 <DiagnosticsLastChecked checkedAt={data?.readAt ?? null} />
1128 <Tooltip>
1129 <TooltipTrigger
1130 render={
1131 <Button
1132 size="icon-micro"
1133 variant="ghost-muted"
1134 disabled={!observability?.logsDirectoryPath || isOpeningLogsDirectory}
1135 onClick={openLogsDirectory}
1136 aria-label="Open logs folder"
1137 >
1138 <FolderOpenIcon className="size-3" />
1139 </Button>
1140 }
1141 />
1142 <TooltipPopup side="top">Open logs folder</TooltipPopup>
1143 </Tooltip>
1144 <DiagnosticsRefreshButton
1145 isPending={isPending}
1146 label="Refresh trace diagnostics"
1147 onClick={refresh}
1148 />
1149 </div>
1150 }
1151 >
1152 <StatsGrid>
1153 <StatBlock label="Spans" value={data ? formatCount(data.recordCount) : "..."} />
1154 <StatBlock
1155 label="Failures"
1156 value={data ? formatCount(data.failureCount) : "..."}
1157 tone={data && data.failureCount > 0 ? "danger" : "default"}
1158 />
1159 <StatBlock
1160 label="Slow Spans"
1161 value={data ? formatCount(data.slowSpanCount) : "..."}
1162 tooltip={
1163 data
1164 ? `Spans with a duration of ${formatDuration(data.slowSpanThresholdMs)} or longer.`
1165 : "Spans at or above the configured slow-span threshold."
1166 }
1167 tone={data && data.slowSpanCount > 0 ? "warning" : "default"}
1168 />
1169 <StatBlock
1170 label="Parse Errors"
1171 value={data ? formatCount(data.parseErrorCount) : "..."}
1172 tone={data && data.parseErrorCount > 0 ? "warning" : "default"}
1173 />
1174 </StatsGrid>
1175 {openLogsDirectoryError || traceDiagnosticsError || error ? (
1176 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
1177 {openLogsDirectoryError ? (
1178 <div className="flex items-start gap-2 text-destructive">
1179 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1180 <span>{openLogsDirectoryError}</span>
1181 </div>
1182 ) : null}
1183 {traceDiagnosticsError ? (
1184 <div
1185 className={cn(
1186 "flex items-start gap-2",
1187 traceDiagnosticsPartialFailure
1188 ? "text-amber-600 dark:text-amber-400"
1189 : "text-destructive",
1190 )}
1191 >
1192 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1193 <span>
1194 {traceDiagnosticsPartialFailure
1195 ? `Some trace files could not be read, so diagnostics may be incomplete. ${traceDiagnosticsError.message}`
1196 : traceDiagnosticsError.message}
1197 </span>
1198 </div>
1199 ) : null}
1200 {error ? (
1201 <div className="flex items-start gap-2 text-destructive">
1202 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1203 <span>{error}</span>
1204 </div>
1205 ) : null}
1206 </div>
1207 ) : null}
1208 </SettingsSection>
1209
1210 <SettingsSection title="Latest Failures">
1211 {data && data.latestFailures.length > 0 ? (
1212 <DiagnosticsTable headers={["Span", "Cause", "Duration", "Ended"]}>
1213 {data.latestFailures.map((failure) => (
1214 <tr key={`${failure.traceId}:${failure.spanId}`}>
1215 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1216 {failure.name}
1217 </td>
1218 <td className="max-w-[360px] px-4 py-3 align-top text-muted-foreground">
1219 <ExpandableText text={failure.cause} />
1220 </td>
1221 <td className="px-4 py-3 align-top font-mono tabular-nums">
1222 {formatDuration(failure.durationMs)}
1223 </td>
1224 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
1225 {formatRelativeNoWrap(failure.endedAt)}
1226 </td>
1227 </tr>
1228 ))}
1229 </DiagnosticsTable>
1230 ) : (
1231 <EmptyRows label={isInitialLoading ? "Loading failures..." : "No failed spans found."} />
1232 )}
1233 </SettingsSection>
1234
1235 <SettingsSection title="Most Common Failures">
1236 {data && data.commonFailures.length > 0 ? (
1237 <DiagnosticsTable
1238 headers={["Span", "Count", "Cause", "Last Seen"]}
1239 minTableWidth="min-w-[760px]"
1240 >
1241 {data.commonFailures.map((failure) => (
1242 <tr key={`${failure.name}:${failure.cause}`}>
1243 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1244 {failure.name}
1245 </td>
1246 <td className="px-4 py-3 align-top font-mono tabular-nums">
1247 {formatCount(failure.count)}
1248 </td>
1249 <td className="max-w-[360px] px-4 py-3 align-top text-muted-foreground">
1250 <ExpandableText text={failure.cause} />
1251 </td>
1252 <td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
1253 {formatRelativeNoWrap(failure.lastSeenAt)}
1254 </td>
1255 </tr>
1256 ))}
1257 </DiagnosticsTable>
1258 ) : (
1259 <EmptyRows
1260 label={isInitialLoading ? "Loading failure groups..." : "No repeated failures found."}
1261 />
1262 )}
1263 </SettingsSection>
1264
1265 <SettingsSection title="Slowest Spans">
1266 {data && data.slowestSpans.length > 0 ? (
1267 <DiagnosticsTable
1268 headers={["Span", "Duration", "Ended", "Trace"]}
1269 minTableWidth="min-w-[900px]"
1270 columnWidths={["w-[44%]", "w-[14%]", "w-[12%]", "w-[30%]"]}
1271 >
1272 {data.slowestSpans.map((span) => (
1273 <tr key={`${span.traceId}:${span.spanId}`}>
1274 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1275 {span.name}
1276 </td>
1277 <td className="px-4 py-3 align-top font-mono tabular-nums">
1278 {formatDuration(span.durationMs)}
1279 </td>
1280 <td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground">
1281 {formatRelativeNoWrap(span.endedAt)}
1282 </td>
1283 <td className="min-w-0 whitespace-nowrap px-4 py-3 align-top text-muted-foreground last:sm:pr-5">
1284 <TraceIdCell traceId={span.traceId} />
1285 </td>
1286 </tr>
1287 ))}
1288 </DiagnosticsTable>
1289 ) : (
1290 <EmptyRows label={isInitialLoading ? "Loading slow spans..." : "No spans found."} />
1291 )}
1292 </SettingsSection>
1293
1294 <SettingsSection title="Span Logs">
1295 {data && data.latestWarningAndErrorLogs.length > 0 ? (
1296 <ScrollArea
1297 chainVerticalScroll
1298 scrollFade
1299 hideScrollbars
1300 className="w-full max-w-full rounded-none"
1301 >
1302 <table className="w-full min-w-[920px] table-fixed text-left text-xs">
1303 <colgroup>
1304 <col className="w-[11%]" />
1305 <col className="w-[9%]" />
1306 <col className="w-[24%]" />
1307 <col className="w-[26%]" />
1308 <col className="w-[30%]" />
1309 </colgroup>
1310 <thead className="border-b border-border/60 text-[11px] uppercase tracking-[0.08em] text-muted-foreground/70">
1311 <tr>
1312 <th className="whitespace-nowrap px-4 py-2.5 font-semibold sm:pl-5">Time</th>
1313 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Level</th>
1314 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Span</th>
1315 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Message</th>
1316 <th className="whitespace-nowrap px-4 py-2.5 font-semibold sm:pr-5">Trace</th>
1317 </tr>
1318 </thead>
1319 <tbody className="divide-y divide-border/60">
1320 {data.latestWarningAndErrorLogs.map((event) => (
1321 <tr
1322 key={`${event.traceId}:${event.spanId}:${DateTime.formatIso(event.seenAt)}:${event.message}`}
1323 className="hover:bg-muted/15"
1324 >
1325 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground sm:pl-5">
1326 {formatRelativeNoWrap(event.seenAt)}
1327 </td>
1328 <td className="px-4 py-3 align-top">
1329 <span className="inline-flex rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] font-medium uppercase text-foreground/80">
1330 {event.level}
1331 </span>
1332 </td>
1333 <td className="px-4 py-3 align-top">
1334 <div className="truncate font-medium text-foreground">{event.spanName}</div>
1335 </td>
1336 <td className="px-4 py-3 align-top text-muted-foreground">
1337 <ExpandableText
1338 collapsedClassName="line-clamp-2"
1339 expandLabel="Show full message"
1340 text={event.message}
1341 />
1342 </td>
1343 <td className="min-w-0 whitespace-nowrap px-4 py-3 align-top text-muted-foreground sm:pr-5">
1344 <TraceIdCell traceId={event.traceId} />
1345 </td>
1346 </tr>
1347 ))}
1348 </tbody>
1349 </table>
1350 </ScrollArea>
1351 ) : (
1352 <EmptyRows
1353 label={isInitialLoading ? "Loading recent logs..." : "No warnings or errors found."}
1354 />
1355 )}
1356 </SettingsSection>
1357
1358 <SettingsSection title="Top Span Names">
1359 {data && data.topSpansByCount.length > 0 ? (
1360 <DiagnosticsTable
1361 headers={["Span", "Count", "Failures", "Average", "Max"]}
1362 minTableWidth="min-w-[760px]"
1363 columnWidths={["w-[48%]", "w-[13%]", "w-[13%]", "w-[13%]", "w-[13%]"]}
1364 >
1365 {data.topSpansByCount.map((span) => (
1366 <tr key={span.name}>
1367 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1368 {span.name}
1369 </td>
1370 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1371 {formatCount(span.count)}
1372 </td>
1373 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1374 {formatCount(span.failureCount)}
1375 </td>
1376 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1377 {formatDuration(span.averageDurationMs)}
1378 </td>
1379 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums last:sm:pr-5">
1380 {formatDuration(span.maxDurationMs)}
1381 </td>
1382 </tr>
1383 ))}
1384 </DiagnosticsTable>
1385 ) : (
1386 <EmptyRows label={isInitialLoading ? "Loading span names..." : "No spans found."} />
1387 )}
1388 </SettingsSection>
1389 </SettingsPageContainer>
1390 );
1391}