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

DiagnosticsSettings.tsx

1,424 lines50.7 KB

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