Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

DiagnosticsSettings.tsx

1,349 lines49.3 KB

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);
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`;
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]}`;
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;
71​
72function shortenTraceId(traceId: string): string {
73 if (traceId.length <= 32) return traceId;
74 return `${traceId.slice(0, 18)}...${traceId.slice(-10)}`;
76​
77function isStaleProcessSignalMessage(message: string | undefined): boolean {
78 return message?.includes("not a live descendant") ?? false;
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 );
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 );
149​
150function EmptyRows({ label }: { label: string }) {
151 return <div className="px-4 py-4 text-xs text-muted-foreground sm:px-5">{label}</div>;
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 );
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 );
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;
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";
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 );
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;
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 );
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`;
446​
447function formatShortProcessName(command: string): string {
448 const name = formatProcessName(command);
449 return name.length > 42 ? `${name.slice(0, 39)}...` : name;
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 );
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 );
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 );
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 );
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 );
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 );
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 // The export form waits for each environment's first tables so a search target below them
816 // stays in view. Later loads, such as a new resource window, must not remount it and drop drafts.
817 const [exportFormEnvironmentId, setExportFormEnvironmentId] =
818 useState<typeof environmentId>(null);
819 if (
820 exportFormEnvironmentId !== environmentId &&
821 canReadDiagnostics &&
822 !isInitialLoading &&
823 !isProcessInitialLoading &&
824 !isResourceInitialLoading
825 ) {
826 setExportFormEnvironmentId(environmentId);
827 }
828 const signalProcess = async (pid: number, signal: ServerProcessSignal) => {
829 const targetEnvironmentId = environmentIdRef.current;
830 const process = processDataRef.current?.processes.find((entry) => entry.pid === pid);
831 if (
832 targetEnvironmentId === null ||
833 process === undefined ||
834 !readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)
835 )
836 return;
837 if (signalingPidRef.current !== null) return;
838 signalingPidRef.current = pid;
839 setSignalingPid(pid);
840 const clearSignaling = () => {
841 signalingPidRef.current = null;
842 setSignalingPid(null);
843 };
844 if (signal === "SIGKILL") {
845 let confirmed = false;
846 try {
847 confirmed = await ensureLocalApi().dialogs.confirm(
848 `Send SIGKILL to process ${pid}? This cannot be handled by the process.`,
849 { variant: "destructive" },
850 );
851 } catch (error) {
852 clearSignaling();
853 toastManager.add({
854 type: "error",
855 title: "Could not confirm signal",
856 description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
857 });
858 return;
859 }
860 if (!confirmed) {
861 clearSignaling();
862 return;
863 }
864 }
865 const currentEnvironmentId = environmentIdRef.current;
866 if (
867 currentEnvironmentId === null ||
868 currentEnvironmentId !== targetEnvironmentId ||
869 !readEnvironmentScope(currentEnvironmentId, AuthEnvironmentMaintainScope)
870 ) {
871 clearSignaling();
872 return;
873 }
874 if (
875 processDataRef.current?.processes.find((entry) => entry.pid === pid)?.startTimeMs !==
876 process.startTimeMs
877 ) {
878 clearSignaling();
879 return;
880 }
881​
882 const result = await signalServerProcess({
883 environmentId: targetEnvironmentId,
884 input: { pid, startTimeMs: process.startTimeMs, signal },
885 });
886 clearSignaling();
887 if (result._tag === "Failure") {
888 if (!isAtomCommandInterrupted(result)) {
889 const error = squashAtomCommandFailure(result);
890 toastManager.add({
891 type: "error",
892 title: `Could not send ${signal}`,
893 description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
894 });
895 }
896 return;
897 }
898 if (!result.value.signaled) {
899 const message = Option.getOrUndefined(result.value.message);
900 refreshProcesses();
901 if (isStaleProcessSignalMessage(message)) {
902 toastManager.add({
903 type: "info",
904 title: "Process already exited",
905 description: "The process is not a child of the T3 Server. It might already have exited.",
906 });
907 return;
908 }
909​
910 toastManager.add({
911 type: "error",
912 title: `Could not send ${signal}`,
913 description: message ?? `Failed to send ${signal}.`,
914 });
915 return;
916 }
917 refreshProcesses();
918 };
919​
920 const processDiagnosticsError = processData ? Option.getOrNull(processData.error) : null;
921 const processResourceError = resourceData ? Option.getOrNull(resourceData.error) : null;
922 const traceDiagnosticsError = data ? Option.getOrNull(data.error) : null;
923 const traceDiagnosticsPartialFailure = data
924 ? Option.getOrElse(data.partialFailure, () => false)
925 : false;
926​
927 if (!canReadDiagnostics) {
928 return (
929 <SettingsPageContainer>
930 <p className="text-sm text-muted-foreground">
931 {environmentId === null
932 ? "Connect an environment to see diagnostics."
933 : diagnosticsAccess.isPending
934 ? "Checking diagnostics access…"
935 : diagnosticsAccess.error}
936 </p>
937 </SettingsPageContainer>
938 );
939 }
940​
941 return (
942 <SettingsPageContainer width="expanded" className="gap-10">
943 <ResourceTelemetryDiagnostics environmentId={environmentId} />
944​
945 <SettingsSection
946 title="Live Processes"
947 headerAction={
948 <div className="flex items-center gap-1.5">
949 <DiagnosticsLastChecked checkedAt={processData?.readAt ?? null} />
950 <DiagnosticsRefreshButton
951 isPending={isProcessPending}
952 label="Refresh process diagnostics"
953 onClick={refreshProcesses}
954 />
955 </div>
956 }
957 >
958 <StatsGrid>
959 <StatBlock
960 label="Child Processes"
961 value={processData ? formatCount(processData.processCount) : "..."}
962 />
963 <StatBlock
964 label="CPU"
965 value={processData ? `${processData.totalCpuPercent.toFixed(1)}%` : "..."}
966 tooltip="Total CPU across live child processes of the current server process. The desktop shell and other parent processes are not included."
967 />
968 <StatBlock
969 label="Memory"
970 value={processData ? formatBytes(processData.totalRssBytes) : "..."}
971 tooltip="Total resident memory across live child processes of the current server process. The desktop shell and other parent processes are not included."
972 />
973 <StatBlock
974 label="Server PID"
975 value={processData ? String(processData.serverPid) : "..."}
976 />
977 </StatsGrid>
978 {processDiagnosticsError || processError ? (
979 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
980 {processDiagnosticsError ? (
981 <div className="flex items-start gap-2 text-destructive">
982 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
983 <span>{processDiagnosticsError.message}</span>
984 </div>
985 ) : null}
986 {processError ? (
987 <div className="flex items-start gap-2 text-destructive">
988 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
989 <span>{processError}</span>
990 </div>
991 ) : null}
992 </div>
993 ) : null}
994 <ProcessDiagnosticsTable
995 processes={processData?.processes ?? []}
996 canMaintainEnvironment={canMaintainEnvironment}
997 signalingPid={signalingPid}
998 onSignal={signalProcess}
999 emptyLabel={
1000 isProcessInitialLoading
1001 ? "Loading live processes..."
1002 : "No live descendant processes found."
1004 />
1005 </SettingsSection>
1006​
1007 <SettingsSection
1008 title="Resource History"
1009 headerAction={
1010 <div className="flex items-center gap-1.5">
1011 <ResourceHistoryWindowSelector
1012 selectedWindowMs={resourceWindowMs}
1013 onSelect={setResourceWindowMs}
1014 />
1015 <DiagnosticsLastChecked checkedAt={resourceData?.readAt ?? null} />
1016 <DiagnosticsRefreshButton
1017 isPending={isResourcePending}
1018 label="Refresh resource history"
1019 onClick={refreshResources}
1020 />
1021 </div>
1024 <StatsGrid>
1025 <StatBlock
1026 label="CPU Time"
1027 value={resourceData ? formatCpuTime(resourceData.totalCpuSecondsApprox) : "..."}
1028 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."
1029 />
1030 <StatBlock
1031 label="Samples"
1032 value={resourceData ? formatCount(resourceData.retainedSampleCount) : "..."}
1033 tooltip="In-memory process samples retained by the server. The server samples only while diagnostics is open, and this resets when the server restarts."
1034 />
1035 <StatBlock
1036 label="Interval"
1037 value={
1038 resourceData
1039 ? resourceData.sampleIntervalMs === 0
1040 ? "On demand"
1041 : formatDuration(resourceData.sampleIntervalMs)
1042 : "..."
1044 />
1045 <StatBlock
1046 label="Processes"
1047 value={resourceData ? formatCount(resourceData.topProcesses.length) : "..."}
1048 />
1049 </StatsGrid>
1050 {processResourceError || resourceError ? (
1051 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
1052 {processResourceError ? (
1053 <div className="flex items-start gap-2 text-destructive">
1054 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1055 <span>{processResourceError.message}</span>
1056 </div>
1057 ) : null}
1058 {resourceError ? (
1059 <div className="flex items-start gap-2 text-destructive">
1060 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1061 <span>{resourceError}</span>
1062 </div>
1063 ) : null}
1064 </div>
1065 ) : null}
1066 <ProcessResourceHistoryChart buckets={resourceData?.buckets ?? []} />
1067 <ProcessResourceHistoryTable
1068 processes={resourceData?.topProcesses ?? []}
1069 emptyLabel={
1070 isResourceInitialLoading
1071 ? "Collecting process resource samples..."
1072 : "No process resource samples found for this window."
1074 />
1075 </SettingsSection>
1076​
1077 <SettingsSection
1078 title="Trace Diagnostics"
1079 headerAction={
1080 <div className="flex items-center gap-1.5">
1081 <DiagnosticsLastChecked checkedAt={data?.readAt ?? null} />
1082 <Tooltip>
1083 <TooltipTrigger
1084 render={
1085 <Button
1086 size="icon-xs"
1087 variant="ghost-muted"
1088 disabled={
1089 !canOpenHostEditor ||
1090 !observability?.logsDirectoryPath ||
1091 isOpeningLogsDirectory
1093 onClick={openLogsDirectory}
1094 aria-label="Open logs folder"
1096 <FolderOpenIcon />
1097 </Button>
1099 />
1100 <TooltipPopup side="top">Open logs folder</TooltipPopup>
1101 </Tooltip>
1102 <DiagnosticsRefreshButton
1103 isPending={isPending}
1104 label="Refresh trace diagnostics"
1105 onClick={refresh}
1106 />
1107 </div>
1110 <StatsGrid>
1111 <StatBlock label="Spans" value={data ? formatCount(data.recordCount) : "..."} />
1112 <StatBlock
1113 label="Failures"
1114 value={data ? formatCount(data.failureCount) : "..."}
1115 tone={data && data.failureCount > 0 ? "danger" : "default"}
1116 />
1117 <StatBlock
1118 label="Slow Spans"
1119 value={data ? formatCount(data.slowSpanCount) : "..."}
1120 tooltip={
1121 data
1122 ? `Spans with a duration of ${formatDuration(data.slowSpanThresholdMs)} or longer.`
1123 : "Spans at or above the configured slow-span threshold."
1125 tone={data && data.slowSpanCount > 0 ? "warning" : "default"}
1126 />
1127 <StatBlock
1128 label="Parse Errors"
1129 value={data ? formatCount(data.parseErrorCount) : "..."}
1130 tone={data && data.parseErrorCount > 0 ? "warning" : "default"}
1131 />
1132 </StatsGrid>
1133 {openLogsDirectoryError || traceDiagnosticsError || error ? (
1134 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
1135 {openLogsDirectoryError ? (
1136 <div className="flex items-start gap-2 text-destructive">
1137 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1138 <span>{openLogsDirectoryError}</span>
1139 </div>
1140 ) : null}
1141 {traceDiagnosticsError ? (
1142 <div
1143 className={cn(
1144 "flex items-start gap-2",
1145 traceDiagnosticsPartialFailure ? "text-warning-foreground" : "text-destructive",
1146 )}
1148 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1149 <span>
1150 {traceDiagnosticsPartialFailure
1151 ? `Some trace files could not be read, so diagnostics may be incomplete. ${traceDiagnosticsError.message}`
1152 : traceDiagnosticsError.message}
1153 </span>
1154 </div>
1155 ) : null}
1156 {error ? (
1157 <div className="flex items-start gap-2 text-destructive">
1158 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0" />
1159 <span>{error}</span>
1160 </div>
1161 ) : null}
1162 </div>
1163 ) : null}
1164 </SettingsSection>
1165​
1166 <SettingsSection title="Latest Failures">
1167 {data && data.latestFailures.length > 0 ? (
1168 <DiagnosticsTable headers={["Span", "Cause", "Duration", "Ended"]}>
1169 {data.latestFailures.map((failure) => (
1170 <tr key={`${failure.traceId}:${failure.spanId}`}>
1171 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1172 {failure.name}
1173 </td>
1174 <td className="max-w-[360px] px-4 py-3 align-top text-muted-foreground">
1175 <ExpandableText text={failure.cause} />
1176 </td>
1177 <td className="px-4 py-3 align-top font-mono tabular-nums">
1178 {formatDuration(failure.durationMs)}
1179 </td>
1180 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
1181 <RelativeTimeNoWrap value={failure.endedAt} />
1182 </td>
1183 </tr>
1184 ))}
1185 </DiagnosticsTable>
1186 ) : (
1187 <EmptyRows label={isInitialLoading ? "Loading failures..." : "No failed spans found."} />
1188 )}
1189 </SettingsSection>
1190​
1191 <SettingsSection title="Most Common Failures">
1192 {data && data.commonFailures.length > 0 ? (
1193 <DiagnosticsTable
1194 headers={["Span", "Count", "Cause", "Last Seen"]}
1195 minTableWidth="min-w-[760px]"
1197 {data.commonFailures.map((failure) => (
1198 <tr key={`${failure.name}:${failure.cause}`}>
1199 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1200 {failure.name}
1201 </td>
1202 <td className="px-4 py-3 align-top font-mono tabular-nums">
1203 {formatCount(failure.count)}
1204 </td>
1205 <td className="max-w-[360px] px-4 py-3 align-top text-muted-foreground">
1206 <ExpandableText text={failure.cause} />
1207 </td>
1208 <td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
1209 <RelativeTimeNoWrap value={failure.lastSeenAt} />
1210 </td>
1211 </tr>
1212 ))}
1213 </DiagnosticsTable>
1214 ) : (
1215 <EmptyRows
1216 label={isInitialLoading ? "Loading failure groups..." : "No repeated failures found."}
1217 />
1218 )}
1219 </SettingsSection>
1220​
1221 <SettingsSection title="Slowest Spans">
1222 {data && data.slowestSpans.length > 0 ? (
1223 <DiagnosticsTable
1224 headers={["Span", "Duration", "Ended", "Trace"]}
1225 minTableWidth="min-w-[900px]"
1226 columnWidths={["w-[44%]", "w-[14%]", "w-[12%]", "w-[30%]"]}
1228 {data.slowestSpans.map((span) => (
1229 <tr key={`${span.traceId}:${span.spanId}`}>
1230 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1231 {span.name}
1232 </td>
1233 <td className="px-4 py-3 align-top font-mono tabular-nums">
1234 {formatDuration(span.durationMs)}
1235 </td>
1236 <td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground">
1237 <RelativeTimeNoWrap value={span.endedAt} />
1238 </td>
1239 <td className="min-w-0 whitespace-nowrap px-4 py-3 align-top text-muted-foreground last:sm:pr-5">
1240 <TraceIdCell traceId={span.traceId} />
1241 </td>
1242 </tr>
1243 ))}
1244 </DiagnosticsTable>
1245 ) : (
1246 <EmptyRows label={isInitialLoading ? "Loading slow spans..." : "No spans found."} />
1247 )}
1248 </SettingsSection>
1249​
1250 <SettingsSection title="Span Logs">
1251 {data && data.latestWarningAndErrorLogs.length > 0 ? (
1252 <ScrollArea
1253 radius="none"
1254 chainVerticalScroll
1255 scrollFade
1256 hideScrollbars
1257 className="w-full max-w-full"
1259 <table className="w-full min-w-[920px] table-fixed text-left text-xs">
1260 <colgroup>
1261 <col className="w-[11%]" />
1262 <col className="w-[9%]" />
1263 <col className="w-[24%]" />
1264 <col className="w-[26%]" />
1265 <col className="w-[30%]" />
1266 </colgroup>
1267 <thead className="border-b border-border/60 text-2xs uppercase tracking-widest text-muted-foreground/70">
1268 <tr>
1269 <th className="whitespace-nowrap px-4 py-2.5 font-semibold sm:pl-5">Time</th>
1270 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Level</th>
1271 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Span</th>
1272 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Message</th>
1273 <th className="whitespace-nowrap px-4 py-2.5 font-semibold sm:pr-5">Trace</th>
1274 </tr>
1275 </thead>
1276 <tbody className="divide-y divide-border/60">
1277 {data.latestWarningAndErrorLogs.map((event) => (
1278 <tr
1279 key={`${event.traceId}:${event.spanId}:${DateTime.formatIso(event.seenAt)}:${event.message}`}
1280 className="hover:bg-muted/15"
1282 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground sm:pl-5">
1283 <RelativeTimeNoWrap value={event.seenAt} />
1284 </td>
1285 <td className="px-4 py-3 align-top">
1286 <span className="inline-flex rounded bg-muted px-1.5 py-0.5 font-mono text-2xs font-medium uppercase text-foreground/80">
1287 {event.level}
1288 </span>
1289 </td>
1290 <td className="px-4 py-3 align-top">
1291 <div className="truncate font-medium text-foreground">{event.spanName}</div>
1292 </td>
1293 <td className="px-4 py-3 align-top text-muted-foreground">
1294 <ExpandableText
1295 collapsedClassName="line-clamp-2"
1296 expandLabel="Show full message"
1297 text={event.message}
1298 />
1299 </td>
1300 <td className="min-w-0 whitespace-nowrap px-4 py-3 align-top text-muted-foreground sm:pr-5">
1301 <TraceIdCell traceId={event.traceId} />
1302 </td>
1303 </tr>
1304 ))}
1305 </tbody>
1306 </table>
1307 </ScrollArea>
1308 ) : (
1309 <EmptyRows
1310 label={isInitialLoading ? "Loading recent logs..." : "No warnings or errors found."}
1311 />
1312 )}
1313 </SettingsSection>
1314​
1315 <SettingsSection title="Top Span Names">
1316 {data && data.topSpansByCount.length > 0 ? (
1317 <DiagnosticsTable
1318 headers={["Span", "Count", "Failures", "Average", "Max"]}
1319 minTableWidth="min-w-[760px]"
1320 columnWidths={["w-[48%]", "w-[13%]", "w-[13%]", "w-[13%]", "w-[13%]"]}
1322 {data.topSpansByCount.map((span) => (
1323 <tr key={span.name}>
1324 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1325 {span.name}
1326 </td>
1327 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1328 {formatCount(span.count)}
1329 </td>
1330 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1331 {formatCount(span.failureCount)}
1332 </td>
1333 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1334 {formatDuration(span.averageDurationMs)}
1335 </td>
1336 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums last:sm:pr-5">
1337 {formatDuration(span.maxDurationMs)}
1338 </td>
1339 </tr>
1340 ))}
1341 </DiagnosticsTable>
1342 ) : (
1343 <EmptyRows label={isInitialLoading ? "Loading span names..." : "No spans found."} />
1344 )}
1345 </SettingsSection>
1346 {exportFormEnvironmentId === environmentId && <TelemetryExportSettings />}
1347 </SettingsPageContainer>
1348 );