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