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