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