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