🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(web): show error id in tRPC error toast and include it in issue reports (#17427)
Niklas Semmlerb00e9188bb57
diff --git a/web/src/features/notifications/ErrorNotification.tsx b/web/src/features/notifications/ErrorNotification.tsxindex 4ab27e8927..2fa6cc1f51 100644--- a/web/src/features/notifications/ErrorNotification.tsx+++ b/web/src/features/notifications/ErrorNotification.tsx@@ -2,7 +2,8 @@ import { Button } from "@/src/components/ui/button";import { usePostHogClientCapture } from "@/src/features/posthog-analytics";import { useSupportDrawer } from "@/src/features/support-chat";import { useV4MigrationPanel } from "@/src/features/v4-migration/V4MigrationPanelProvider";-import { AlertTriangle, X } from "lucide-react";+import { useCopyToClipboard } from "@/src/hooks/useCopyToClipboard";+import { AlertTriangle, Check, Copy, X } from "lucide-react";interface ErrorNotificationProps {error: string;@@ -11,6 +12,7 @@ interface ErrorNotificationProps {dismissToast: (t?: string | number | undefined) => void;toast: string | number;path?: string;+ traceId?: string;}export const ErrorNotification: React.FC<ErrorNotificationProps> = ({@@ -20,24 +22,17 @@ export const ErrorNotification: React.FC<ErrorNotificationProps> = ({dismissToast,toast,path,+ traceId,}) => {const { setOpen } = useSupportDrawer();const { setOpen: setMigrationPanelOpen } = useV4MigrationPanel();const capture = usePostHogClientCapture();+ const { copy, isCopied } = useCopyToClipboard();const isError = type === "ERROR";const textColor = isError? "text-destructive-foreground": "text-dark-yellow";- // const handleReportIssueClick = () => {- // if (chatAvailable) {- // const currentUrl = window.location.href;- // const message = `I received the following error:\n\nError: ${error}\nDescription: ${description}\n ${path ? `Path: ${path}\n` : ""}URL: ${currentUrl}`;- // sendUserChatMessage(message);- // dismissToast(toast);- // }- // };-return (<div className="flex justify-between"><div className="flex min-w-[300px] flex-1 flex-col gap-2">@@ -59,6 +54,24 @@ export const ErrorNotification: React.FC<ErrorNotificationProps> = ({Path: {path}</div>)}+ {traceId && (+ <div+ className={`flex items-start gap-1 text-sm leading-tight ${textColor}`}+ >+ <span className="min-w-0 break-all">Error ID: {traceId}</span>+ <button+ className={`flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center border-none bg-transparent p-0 ${textColor}`}+ onClick={() => copy(traceId).catch(() => undefined)}+ onPointerDown={(e) => {+ e.stopPropagation();+ }}+ aria-label="Copy error ID"+ title="Copy error ID"+ >+ {isCopied ? <Check size={14} /> : <Copy size={14} />}+ </button>+ </div>+ )}{isError && (<Button@@ -70,7 +83,14 @@ export const ErrorNotification: React.FC<ErrorNotificationProps> = ({path,});setMigrationPanelOpen(false);- setOpen(true);+ setOpen(true, {+ message: formatReportIssueMessage({+ error,+ description,+ path,+ traceId,+ }),+ });}}>Report issue to Langfuse team@@ -101,3 +121,20 @@ export const ErrorNotification: React.FC<ErrorNotificationProps> = ({</div>);};++const formatReportIssueMessage = (details: {+ error: string;+ description: string;+ path?: string;+ traceId?: string;+}) => {+ const lines = [+ "I received the following error:",+ "",+ `Error: ${details.error}`,+ ];+ if (details.description) lines.push(`Description: ${details.description}`);+ if (details.path) lines.push(`Path: ${details.path}`);+ if (details.traceId) lines.push(`Error ID: ${details.traceId}`);+ return `${lines.join("\n")}\n\n`;+};diff --git a/web/src/features/notifications/showErrorToast.tsx b/web/src/features/notifications/showErrorToast.tsxindex e243d9d570..68404bec69 100644--- a/web/src/features/notifications/showErrorToast.tsx+++ b/web/src/features/notifications/showErrorToast.tsx@@ -21,6 +21,7 @@ export const showErrorToast = (description: string,type: "WARNING" | "ERROR" = "ERROR",path?: string,+ traceId?: string,) => {toast.custom((t) => (@@ -29,6 +30,7 @@ export const showErrorToast = (description={description}type={type}path={path}+ traceId={traceId}dismissToast={toast.dismiss}toast={t}/>diff --git a/web/src/features/support-chat/ConnectedSupportFormSection.tsx b/web/src/features/support-chat/ConnectedSupportFormSection.tsxindex fe0e06a6f4..0b49a42311 100644--- a/web/src/features/support-chat/ConnectedSupportFormSection.tsx+++ b/web/src/features/support-chat/ConnectedSupportFormSection.tsx@@ -20,7 +20,7 @@ export function ConnectedSupportFormSection({onSuccess: () => void;}) {const { organization, project } = useQueryProjectOrOrganization();- const { initialTopic } = useSupportDrawer();+ const { initialTopic, initialMessage } = useSupportDrawer();const showV4MigrationTopic = useV4UpgradeUiEnabled(project?.id);// The support drawer is mounted globally and reachable from pages without an// org/project in the URL (home, setup, onboarding, account settings), where@@ -125,6 +125,7 @@ export function ConnectedSupportFormSection({<SupportFormcanSelectHighSeverity={canSelectHighSeverity}initialTopic={initialTopic ?? ""}+ initialMessage={initialMessage}showV4MigrationTopic={showV4MigrationTopic}onCancel={onCancel}onSuccess={onSuccess}diff --git a/web/src/features/support-chat/SupportDrawerProvider.clienttest.tsx b/web/src/features/support-chat/SupportDrawerProvider.clienttest.tsxindex 34dde938b9..dfeef8441f 100644--- a/web/src/features/support-chat/SupportDrawerProvider.clienttest.tsx+++ b/web/src/features/support-chat/SupportDrawerProvider.clienttest.tsx@@ -52,4 +52,21 @@ describe("SupportDrawerProvider", () => {expect(result.current.openEpoch).toBe(epoch + 1);expect(result.current.initialMode).toBe("form");});++ it("seeds the form message on closed→open only", () => {+ const { result } = renderHook(() => useSupportDrawer(), { wrapper });++ act(() => result.current.setOpen(true, { message: "Error ID: abc123" }));+ const epoch = result.current.openEpoch;+ expect(result.current.initialMessage).toBe("Error ID: abc123");++ // Reporting a second error while open must not wipe the draft.+ act(() => result.current.setOpen(true, { message: "Error ID: def456" }));+ expect(result.current.openEpoch).toBe(epoch);+ expect(result.current.initialMessage).toBe("Error ID: abc123");++ act(() => result.current.setOpen(false));+ act(() => result.current.setOpen(true));+ expect(result.current.initialMessage).toBe("");+ });});diff --git a/web/src/features/support-chat/SupportDrawerProvider.tsx b/web/src/features/support-chat/SupportDrawerProvider.tsxindex 50a866168b..802ff6cca7 100644--- a/web/src/features/support-chat/SupportDrawerProvider.tsx+++ b/web/src/features/support-chat/SupportDrawerProvider.tsx@@ -11,18 +11,24 @@ export type SupportDrawerMode = "intro" | "form";type SupportDrawerContextType = {open: boolean;- setOpen: (v: boolean) => void;+ /** `message` seeds the support form, but only on a closed→open transition. */+ setOpen: (v: boolean, options?: { message?: string }) => void;/** Section the drawer shows when it opens; a closed→open resets to intro. */initialMode: SupportDrawerMode;/** Topic preselected in the support form; a closed→open resets it. */initialTopic: Topic | null;+ /** Message prefilled in the support form; a closed→open resets it. */+ initialMessage: string;/*** Bumped on closed→open transitions and on every openWithMode so the* drawer can remount via key and re-seed mode/topic. A redundant* setOpen(true) while already open does NOT bump it.*/openEpoch: number;- openWithMode: (mode: SupportDrawerMode, options?: { topic?: Topic }) => void;+ openWithMode: (+ mode: SupportDrawerMode,+ options?: { topic?: Topic; message?: string },+ ) => void;};const SupportDrawerContext = createContext<SupportDrawerContextType | null>(@@ -41,16 +47,18 @@ export function SupportDrawerProvider({const [open, setOpenState] = useState(defaultOpen);const [initialMode, setInitialMode] = useState<SupportDrawerMode>("intro");const [initialTopic, setInitialTopic] = useState<Topic | null>(null);+ const [initialMessage, setInitialMessage] = useState("");const [openEpoch, setOpenEpoch] = useState(0);const setOpen = useCallback(- (v: boolean) => {+ (v: boolean, options?: { message?: string }) => {// Reseed only on a closed→open transition: a redundant setOpen(true)// while open (support button, "Report issue") must not remount the// drawer and wipe an in-progress draft. openWithMode always reseeds.if (v && !open) {setInitialMode("intro");setInitialTopic(null);+ setInitialMessage(options?.message ?? "");setOpenEpoch((e) => e + 1);}setOpenState(v);@@ -59,9 +67,13 @@ export function SupportDrawerProvider({);const openWithMode = useCallback(- (mode: SupportDrawerMode, options?: { topic?: Topic }) => {+ (+ mode: SupportDrawerMode,+ options?: { topic?: Topic; message?: string },+ ) => {setInitialMode(mode);setInitialTopic(options?.topic ?? null);+ setInitialMessage(options?.message ?? "");setOpenEpoch((e) => e + 1);setOpenState(true);},@@ -75,6 +87,7 @@ export function SupportDrawerProvider({setOpen,initialMode,initialTopic,+ initialMessage,openEpoch,openWithMode,}}diff --git a/web/src/features/support-chat/SupportForm.tsx b/web/src/features/support-chat/SupportForm.tsxindex 765cd51276..5557bf6425 100644--- a/web/src/features/support-chat/SupportForm.tsx+++ b/web/src/features/support-chat/SupportForm.tsx@@ -49,6 +49,7 @@ export type SupportFormSubmitStatus = "success" | "kept";export type SupportFormProps = {canSelectHighSeverity: boolean;initialTopic: Topic | "";+ initialMessage?: string;showV4MigrationTopic: boolean;onCancel: () => void;onSuccess: () => void;@@ -175,6 +176,7 @@ function isSeveritySelectable(export function SupportForm({canSelectHighSeverity,initialTopic,+ initialMessage = "",showV4MigrationTopic,onCancel,onSuccess,@@ -200,7 +202,7 @@ export function SupportForm({messageType: "Question" as MessageType,severity: SEVERITY_3,topic: initialTopic,- message: "",+ message: initialMessage,integrationType: "",},mode: "onSubmit",diff --git a/web/src/utils/trpcErrorToast.clienttest.ts b/web/src/utils/trpcErrorToast.clienttest.tsindex ea4c5a9f18..0912ff344d 100644--- a/web/src/utils/trpcErrorToast.clienttest.ts+++ b/web/src/utils/trpcErrorToast.clienttest.ts@@ -30,6 +30,7 @@ const trpcError = (opts: {message: string;path?: string;zodError?: unknown;+ traceId?: string;}) =>TRPCClientError.from({error: {@@ -40,6 +41,7 @@ const trpcError = (opts: {httpStatus: opts.httpStatus,...(opts.path !== undefined ? { path: opts.path } : {}),...(opts.zodError !== undefined ? { zodError: opts.zodError } : {}),+ ...(opts.traceId !== undefined ? { traceId: opts.traceId } : {}),},},});@@ -123,6 +125,7 @@ describe("trpcErrorToast", () => {"name: Too small: expected string to have >=1 characters","WARNING","prompts.create",+ undefined,);});@@ -141,6 +144,27 @@ describe("trpcErrorToast", () => {"Invalid input, projectId is required","WARNING","prompts.create",+ undefined,+ );+ });++ it("forwards the OTEL trace id to the toast when present", () => {+ trpcErrorToast(+ trpcError({+ code: "INTERNAL_SERVER_ERROR",+ httpStatus: 500,+ path: "prompts.create",+ message: "Something went wrong",+ traceId: "abc123def456",+ }),+ );++ expect(showErrorToastMock).toHaveBeenCalledWith(+ "Internal Server Error",+ "Something went wrong",+ "ERROR",+ "prompts.create",+ "abc123def456",);});});diff --git a/web/src/utils/trpcErrorToast.tsx b/web/src/utils/trpcErrorToast.tsxindex 2f020545bf..2d3b1d6eb0 100644--- a/web/src/utils/trpcErrorToast.tsx+++ b/web/src/utils/trpcErrorToast.tsx@@ -96,6 +96,11 @@ export const trpcErrorToast = (error: unknown) => {const { errorTitle, httpStatus } = getErrorTitleAndHttpCode(error);const path = error.data?.path;+ // OTEL trace id attached by the tRPC errorFormatter; absent when OTEL is not+ // running (self-hosted / unsampled). Surfaced so users can share it in+ // support tickets for correlation.+ const traceId =+ typeof error.data?.traceId === "string" ? error.data.traceId : undefined;const validationDescription = formatTrpcZodValidationDescription(error);const description =validationDescription ?? error.message ?? getErrorDescription(httpStatus);@@ -105,6 +110,7 @@ export const trpcErrorToast = (error: unknown) => {description,httpStatus >= 500 && httpStatus < 600 ? "ERROR" : "WARNING",path,+ traceId,);} else {showErrorToast(