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