Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(trace-log): better behaviour for large traces (#10211)

Nimar26803ceb2396
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 84be1b0766..3cfaf01f54 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -53,7 +53,7 @@ importers:
next-auth:
specifier: ^4.24.12
zod:
specifier: ^3.25.62
version: 3.25.62
@@ -236,7 +236,7 @@ importers:
version: 4.1.1
next-auth:
specifier: ^4.24.12
nodemailer:
specifier: ^7.0.10
version: 7.0.10
@@ -633,7 +633,7 @@ importers:
next-auth:
specifier: ^4.24.12
next-query-params:
specifier: ^5.1.0
@@ -17603,7 +17603,7 @@ snapshots:
dependencies:
dependencies:
@@ -21093,7 +21093,7 @@ snapshots:
dependencies:
- '@types/node': 24.10.0
+ '@types/node': 24.3.0
optional: true
@@ -24196,7 +24196,7 @@ snapshots:
dependencies:
- debug: 4.3.4
+ debug: 4.4.3
get-stream: 5.2.0
yauzl: 2.10.0
optionalDependencies:
@@ -27037,7 +27037,7 @@ snapshots:
dependencies:
type-fest: 2.19.0
dependencies:
'@babel/runtime': 7.28.4
'@panva/hkdf': 1.2.1
diff --git a/web/src/components/trace/TraceLogView.tsx b/web/src/components/trace/TraceLogView.tsx
index 71fc6982e0..a9e4bf0aa3 100644
--- a/web/src/components/trace/TraceLogView.tsx
+++ b/web/src/components/trace/TraceLogView.tsx
@@ -1,4 +1,4 @@
-import { useMemo, useEffect } from "react";
+import { useMemo, useEffect, useCallback } from "react";
import { PrettyJsonView } from "@/src/components/ui/PrettyJsonView";
import { type ObservationReturnTypeWithMetadata } from "@/src/server/api/routers/traces";
import { api } from "@/src/utils/api";
@@ -6,6 +6,9 @@ import { StringParam, useQueryParam } from "use-query-params";
import { useQueries } from "@tanstack/react-query";
import { type JsonNested } from "@langfuse/shared";
import { useJsonExpansion } from "@/src/components/trace/JsonExpansionContext";
+import { Download } from "lucide-react";
+import { Button } from "@/src/components/ui/button";
+import { downloadTraceAsJson as downloadTraceUtil } from "@/src/components/trace/lib/helpers";
// for Json Expansion Context State (keeps expanded/collapsed state across traces)
@@ -85,11 +88,16 @@ export const TraceLogView = ({
traceId,
projectId,
currentView,
+ trace,
}: {
observations: ObservationReturnTypeWithMetadata[];
traceId: string;
projectId: string;
currentView: "pretty" | "json";
+ trace: {
+ id: string;
+ [key: string]: unknown;
+ };
}) => {
const [currentObservationId] = useQueryParam("observation", StringParam);
const [selectedTab] = useQueryParam("view", StringParam);
@@ -196,7 +204,7 @@ export const TraceLogView = ({
`[data-observation-id="${keyPathFormat}"]`,
);
if (element) {
- element.scrollIntoView({ behavior: "smooth", block: "center" });
+ element.scrollIntoView({ behavior: "smooth", block: "start" });
}
}
}
@@ -214,6 +222,41 @@ export const TraceLogView = ({
[expansionState.log, observationKeys],
);
+ // download includes trace + observations with full I/O
+ const downloadLogAsJson = useCallback(() => {
+ const observationsWithFullData = observations.map((obs, index) => {
+ const obsWithIO = observationsWithIO[index]?.data;
+ return {
+ ...obs,
+ input: obsWithIO?.input,
+ output: obsWithIO?.output,
+ metadata: obsWithIO?.metadata,
+ };
+ });
+
+ downloadTraceUtil({
+ trace,
+ observations: observationsWithFullData,
+ filename: `trace-with-observations-${traceId}.json`,
+ });
+ }, [trace, observations, observationsWithIO, traceId]);
+
+ // Only render the actual log view when all data is loaded
+ // prevents partial rendering and improves performance
+ if (isLoading) {
+ return (
+ <div className="flex h-full w-full flex-col overflow-hidden pr-3">
+ <div className="mb-2 flex max-h-full min-h-0 w-full flex-col gap-2 overflow-y-auto">
+ <div className="rounded-md border p-4">
+ <div className="text-sm text-muted-foreground">
+ Loading {observations.length} observations...
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+ }
+
return (
<div className="flex h-full w-full flex-col overflow-hidden pr-3">
<div className="mb-2 flex max-h-full min-h-0 w-full flex-col gap-2 overflow-y-auto">
@@ -222,7 +265,7 @@ export const TraceLogView = ({
title="Concatenated Observation Log"
json={logData.data}
currentView={currentView}
- isLoading={isLoading}
+ isLoading={false}
showNullValues={false}
externalExpansionState={denormalizedState}
onExternalExpansionChange={(expansion) =>
@@ -230,6 +273,17 @@ export const TraceLogView = ({
}
stickyTopLevelKey={true}
showObservationTypeBadge={true}
+ controlButtons={
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={downloadLogAsJson}
+ title="Download trace log as JSON"
+ className="-mr-2"
+ >
+ <Download className="h-3 w-3" />
+ </Button>
+ }
/>
</div>
</div>
diff --git a/web/src/components/trace/TracePreview.tsx b/web/src/components/trace/TracePreview.tsx
index 429e27c401..8339de4add 100644
--- a/web/src/components/trace/TracePreview.tsx
+++ b/web/src/components/trace/TracePreview.tsx
@@ -46,6 +46,19 @@ import {
TooltipTrigger,
} from "@/src/components/ui/tooltip";
import TagList from "@/src/features/tag/components/TagList";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/src/components/ui/alert-dialog";
+
+const LOG_VIEW_CONFIRMATION_THRESHOLD = 150;
+const LOG_VIEW_DISABLED_THRESHOLD = 350;
export const TracePreview = ({
trace,
@@ -116,14 +129,30 @@ export const TracePreview = ({
);
// For performance reasons, we preemptively disable the log view if there are too many observations.
- const isLogViewDisabled = observations.length > 150;
+ const isLogViewDisabled = observations.length > LOG_VIEW_DISABLED_THRESHOLD;
+ const requiresConfirmation =
+ observations.length > LOG_VIEW_CONFIRMATION_THRESHOLD && !isLogViewDisabled;
const showLogViewTab = observations.length > 0;
+
+ const [hasLogViewConfirmed, setHasLogViewConfirmed] = useState(false);
+ const [showLogViewDialog, setShowLogViewDialog] = useState(false);
+
+ useEffect(() => {
+ setHasLogViewConfirmed(false);
+ }, [trace.id]);
+
useEffect(() => {
if ((isLogViewDisabled || !showLogViewTab) && selectedTab === "log") {
setSelectedTab("preview");
}
}, [isLogViewDisabled, showLogViewTab, selectedTab, setSelectedTab]);
+ const handleConfirmLogView = () => {
+ setHasLogViewConfirmed(true);
+ setShowLogViewDialog(false);
+ setSelectedTab("log");
+ };
+
return (
<div className="col-span-2 flex h-full flex-1 flex-col overflow-hidden md:col-span-3">
<div className="flex h-full flex-1 flex-col items-start gap-1 overflow-hidden">
@@ -270,6 +299,15 @@ export const TracePreview = ({
}
className="flex min-h-0 flex-1 flex-col overflow-hidden"
onValueChange={(value) => {
+ // on tab click, is confirmation is needed?
+ if (
+ value === "log" &&
+ requiresConfirmation &&
+ !hasLogViewConfirmed
+ ) {
+ setShowLogViewDialog(true);
+ return;
+ }
capture("trace_detail:view_mode_switch", { mode: value });
setSelectedTab(value);
}}
@@ -282,12 +320,14 @@ export const TracePreview = ({
<TabsBarTrigger value="log" disabled={isLogViewDisabled}>
<Tooltip>
<TooltipTrigger asChild>
- <span>Log View (Beta)</span>
+ <span>Log View</span>
</TooltipTrigger>
<TooltipContent className="text-xs">
{isLogViewDisabled
- ? `Log View is disabled for traces with more than 150 observations (this trace has ${observations.length})`
- : "Shows all observations concatenated. Great for quickly scanning through them. Nullish values are omitted."}
+ ? `Log View is disabled for traces with more than ${LOG_VIEW_DISABLED_THRESHOLD} observations (this trace has ${observations.length})`
+ : requiresConfirmation
+ ? `Log View may be slow with ${observations.length} observations. Click to confirm.`
+ : "Shows all observations concatenated. Great for quickly scanning through them. Nullish values are omitted."}
</TooltipContent>
</Tooltip>
</TabsBarTrigger>
@@ -390,6 +430,7 @@ export const TracePreview = ({
traceId={trace.id}
projectId={trace.projectId}
currentView={currentView}
+ trace={trace}
/>
</TabsBarContent>
{showScoresTab && (
@@ -410,6 +451,27 @@ export const TracePreview = ({
)}
</TabsBar>
</div>
+
+ {/* Confirmation dialog for log view with many observations */}
+ <AlertDialog open={showLogViewDialog} onOpenChange={setShowLogViewDialog}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Sluggish Performance Warning</AlertDialogTitle>
+ <AlertDialogDescription>
+ This trace has {observations.length} observations. The log view
+ may be slow to load and interact with. Do you want to continue?
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel onClick={() => setShowLogViewDialog(false)}>
+ Cancel
+ </AlertDialogCancel>
+ <AlertDialogAction onClick={handleConfirmLogView}>
+ Show Log View
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</div>
);
};
diff --git a/web/src/components/trace/index.tsx b/web/src/components/trace/index.tsx
index 3e3ce980d3..b57c15c80c 100644
--- a/web/src/components/trace/index.tsx
+++ b/web/src/components/trace/index.tsx
@@ -32,7 +32,10 @@ import { Button } from "@/src/components/ui/button";
import { cn } from "@/src/utils/tailwind";
import useSessionStorage from "@/src/components/useSessionStorage";
import { JsonExpansionProvider } from "@/src/components/trace/JsonExpansionContext";
-import { buildTraceUiData } from "@/src/components/trace/lib/helpers";
+import {
+ buildTraceUiData,
+ downloadTraceAsJson as downloadTraceUtil,
+} from "@/src/components/trace/lib/helpers";
import {
ResizablePanelGroup,
ResizablePanel,
@@ -260,24 +263,11 @@ export function Trace(props: {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
- const downloadTraceAsJson = useCallback(() => {
- const exportData = {
+ const handleDownloadTrace = useCallback(() => {
+ downloadTraceUtil({
trace: props.trace,
observations: props.observations,
- };
-
- const jsonString = JSON.stringify(exportData, null, 2);
- const blob = new Blob([jsonString], { type: "application/json" });
- const url = URL.createObjectURL(blob);
-
- const link = document.createElement("a");
- link.href = url;
- link.download = `trace-${props.trace.id}.json`;
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- URL.revokeObjectURL(url);
-
+ });
capture("trace_detail:download_button_click");
}, [props.trace, props.observations, capture]);
@@ -505,7 +495,7 @@ export function Trace(props: {
<Button
variant="ghost"
size="icon"
- onClick={downloadTraceAsJson}
+ onClick={handleDownloadTrace}
title="Download trace as JSON"
>
<Download className="h-4 w-4" />
@@ -745,7 +735,7 @@ export function Trace(props: {
<Button
variant="ghost"
size="icon"
- onClick={downloadTraceAsJson}
+ onClick={handleDownloadTrace}
title="Download trace as JSON"
>
<Download className="h-4 w-4" />
diff --git a/web/src/components/trace/lib/helpers.ts b/web/src/components/trace/lib/helpers.ts
index bd15dd00aa..b412f67620 100644
--- a/web/src/components/trace/lib/helpers.ts
+++ b/web/src/components/trace/lib/helpers.ts
@@ -342,3 +342,37 @@ export function buildTraceUiData(
return { tree, hiddenObservationsCount, searchItems: out };
}
+
+/**
+ * Download trace data with optionally observations as JSON file
+ * @param trace - Trace object to download
+ * @param observations - Array of observations (can be basic or with full I/O data)
+ * @param filename - Optional custom filename (defaults to trace-{traceId}.json)
+ */
+export function downloadTraceAsJson(params: {
+ trace: {
+ id: string;
+ [key: string]: unknown;
+ };
+ observations: unknown[];
+ filename?: string;
+}) {
+ const { trace, observations, filename } = params;
+
+ const exportData = {
+ trace,
+ observations,
+ };
+
+ const jsonString = JSON.stringify(exportData, null, 2);
+ const blob = new Blob([jsonString], { type: "application/json" });
+ const url = URL.createObjectURL(blob);
+
+ const link = document.createElement("a");
+ link.href = url;
+ link.download = filename || `trace-${trace.id}.json`;
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ URL.revokeObjectURL(url);
+}
diff --git a/web/src/components/ui/alert-dialog.tsx b/web/src/components/ui/alert-dialog.tsx
new file mode 100644
index 0000000000..d38e47056d
--- /dev/null
+++ b/web/src/components/ui/alert-dialog.tsx
@@ -0,0 +1,141 @@
+"use client";
+
+import * as React from "react";
+import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
+
+import { cn } from "@/src/utils/tailwind";
+import { buttonVariants } from "@/src/components/ui/button";
+
+const AlertDialog = AlertDialogPrimitive.Root;
+
+const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
+
+const AlertDialogPortal = AlertDialogPrimitive.Portal;
+
+const AlertDialogOverlay = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Overlay
+ className={cn(
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
+ className,
+ )}
+ {...props}
+ ref={ref}
+ />
+));
+AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
+
+const AlertDialogContent = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPortal>
+ <AlertDialogOverlay />
+ <AlertDialogPrimitive.Content
+ ref={ref}
+ className={cn(
+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
+ className,
+ )}
+ {...props}
+ />
+ </AlertDialogPortal>
+));
+AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;
+
+const AlertDialogHeader = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ "flex flex-col space-y-2 text-center sm:text-left",
+ className,
+ )}
+ {...props}
+ />
+);
+AlertDialogHeader.displayName = "AlertDialogHeader";
+
+const AlertDialogFooter = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
+ className,
+ )}
+ {...props}
+ />
+);
+AlertDialogFooter.displayName = "AlertDialogFooter";
+
+const AlertDialogTitle = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Title>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Title
+ ref={ref}
+ className={cn("text-lg font-semibold", className)}
+ {...props}
+ />
+));
+AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;
+
+const AlertDialogDescription = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Description>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Description
+ ref={ref}
+ className={cn("text-sm text-muted-foreground", className)}
+ {...props}
+ />
+));
+AlertDialogDescription.displayName =
+ AlertDialogPrimitive.Description.displayName;
+
+const AlertDialogAction = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Action>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Action
+ ref={ref}
+ className={cn(buttonVariants(), className)}
+ {...props}
+ />
+));
+AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
+
+const AlertDialogCancel = React.forwardRef<
+ React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
+ React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
+>(({ className, ...props }, ref) => (
+ <AlertDialogPrimitive.Cancel
+ ref={ref}
+ className={cn(
+ buttonVariants({ variant: "outline" }),
+ "mt-2 sm:mt-0",
+ className,
+ )}
+ {...props}
+ />
+));
+AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;
+
+export {
+ AlertDialog,
+ AlertDialogPortal,
+ AlertDialogOverlay,
+ AlertDialogTrigger,
+ AlertDialogContent,
+ AlertDialogHeader,
+ AlertDialogFooter,
+ AlertDialogTitle,
+ AlertDialogDescription,
+ AlertDialogAction,
+ AlertDialogCancel,
+};