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 { 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).replace(/\.0+$/, "")} 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).replace(/\.0+$/, "")}s`;
442 const minutes = seconds / 60;
443 if (minutes < 60) return `${minutes.toFixed(minutes >= 10 ? 1 : 2).replace(/\.0+$/, "")}m`;
444 return `${(minutes / 60).toFixed(2).replace(/\.0+$/, "")}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 // Signals and pending UI state belong to one environment, so a scope switch starts fresh.
719 return <DiagnosticsSettingsBody key={environment?.environmentId ?? ""} />;
720}
721
722function DiagnosticsSettingsBody() {
723 const { environment } = useSettingsScope();
724 const environmentId = environment?.environmentId ?? null;
725 const canMaintainEnvironment = useEnvironmentScope(environmentId, AuthEnvironmentMaintainScope);
726 const observability = environment?.serverConfig?.observability;
727 const availableEditors = environment?.serverConfig?.availableEditors;
728 const canOpenHostEditor = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope);
729 const session = useEnvironmentQuery(
730 environmentId === null ? null : environmentSession.sessionStateAtom(environmentId),
731 );
732 const diagnosticsAccess = resolveUsageAccess({
733 connectionPhase: environment?.connection.phase ?? "available",
734 session: session.data,
735 hasSessionError: session.error !== null,
736 });
737 const canReadDiagnostics = diagnosticsAccess.canReadDiagnostics;
738 const signalServerProcess = useAtomCommand(serverEnvironment.signalProcess, {
739 reportFailure: false,
740 });
741 const openInEditor = useOpenInPreferredEditor(environmentId, availableEditors ?? []);
742 const [resourceWindowMs, setResourceWindowMs] = useState(15 * 60_000);
743 const selectedResourceWindow =
744 RESOURCE_HISTORY_WINDOWS.find((option) => option.windowMs === resourceWindowMs) ??
745 RESOURCE_HISTORY_WINDOWS[1];
746 const { data, error, isPending, refresh } = useEnvironmentQuery(
747 environmentId === null || !canReadDiagnostics
748 ? null
749 : serverEnvironment.traceDiagnostics({ environmentId, input: {} }),
750 );
751 const {
752 data: processData,
753 error: processError,
754 isPending: isProcessPending,
755 refresh: refreshProcesses,
756 } = useEnvironmentQuery(
757 environmentId === null || !canReadDiagnostics
758 ? null
759 : serverEnvironment.processDiagnostics({ environmentId, input: {} }),
760 );
761 const {
762 data: resourceData,
763 error: resourceError,
764 isPending: isResourcePending,
765 refresh: refreshResources,
766 } = useEnvironmentQuery(
767 environmentId === null || !canReadDiagnostics
768 ? null
769 : serverEnvironment.processResourceHistory({
770 environmentId,
771 input: {
772 windowMs: selectedResourceWindow.windowMs,
773 bucketMs: selectedResourceWindow.bucketMs,
774 },
775 }),
776 );
777 const [isOpeningLogsDirectory, setIsOpeningLogsDirectory] = useState(false);
778 const [openLogsDirectoryError, setOpenLogsDirectoryError] = useState<string | null>(null);
779 const [signalingPid, setSignalingPid] = useState<number | null>(null);
780 const signalingPidRef = useRef<number | null>(null);
781
782 const openLogsDirectory = () => {
783 const logsDirectoryPath = observability?.logsDirectoryPath ?? null;
784 if (!logsDirectoryPath) return;
785
786 if (
787 environmentId === null ||
788 !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)
789 ) {
790 return;
791 }
792
793 setIsOpeningLogsDirectory(true);
794 setOpenLogsDirectoryError(null);
795 void (async () => {
796 const result = await openInEditor(logsDirectoryPath);
797 setIsOpeningLogsDirectory(false);
798 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
799 const error = squashAtomCommandFailure(result);
800 setOpenLogsDirectoryError(
801 error instanceof Error ? error.message : "Unable to open logs folder.",
802 );
803 }
804 })();
805 };
806
807 const isInitialLoading = isPending && data === null;
808 const isProcessInitialLoading = isProcessPending && processData === null;
809 const isResourceInitialLoading = isResourcePending && resourceData === null;
810 // Wait for initial tables to stabilize search targets; later loads must preserve export drafts.
811 const [exportFormEnvironmentId, setExportFormEnvironmentId] =
812 useState<typeof environmentId>(null);
813 if (
814 exportFormEnvironmentId !== environmentId &&
815 canReadDiagnostics &&
816 !isInitialLoading &&
817 !isProcessInitialLoading &&
818 !isResourceInitialLoading
819 ) {
820 setExportFormEnvironmentId(environmentId);
821 }
822 const signalProcess = async (pid: number, signal: ServerProcessSignal) => {
823 const targetEnvironmentId = environmentId;
824 const process = processData?.processes.find((entry) => entry.pid === pid);
825 if (
826 targetEnvironmentId === null ||
827 process === undefined ||
828 !readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)
829 )
830 return;
831 if (signalingPidRef.current !== null) return;
832 signalingPidRef.current = pid;
833 setSignalingPid(pid);
834 const clearSignaling = () => {
835 signalingPidRef.current = null;
836 setSignalingPid(null);
837 };
838 if (signal === "SIGKILL") {
839 let confirmed = false;
840 try {
841 confirmed = await ensureLocalApi().dialogs.confirm(
842 `Send SIGKILL to process ${pid}? This cannot be handled by the process.`,
843 { variant: "destructive" },
844 );
845 } catch (error) {
846 clearSignaling();
847 toastManager.add({
848 type: "error",
849 title: "Could not confirm signal",
850 description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
851 });
852 return;
853 }
854 if (!confirmed) {
855 clearSignaling();
856 return;
857 }
858 }
859 // The server rejects a pid whose start time no longer matches, so a process that exited
860 // during confirmation is never signaled by mistake.
861 if (!readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)) {
862 clearSignaling();
863 return;
864 }
865
866 const result = await signalServerProcess({
867 environmentId: targetEnvironmentId,
868 input: { pid, startTimeMs: process.startTimeMs, signal },
869 });
870 clearSignaling();
871 if (result._tag === "Failure") {
872 if (!isAtomCommandInterrupted(result)) {
873 const error = squashAtomCommandFailure(result);
874 toastManager.add({
875 type: "error",
876 title: `Could not send ${signal}`,
877 description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
878 });
879 }
880 return;
881 }
882 if (!result.value.signaled) {
883 const message = Option.getOrUndefined(result.value.message);
884 refreshProcesses();
885 if (isStaleProcessSignalMessage(message)) {
886 toastManager.add({
887 type: "info",
888 title: "Process already exited",
889 description: "The process is not a child of the T3 Server. It might already have exited.",
890 });
891 return;
892 }
893
894 toastManager.add({
895 type: "error",
896 title: `Could not send ${signal}`,
897 description: message ?? `Failed to send ${signal}.`,
898 });
899 return;
900 }
901 refreshProcesses();
902 };
903
904 const processDiagnosticsError = processData ? Option.getOrNull(processData.error) : null;
905 const processResourceError = resourceData ? Option.getOrNull(resourceData.error) : null;
906 const traceDiagnosticsError = data ? Option.getOrNull(data.error) : null;
907 const traceDiagnosticsPartialFailure = data
908 ? Option.getOrElse(data.partialFailure, () => false)
909 : false;
910
911 if (!canReadDiagnostics) {
912 return (
913 <SettingsPageContainer>
914 <p className="text-sm text-muted-foreground">
915 {environmentId === null
916 ? "Connect an environment to see diagnostics."
917 : diagnosticsAccess.isPending
918 ? "Checking diagnostics access…"
919 : diagnosticsAccess.error}
920 </p>
921 </SettingsPageContainer>
922 );
923 }
924
925 return (
926 <SettingsPageContainer width="expanded" className="gap-10">
927 <ResourceTelemetryDiagnostics environmentId={environmentId} />
928
929 <SettingsSection
930 title="Live Processes"
931 headerAction={
932 <div className="flex items-center gap-1.5">
933 <DiagnosticsLastChecked checkedAt={processData?.readAt ?? null} />
934 <DiagnosticsRefreshButton
935 isPending={isProcessPending}
936 label="Refresh process diagnostics"
937 onClick={refreshProcesses}
938 />
939 </div>
940 }
941 >
942 <StatsGrid>
943 <StatBlock
944 label="Child Processes"
945 value={processData ? formatCount(processData.processCount) : "..."}
946 />
947 <StatBlock
948 label="CPU"
949 value={processData ? `${processData.totalCpuPercent.toFixed(1)}%` : "..."}
950 tooltip="Total CPU across live child processes of the current server process. The desktop shell and other parent processes are not included."
951 />
952 <StatBlock
953 label="Memory"
954 value={processData ? formatBytes(processData.totalRssBytes) : "..."}
955 tooltip="Total resident memory across live child processes of the current server process. The desktop shell and other parent processes are not included."
956 />
957 <StatBlock
958 label="Server PID"
959 value={processData ? String(processData.serverPid) : "..."}
960 />
961 </StatsGrid>
962 {processDiagnosticsError || processError ? (
963 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
964 {processDiagnosticsError ? (
965 <div className="flex items-start gap-2 text-destructive">
966 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
967 <span>{processDiagnosticsError.message}</span>
968 </div>
969 ) : null}
970 {processError ? (
971 <div className="flex items-start gap-2 text-destructive">
972 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
973 <span>{processError}</span>
974 </div>
975 ) : null}
976 </div>
977 ) : null}
978 <ProcessDiagnosticsTable
979 processes={processData?.processes ?? []}
980 canMaintainEnvironment={canMaintainEnvironment}
981 signalingPid={signalingPid}
982 onSignal={signalProcess}
983 emptyLabel={
984 isProcessInitialLoading
985 ? "Loading live processes..."
986 : "No live descendant processes found."
987 }
988 />
989 </SettingsSection>
990
991 <SettingsSection
992 title="Resource History"
993 headerAction={
994 <div className="flex items-center gap-1.5">
995 <ResourceHistoryWindowSelector
996 selectedWindowMs={resourceWindowMs}
997 onSelect={setResourceWindowMs}
998 />
999 <DiagnosticsLastChecked checkedAt={resourceData?.readAt ?? null} />
1000 <DiagnosticsRefreshButton
1001 isPending={isResourcePending}
1002 label="Refresh resource history"
1003 onClick={refreshResources}
1004 />
1005 </div>
1006 }
1007 >
1008 <StatsGrid>
1009 <StatBlock
1010 label="CPU Time"
1011 value={resourceData ? formatCpuTime(resourceData.totalCpuSecondsApprox) : "..."}
1012 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."
1013 />
1014 <StatBlock
1015 label="Samples"
1016 value={resourceData ? formatCount(resourceData.retainedSampleCount) : "..."}
1017 tooltip="In-memory process samples retained by the server. The server samples only while diagnostics is open, and this resets when the server restarts."
1018 />
1019 <StatBlock
1020 label="Interval"
1021 value={
1022 resourceData
1023 ? resourceData.sampleIntervalMs === 0
1024 ? "On demand"
1025 : formatDuration(resourceData.sampleIntervalMs)
1026 : "..."
1027 }
1028 />
1029 <StatBlock
1030 label="Processes"
1031 value={resourceData ? formatCount(resourceData.topProcesses.length) : "..."}
1032 />
1033 </StatsGrid>
1034 {processResourceError || resourceError ? (
1035 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
1036 {processResourceError ? (
1037 <div className="flex items-start gap-2 text-destructive">
1038 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1039 <span>{processResourceError.message}</span>
1040 </div>
1041 ) : null}
1042 {resourceError ? (
1043 <div className="flex items-start gap-2 text-destructive">
1044 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1045 <span>{resourceError}</span>
1046 </div>
1047 ) : null}
1048 </div>
1049 ) : null}
1050 <ProcessResourceHistoryChart buckets={resourceData?.buckets ?? []} />
1051 <ProcessResourceHistoryTable
1052 processes={resourceData?.topProcesses ?? []}
1053 emptyLabel={
1054 isResourceInitialLoading
1055 ? "Collecting process resource samples..."
1056 : "No process resource samples found for this window."
1057 }
1058 />
1059 </SettingsSection>
1060
1061 <SettingsSection
1062 title="Trace Diagnostics"
1063 headerAction={
1064 <div className="flex items-center gap-1.5">
1065 <DiagnosticsLastChecked checkedAt={data?.readAt ?? null} />
1066 <Tooltip>
1067 <TooltipTrigger
1068 render={
1069 <Button
1070 size="icon-xs"
1071 variant="ghost-muted"
1072 disabled={
1073 !canOpenHostEditor ||
1074 !observability?.logsDirectoryPath ||
1075 isOpeningLogsDirectory
1076 }
1077 onClick={openLogsDirectory}
1078 aria-label="Open logs folder"
1079 >
1080 <FolderOpenIcon />
1081 </Button>
1082 }
1083 />
1084 <TooltipPopup side="top">Open logs folder</TooltipPopup>
1085 </Tooltip>
1086 <DiagnosticsRefreshButton
1087 isPending={isPending}
1088 label="Refresh trace diagnostics"
1089 onClick={refresh}
1090 />
1091 </div>
1092 }
1093 >
1094 <StatsGrid>
1095 <StatBlock label="Spans" value={data ? formatCount(data.recordCount) : "..."} />
1096 <StatBlock
1097 label="Failures"
1098 value={data ? formatCount(data.failureCount) : "..."}
1099 tone={data && data.failureCount > 0 ? "danger" : "default"}
1100 />
1101 <StatBlock
1102 label="Slow Spans"
1103 value={data ? formatCount(data.slowSpanCount) : "..."}
1104 tooltip={
1105 data
1106 ? `Spans with a duration of ${formatDuration(data.slowSpanThresholdMs)} or longer.`
1107 : "Spans at or above the configured slow-span threshold."
1108 }
1109 tone={data && data.slowSpanCount > 0 ? "warning" : "default"}
1110 />
1111 <StatBlock
1112 label="Parse Errors"
1113 value={data ? formatCount(data.parseErrorCount) : "..."}
1114 tone={data && data.parseErrorCount > 0 ? "warning" : "default"}
1115 />
1116 </StatsGrid>
1117 {openLogsDirectoryError || traceDiagnosticsError || error ? (
1118 <div className="space-y-2 border-t border-border/60 px-4 py-3 text-xs text-muted-foreground sm:px-5">
1119 {openLogsDirectoryError ? (
1120 <div className="flex items-start gap-2 text-destructive">
1121 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1122 <span>{openLogsDirectoryError}</span>
1123 </div>
1124 ) : null}
1125 {traceDiagnosticsError ? (
1126 <div
1127 className={cn(
1128 "flex items-start gap-2",
1129 traceDiagnosticsPartialFailure ? "text-warning-foreground" : "text-destructive",
1130 )}
1131 >
1132 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1133 <span>
1134 {traceDiagnosticsPartialFailure
1135 ? `Some trace files could not be read, so diagnostics may be incomplete. ${traceDiagnosticsError.message}`
1136 : traceDiagnosticsError.message}
1137 </span>
1138 </div>
1139 ) : null}
1140 {error ? (
1141 <div className="flex items-start gap-2 text-destructive">
1142 <AlertTriangleIcon className="size-3.5 h-lh shrink-0" />
1143 <span>{error}</span>
1144 </div>
1145 ) : null}
1146 </div>
1147 ) : null}
1148 </SettingsSection>
1149
1150 <SettingsSection title="Latest Failures">
1151 {data && data.latestFailures.length > 0 ? (
1152 <DiagnosticsTable headers={["Span", "Cause", "Duration", "Ended"]}>
1153 {data.latestFailures.map((failure) => (
1154 <tr key={`${failure.traceId}:${failure.spanId}`}>
1155 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1156 {failure.name}
1157 </td>
1158 <td className="max-w-[360px] px-4 py-3 align-top text-muted-foreground">
1159 <ExpandableText text={failure.cause} />
1160 </td>
1161 <td className="px-4 py-3 align-top font-mono tabular-nums">
1162 {formatDuration(failure.durationMs)}
1163 </td>
1164 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
1165 <RelativeTimeNoWrap value={failure.endedAt} />
1166 </td>
1167 </tr>
1168 ))}
1169 </DiagnosticsTable>
1170 ) : (
1171 <EmptyRows label={isInitialLoading ? "Loading failures..." : "No failed spans found."} />
1172 )}
1173 </SettingsSection>
1174
1175 <SettingsSection title="Most Common Failures">
1176 {data && data.commonFailures.length > 0 ? (
1177 <DiagnosticsTable
1178 headers={["Span", "Count", "Cause", "Last Seen"]}
1179 minTableWidth="min-w-[760px]"
1180 >
1181 {data.commonFailures.map((failure) => (
1182 <tr key={`${failure.name}:${failure.cause}`}>
1183 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1184 {failure.name}
1185 </td>
1186 <td className="px-4 py-3 align-top font-mono tabular-nums">
1187 {formatCount(failure.count)}
1188 </td>
1189 <td className="max-w-[360px] px-4 py-3 align-top text-muted-foreground">
1190 <ExpandableText text={failure.cause} />
1191 </td>
1192 <td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground last:sm:pr-5">
1193 <RelativeTimeNoWrap value={failure.lastSeenAt} />
1194 </td>
1195 </tr>
1196 ))}
1197 </DiagnosticsTable>
1198 ) : (
1199 <EmptyRows
1200 label={isInitialLoading ? "Loading failure groups..." : "No repeated failures found."}
1201 />
1202 )}
1203 </SettingsSection>
1204
1205 <SettingsSection title="Slowest Spans">
1206 {data && data.slowestSpans.length > 0 ? (
1207 <DiagnosticsTable
1208 headers={["Span", "Duration", "Ended", "Trace"]}
1209 minTableWidth="min-w-[900px]"
1210 columnWidths={["w-[44%]", "w-[14%]", "w-[12%]", "w-[30%]"]}
1211 >
1212 {data.slowestSpans.map((span) => (
1213 <tr key={`${span.traceId}:${span.spanId}`}>
1214 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1215 {span.name}
1216 </td>
1217 <td className="px-4 py-3 align-top font-mono tabular-nums">
1218 {formatDuration(span.durationMs)}
1219 </td>
1220 <td className="w-px whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground">
1221 <RelativeTimeNoWrap value={span.endedAt} />
1222 </td>
1223 <td className="min-w-0 whitespace-nowrap px-4 py-3 align-top text-muted-foreground last:sm:pr-5">
1224 <TraceIdCell traceId={span.traceId} />
1225 </td>
1226 </tr>
1227 ))}
1228 </DiagnosticsTable>
1229 ) : (
1230 <EmptyRows label={isInitialLoading ? "Loading slow spans..." : "No spans found."} />
1231 )}
1232 </SettingsSection>
1233
1234 <SettingsSection title="Span Logs">
1235 {data && data.latestWarningAndErrorLogs.length > 0 ? (
1236 <ScrollArea
1237 radius="none"
1238 chainVerticalScroll
1239 scrollFade
1240 hideScrollbars
1241 className="w-full max-w-full"
1242 >
1243 <table className="w-full min-w-[920px] table-fixed text-left text-xs">
1244 <colgroup>
1245 <col className="w-[11%]" />
1246 <col className="w-[9%]" />
1247 <col className="w-[24%]" />
1248 <col className="w-[26%]" />
1249 <col className="w-[30%]" />
1250 </colgroup>
1251 <thead className="border-b border-border/60 text-2xs uppercase tracking-widest text-muted-foreground/70">
1252 <tr>
1253 <th className="whitespace-nowrap px-4 py-2.5 font-semibold sm:pl-5">Time</th>
1254 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Level</th>
1255 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Span</th>
1256 <th className="whitespace-nowrap px-4 py-2.5 font-semibold">Message</th>
1257 <th className="whitespace-nowrap px-4 py-2.5 font-semibold sm:pr-5">Trace</th>
1258 </tr>
1259 </thead>
1260 <tbody className="divide-y divide-border/60">
1261 {data.latestWarningAndErrorLogs.map((event) => (
1262 <tr
1263 key={`${event.traceId}:${event.spanId}:${DateTime.formatIso(event.seenAt)}:${event.message}`}
1264 className="hover:bg-muted/15"
1265 >
1266 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums text-muted-foreground sm:pl-5">
1267 <RelativeTimeNoWrap value={event.seenAt} />
1268 </td>
1269 <td className="px-4 py-3 align-top">
1270 <span className="inline-flex rounded bg-muted px-1.5 py-0.5 font-mono text-2xs font-medium uppercase text-foreground/80">
1271 {event.level}
1272 </span>
1273 </td>
1274 <td className="px-4 py-3 align-top">
1275 <div className="truncate font-medium text-foreground">{event.spanName}</div>
1276 </td>
1277 <td className="px-4 py-3 align-top text-muted-foreground">
1278 <ExpandableText
1279 collapsedClassName="line-clamp-2"
1280 expandLabel="Show full message"
1281 text={event.message}
1282 />
1283 </td>
1284 <td className="min-w-0 whitespace-nowrap px-4 py-3 align-top text-muted-foreground sm:pr-5">
1285 <TraceIdCell traceId={event.traceId} />
1286 </td>
1287 </tr>
1288 ))}
1289 </tbody>
1290 </table>
1291 </ScrollArea>
1292 ) : (
1293 <EmptyRows
1294 label={isInitialLoading ? "Loading recent logs..." : "No warnings or errors found."}
1295 />
1296 )}
1297 </SettingsSection>
1298
1299 <SettingsSection title="Top Span Names">
1300 {data && data.topSpansByCount.length > 0 ? (
1301 <DiagnosticsTable
1302 headers={["Span", "Count", "Failures", "Average", "Max"]}
1303 minTableWidth="min-w-[760px]"
1304 columnWidths={["w-[48%]", "w-[13%]", "w-[13%]", "w-[13%]", "w-[13%]"]}
1305 >
1306 {data.topSpansByCount.map((span) => (
1307 <tr key={span.name}>
1308 <td className="px-4 py-3 align-top text-xs font-medium text-foreground first:sm:pl-5">
1309 {span.name}
1310 </td>
1311 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1312 {formatCount(span.count)}
1313 </td>
1314 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1315 {formatCount(span.failureCount)}
1316 </td>
1317 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums">
1318 {formatDuration(span.averageDurationMs)}
1319 </td>
1320 <td className="whitespace-nowrap px-4 py-3 align-top font-mono tabular-nums last:sm:pr-5">
1321 {formatDuration(span.maxDurationMs)}
1322 </td>
1323 </tr>
1324 ))}
1325 </DiagnosticsTable>
1326 ) : (
1327 <EmptyRows label={isInitialLoading ? "Loading span names..." : "No spans found."} />
1328 )}
1329 </SettingsSection>
1330 {exportFormEnvironmentId === environmentId && <TelemetryExportSettings />}
1331 </SettingsPageContainer>
1332 );
1333}