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