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