Skip to content

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

feat(web): Show sentry error ID on crash page (#13310)

Ben Bachem9a85db1abaf2
diff --git a/web/src/components/CrashModal/CrashModal.stories.tsx b/web/src/components/CrashModal/CrashModal.stories.tsx
new file mode 100644
index 0000000000..e698cd0740
--- /dev/null
+++ b/web/src/components/CrashModal/CrashModal.stories.tsx
@@ -0,0 +1,34 @@
+import preview from "../../../.storybook/preview";
+import { CrashModal } from "./CrashModal";
+
+const SENTRY_EVENT_ID = "2f7f0f0d4b4b4d17bdeed6d3d59b8b92";
+
+const meta = preview.meta({
+ component: CrashModal,
+ args: {
+ description:
+ "Application error: a client-side exception has occurred while loading cloud.langfuse.com (see the browser console for more information).",
+ showReturnHome: true,
+ },
+});
+
+export const ClientCrash = meta.story({
+ args: {
+ sentryEventId: SENTRY_EVENT_ID,
+ },
+});
+
+export const HttpError = meta.story({
+ args: {
+ description: "Internal Server Error.",
+ statusCode: 500,
+ },
+});
+
+export const WithoutErrorId = meta.story({});
+
+export const WithoutCTA = meta.story({
+ args: {
+ showReturnHome: false,
+ },
+});
diff --git a/web/src/components/CrashModal/CrashModal.tsx b/web/src/components/CrashModal/CrashModal.tsx
new file mode 100644
index 0000000000..0e4716a01d
--- /dev/null
+++ b/web/src/components/CrashModal/CrashModal.tsx
@@ -0,0 +1,60 @@
+import Link from "next/link";
+import { CircleAlert } from "lucide-react";
+import { Button } from "@/src/components/ui/button";
+
+type CrashModalProps = {
+ description: string;
+ sentryEventId?: string;
+ showReturnHome: boolean;
+ statusCode?: number;
+};
+
+export const CrashModal = ({
+ description,
+ sentryEventId,
+ showReturnHome,
+ statusCode,
+}: CrashModalProps) => {
+ return (
+ <div className="border-border bg-card w-full max-w-xl rounded-xl border p-6 shadow-sm sm:p-8">
+ <div className="bg-destructive/10 text-destructive flex size-10 items-center justify-center rounded-full">
+ <CircleAlert className="size-5" aria-hidden="true" />
+ </div>
+
+ <div className="mt-4 min-w-0">
+ <h1 className="text-2xl font-semibold tracking-tight">
+ Something went wrong
+ </h1>
+ <p className="text-muted-foreground mt-2 text-sm leading-5">
+ {statusCode ? (
+ <span className="text-foreground mr-2 font-medium whitespace-nowrap">
+ Error {statusCode}
+ </span>
+ ) : null}
+ {description}
+ </p>
+
+ {sentryEventId ? (
+ <div className="border-border bg-muted/40 mt-5 rounded-lg border p-4">
+ <dl>
+ <div>
+ <dt className="text-muted-foreground text-xs font-medium">
+ Error ID
+ </dt>
+ <dd className="mt-1.5 font-mono text-xs leading-5 break-all">
+ {sentryEventId}
+ </dd>
+ </div>
+ </dl>
+ </div>
+ ) : null}
+
+ {showReturnHome ? (
+ <Button asChild className="mt-6">
+ <Link href="/">Return home</Link>
+ </Button>
+ ) : null}
+ </div>
+ </div>
+ );
+};
diff --git a/web/src/pages/_app.tsx b/web/src/pages/_app.tsx
index a1740b1a42..390d587faa 100644
--- a/web/src/pages/_app.tsx
+++ b/web/src/pages/_app.tsx
@@ -117,6 +117,8 @@ const MyApp: AppType<{ session: Session | null }> = ({
pageProps: { session, ...pageProps },
}) => {
const router = useRouter();
+ const skipAppLayout =
+ "skipAppLayout" in Component && Component.skipAppLayout === true;
useEffect(() => {
// PostHog (cloud.langfuse.com)
@@ -133,6 +135,13 @@ const MyApp: AppType<{ session: Session | null }> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ const page = (
+ <>
+ <Component {...pageProps} />
+ <UserTracking />
+ </>
+ );
+
return (
<QueryParamProvider
adapter={NextAdapterPages}
@@ -158,10 +167,11 @@ const MyApp: AppType<{ session: Session | null }> = ({
<CorrectionCacheProvider>
<SupportDrawerProvider defaultOpen={false}>
<InAppAiAgentProvider defaultOpen={false}>
- <AppLayout>
- <Component {...pageProps} />
- <UserTracking />
- </AppLayout>
+ {skipAppLayout ? (
+ page
+ ) : (
+ <AppLayout>{page}</AppLayout>
+ )}
</InAppAiAgentProvider>
</SupportDrawerProvider>
</CorrectionCacheProvider>
diff --git a/web/src/pages/_error.tsx b/web/src/pages/_error.tsx
new file mode 100644
index 0000000000..233a7a3078
--- /dev/null
+++ b/web/src/pages/_error.tsx
@@ -0,0 +1,79 @@
+import {
+ captureUnderscoreErrorException,
+ isEnabled as isSentryEnabled,
+} from "@sentry/nextjs";
+import Head from "next/head";
+import NextErrorComponent, { type ErrorProps } from "next/error";
+import type { NextPageContext } from "next";
+import { CrashModal } from "@/src/components/CrashModal/CrashModal";
+
+type LangfuseErrorPageProps = ErrorProps & {
+ sentryEventId?: string;
+ showReturnHome: boolean;
+};
+
+const statusTitles: Record<number, string> = {
+ 400: "Bad Request",
+ 404: "This page could not be found",
+ 405: "Method Not Allowed",
+ 500: "Internal Server Error",
+};
+
+const ErrorPage = ({
+ hostname,
+ sentryEventId,
+ showReturnHome,
+ statusCode,
+ title,
+}: LangfuseErrorPageProps) => {
+ const resolvedTitle =
+ title ??
+ (statusCode ? statusTitles[statusCode] : undefined) ??
+ "An unexpected error has occurred";
+
+ const description = statusCode
+ ? `${resolvedTitle}.`
+ : `Application error: a client-side exception has occurred${
+ hostname ? ` while loading ${hostname}` : ""
+ } (see the browser console for more information).`;
+
+ const documentTitle = statusCode
+ ? `${statusCode}: ${resolvedTitle}`
+ : "Application error: a client-side exception has occurred";
+
+ return (
+ <>
+ <Head>
+ <title>{documentTitle}</title>
+ </Head>
+ <div className="min-h-screen-with-banner bg-background text-foreground flex items-center justify-center px-6 py-10">
+ <CrashModal
+ description={description}
+ sentryEventId={sentryEventId}
+ showReturnHome={showReturnHome}
+ statusCode={statusCode}
+ />
+ </div>
+ </>
+ );
+};
+
+ErrorPage.skipAppLayout = true;
+
+ErrorPage.getInitialProps = async (
+ context: NextPageContext,
+): Promise<LangfuseErrorPageProps> => {
+ const errorInitialProps = await NextErrorComponent.getInitialProps(context);
+ const sentryEventId = isSentryEnabled()
+ ? await captureUnderscoreErrorException(context)
+ : undefined;
+ const pathname = context.asPath?.split(/[?#]/)[0];
+
+ return {
+ ...errorInitialProps,
+ sentryEventId,
+ showReturnHome: pathname !== "/",
+ };
+};
+
+export default ErrorPage;