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