Skip to content

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

refactor(web): thin leftover fat pages into feature Page components (#17721)

Nikita Kabardina95020056155
diff --git a/web/src/features/auth/HfSpacesPage.tsx b/web/src/features/auth/HfSpacesPage.tsx
new file mode 100644
index 0000000000..9a1913c61c
--- /dev/null
+++ b/web/src/features/auth/HfSpacesPage.tsx
@@ -0,0 +1,59 @@
+/**
+ * When running Langfuse in HuggingFace Spaces, the app needs to be opened in a new tab.
+ * Otherwise, the app will not be able to access the session cookie.
+ */
+
+import { Button } from "@/src/components/ui/button";
+import { LangfuseIcon } from "@/src/components/design-system/LangfuseIcon/LangfuseIcon";
+import Head from "next/head";
+import Link from "next/link";
+import { PlusIcon } from "lucide-react";
+import { CodeView } from "@/src/components/ui/CodeJsonViewer";
+
+export type PageProps = {
+ deploymentDomain: string;
+};
+
+export default function HfSpacesPage({ deploymentDomain }: PageProps) {
+ return (
+ <>
+ <Head>
+ <title>Langfuse on Hugging Face</title>
+ </Head>
+ <div className="flex flex-1 flex-col py-6 sm:min-h-full sm:justify-center sm:px-6 sm:py-12 lg:px-8">
+ <div className="sm:mx-auto sm:w-full sm:max-w-md">
+ <div className="flex items-center justify-center gap-2">
+ <LangfuseIcon />
+ <PlusIcon size={12} className="ml-1" />
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+ <img
+ src="/assets/huggingface-logo.svg"
+ alt="Hugging Face Logo"
+ width={36}
+ height={36}
+ />
+ </div>
+ <h2 className="text-primary mt-4 text-center text-2xl leading-9 font-bold tracking-tight">
+ Langfuse on Hugging Face
+ </h2>
+ </div>
+
+ <div className="bg-background mt-14 px-6 py-10 shadow-sm sm:mx-auto sm:w-full sm:max-w-[480px] sm:rounded-lg sm:px-10">
+ <div className="space-y-8">
+ <CodeView content={deploymentDomain} title="HF Space Host" />
+
+ <Button className="w-full" asChild>
+ <Link
+ href={deploymentDomain}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ Open in new tab
+ </Link>
+ </Button>
+ </div>
+ </div>
+ </div>
+ </>
+ );
+}
diff --git a/web/src/features/auth/SsoInitiatePage.tsx b/web/src/features/auth/SsoInitiatePage.tsx
new file mode 100644
index 0000000000..0162becfef
--- /dev/null
+++ b/web/src/features/auth/SsoInitiatePage.tsx
@@ -0,0 +1,63 @@
+import { signIn } from "next-auth/react";
+import Head from "next/head";
+import { useEffect, useState } from "react";
+import { useRouter } from "next/router";
+import { ErrorPageWithSentry } from "@/src/components/error-page";
+import { Spinner } from "@/src/components/layouts/spinner";
+
+export default function SsoInitiatePage() {
+ const router = useRouter();
+ const [error, setError] = useState<string | null>(null);
+
+ useEffect(() => {
+ // Wait for router to be ready
+ if (!router.isReady) {
+ return;
+ }
+
+ const provider = router.query.provider as string | undefined;
+
+ // If provider is missing or empty, show error
+ if (!provider || provider === "") {
+ setError("No SSO provider specified. Please contact your administrator.");
+ return;
+ }
+
+ // Automatically trigger sign-in with the provider
+ signIn(provider)
+ .then(() => {
+ // signIn will redirect automatically on success
+ // No need to do anything here
+ })
+ .catch((error) => {
+ console.error("SSO initiation error:", error);
+ setError(
+ error instanceof Error
+ ? error.message
+ : "Failed to initiate SSO sign-in. Please try again or contact support.",
+ );
+ });
+ }, [router.isReady, router.query.provider]);
+
+ // Show error page if sign-in failed
+ if (error) {
+ return (
+ <>
+ <Head>
+ <title>Sign-in Error | Langfuse</title>
+ </Head>
+ <ErrorPageWithSentry title="SSO Sign-in Failed" message={error} />
+ </>
+ );
+ }
+
+ // Show loading spinner while processing
+ return (
+ <>
+ <Head>
+ <title>Signing in | Langfuse</title>
+ </Head>
+ <Spinner message="Redirecting to your identity provider..." />
+ </>
+ );
+}
diff --git a/web/src/features/auth/server/getHfSpacesPageServerSideProps.ts b/web/src/features/auth/server/getHfSpacesPageServerSideProps.ts
new file mode 100644
index 0000000000..5f8b07aed3
--- /dev/null
+++ b/web/src/features/auth/server/getHfSpacesPageServerSideProps.ts
@@ -0,0 +1,13 @@
+import { type GetServerSideProps } from "next";
+import { env } from "@/src/env.mjs";
+import { type PageProps } from "@/src/features/auth/HfSpacesPage";
+
+export const getServerSideProps: GetServerSideProps<PageProps> = async () => {
+ // remove /api/auth from the URL as it needs to be added for custom base url
+ const deploymentDomain = env.NEXTAUTH_URL?.replace("/api/auth", "");
+ return {
+ props: {
+ deploymentDomain,
+ },
+ };
+};
diff --git a/web/src/features/dashboard/DashboardsPage.tsx b/web/src/features/dashboard/DashboardsPage.tsx
new file mode 100644
index 0000000000..f6938f5c3e
--- /dev/null
+++ b/web/src/features/dashboard/DashboardsPage.tsx
@@ -0,0 +1,48 @@
+import { useRouter } from "next/router";
+import Page from "@/src/components/layouts/page";
+import { ConnectedDashboardTable } from "@/src/features/dashboard/components/DashboardTable/ConnectedDashboardTable";
+import { ActionButton } from "@/src/components/ActionButton";
+import { PlusIcon } from "lucide-react";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import {
+ getDashboardTabs,
+ DASHBOARD_TABS,
+} from "@/src/features/navigation/utils/dashboard-tabs";
+
+export default function DashboardsPage() {
+ const router = useRouter();
+ const { projectId } = router.query as { projectId: string };
+ const hasCUDAccess = useHasProjectAccess({
+ projectId,
+ scope: "dashboards:CUD",
+ });
+
+ return (
+ <Page
+ headerProps={{
+ title: "Dashboards",
+ help: {
+ description: "Manage and create dashboards for your project.",
+ href: "https://langfuse.com/docs/metrics/features/custom-dashboards",
+ },
+ tabsProps: {
+ tabs: getDashboardTabs(projectId),
+ activeTab: DASHBOARD_TABS.DASHBOARDS,
+ },
+ actionButtonsRight: (
+ <ActionButton
+ icon={<PlusIcon className="h-4 w-4" aria-hidden="true" />}
+ hasAccess={hasCUDAccess}
+ href={`/project/${projectId}/dashboards/new`}
+ trackingEventName="dashboard:new_dashboard_form_open"
+ variant="default"
+ >
+ New dashboard
+ </ActionButton>
+ ),
+ }}
+ >
+ <ConnectedDashboardTable />
+ </Page>
+ );
+}
diff --git a/web/src/features/datasets/DatasetItemRunsPage.tsx b/web/src/features/datasets/DatasetItemRunsPage.tsx
new file mode 100644
index 0000000000..e88604a00f
--- /dev/null
+++ b/web/src/features/datasets/DatasetItemRunsPage.tsx
@@ -0,0 +1,67 @@
+import { useRouter } from "next/router";
+import { useEffect } from "react";
+import { DatasetRunItemsByItemTable } from "@/src/features/datasets/components/DatasetRunItemsByItemTable";
+import { DATASET_ITEM_TABS } from "@/src/features/navigation/utils/dataset-item-tabs";
+import { DatasetItemDetailPage } from "@/src/features/datasets/components/DatasetItemDetailPage";
+import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";
+import {
+ RouteParamsPendingFallback,
+ useReadyRouteParams,
+} from "@/src/hooks/useReadyRouteParams";
+
+export default function DatasetItemRunsPage() {
+ const route = useReadyRouteParams(["projectId", "datasetId", "itemId"]);
+ if (!route.ready) return <RouteParamsPendingFallback />;
+ return (
+ <DatasetItemRuns
+ projectId={route.params.projectId}
+ datasetId={route.params.datasetId}
+ itemId={route.params.itemId}
+ />
+ );
+}
+
+function DatasetItemRuns({
+ projectId,
+ datasetId,
+ itemId,
+}: {
+ projectId: string;
+ datasetId: string;
+ itemId: string;
+}) {
+ const router = useRouter();
+
+ // The per-item runs view reads legacy dataset_run_items and has no
+ // events-backed equivalent, so fast-preview (v4) users are redirected back to
+ // the item detail (the Experiments tab is also hidden for them).
+ const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();
+ useEffect(() => {
+ if (isInitializing || !isExperimentsBetaActive || !projectId) return;
+ router.replace(
+ `/project/${projectId}/datasets/${datasetId}/items/${encodeURIComponent(itemId)}`,
+ );
+ }, [
+ isExperimentsBetaActive,
+ isInitializing,
+ projectId,
+ datasetId,
+ itemId,
+ router,
+ ]);
+
+ if (isExperimentsBetaActive) return <RouteParamsPendingFallback />;
+
+ return (
+ <DatasetItemDetailPage
+ withPadding={false}
+ activeTab={DATASET_ITEM_TABS.RUNS}
+ >
+ <DatasetRunItemsByItemTable
+ projectId={projectId}
+ datasetItemId={itemId}
+ datasetId={datasetId}
+ />
+ </DatasetItemDetailPage>
+ );
+}
diff --git a/web/src/features/datasets/DatasetsPage.tsx b/web/src/features/datasets/DatasetsPage.tsx
new file mode 100644
index 0000000000..18ec7ddfb9
--- /dev/null
+++ b/web/src/features/datasets/DatasetsPage.tsx
@@ -0,0 +1,87 @@
+import { useRouter } from "next/router";
+import { DatasetsTable } from "@/src/features/datasets/components/DatasetsTable";
+import Page from "@/src/components/layouts/page";
+import { ButtonWithIcon } from "@/src/components/ButtonWithIcon";
+import { DialogTrigger } from "@/src/components/ui/dialog";
+import { CreateDatasetDialogController } from "@/src/features/datasets/components/CreateDatasetDialogController";
+import { api } from "@/src/utils/api";
+import { DatasetsOnboarding } from "@/src/components/onboarding/DatasetsOnboarding";
+import { LockIcon, PlusIcon } from "lucide-react";
+import { useQueryParam, StringParam } from "use-query-params";
+
+export default function DatasetsPage() {
+ const router = useRouter();
+ const projectId = router.query.projectId as string;
+ const [currentFolderPath] = useQueryParam("folder", StringParam);
+
+ // Check if the project has any datasets
+ const { data: hasAnyDataset, isLoading } = api.datasets.hasAny.useQuery(
+ { projectId },
+ {
+ enabled: !!projectId,
+ trpc: {
+ context: {
+ skipBatch: true,
+ },
+ },
+ },
+ );
+
+ const showOnboarding = !isLoading && !hasAnyDataset;
+
+ if (showOnboarding) {
+ return (
+ <Page
+ headerProps={{
+ title: "Datasets",
+ help: {
+ description:
+ "Datasets in Langfuse are a collection of inputs (and expected outputs) of an LLM application. They are used to benchmark new releases before deployment to production. See docs to learn more.",
+ href: "https://langfuse.com/docs/evaluation/dataset-runs/datasets",
+ },
+ }}
+ scrollable
+ >
+ <DatasetsOnboarding projectId={projectId} />
+ </Page>
+ );
+ }
+
+ return (
+ <Page
+ headerProps={{
+ title: "Datasets",
+ help: {
+ description:
+ "Datasets in Langfuse are a collection of inputs (and expected outputs) of an LLM application. They are used to benchmark new releases before deployment to production. See docs to learn more.",
+ href: "https://langfuse.com/docs/evaluation/dataset-runs/datasets",
+ },
+ actionButtonsRight: (
+ <CreateDatasetDialogController
+ projectId={projectId}
+ target={
+ currentFolderPath
+ ? { type: "folder", prefix: currentFolderPath }
+ : { type: "root" }
+ }
+ >
+ {({ disabled, openDialog }) => (
+ <DialogTrigger asChild>
+ <ButtonWithIcon
+ size="default"
+ disabled={disabled !== undefined}
+ onClick={openDialog}
+ variant="default"
+ icon={disabled === undefined ? PlusIcon : LockIcon}
+ text="New dataset"
+ />
+ </DialogTrigger>
+ )}
+ </CreateDatasetDialogController>
+ ),
+ }}
+ >
+ <DatasetsTable projectId={projectId} />
+ </Page>
+ );
+}
diff --git a/web/src/features/evals/EvalConfigsIndexPage.tsx b/web/src/features/evals/EvalConfigsIndexPage.tsx
new file mode 100644
index 0000000000..370f4af299
--- /dev/null
+++ b/web/src/features/evals/EvalConfigsIndexPage.tsx
@@ -0,0 +1,28 @@
+import { type GetServerSideProps } from "next";
+import { useRouter } from "next/router";
+
+// This url is deprecated, we keep this redirect page for backward compatibility
+export const getServerSideProps: GetServerSideProps = async (context) => {
+ if (!context.params) {
+ return {
+ notFound: true,
+ };
+ }
+ const projectId = context.params.projectId as string;
+
+ return {
+ redirect: {
+ destination: `/project/${projectId}/evals/legacy`,
+ permanent: false,
+ },
+ };
+};
+
+export default function EvalConfigsIndexPage() {
+ const router = useRouter();
+ if (router.isFallback) {
+ return <div className="p-3">Loading...</div>;
+ }
+
+ return <div>Redirecting...</div>;
+}
diff --git a/web/src/features/evals/EvalConfigsNewPage.tsx b/web/src/features/evals/EvalConfigsNewPage.tsx
new file mode 100644
index 0000000000..788321f200
--- /dev/null
+++ b/web/src/features/evals/EvalConfigsNewPage.tsx
@@ -0,0 +1,28 @@
+import { type GetServerSideProps } from "next";
+import { useRouter } from "next/router";
+
+// This url is deprecated, we keep this redirect page for backward compatibility
+export const getServerSideProps: GetServerSideProps = async (context) => {
+ if (!context.params) {
+ return {
+ notFound: true,
+ };
+ }
+ const projectId = context.params.projectId as string;
+
+ return {
+ redirect: {
+ destination: `/project/${projectId}/evals/legacy/new`,
+ permanent: false,
+ },
+ };
+};
+
+export default function EvalConfigsNewPage() {
+ const router = useRouter();
+ if (router.isFallback) {
+ return <div className="p-3">Loading...</div>;
+ }
+
+ return <div>Redirecting...</div>;
+}
diff --git a/web/src/features/events/EventsPage.tsx b/web/src/features/events/EventsPage.tsx
new file mode 100644
index 0000000000..8c7877c510
--- /dev/null
+++ b/web/src/features/events/EventsPage.tsx
@@ -0,0 +1,65 @@
+import React from "react";
+import { useRouter } from "next/router";
+import ObservationsEventsTable from "@/src/features/events/components/EventsTable";
+import Page from "@/src/components/layouts/page";
+import { api } from "@/src/utils/api";
+import { TracesOnboarding } from "@/src/components/onboarding/TracesOnboarding";
+import {
+ getTracingTabs,
+ TRACING_TABS,
+} from "@/src/features/navigation/utils/tracing-tabs";
+import { useQueryProject } from "@/src/features/projects/hooks";
+
+export default function EventsPage() {
+ const router = useRouter();
+ const projectId = router.query.projectId as string;
+ const { project } = useQueryProject();
+
+ // Check if the user has tracing configured
+ // Skip polling entirely if the project flag is already set in the session
+ const { data: hasTracingConfigured, isLoading } =
+ api.traces.hasTracingConfigured.useQuery(
+ { projectId },
+ {
+ enabled: !!projectId,
+ trpc: {
+ context: {
+ skipBatch: true,
+ },
+ },
+ refetchInterval: project?.hasTraces ? false : 10_000,
+ initialData: project?.hasTraces ? true : undefined,
+ staleTime: project?.hasTraces ? Infinity : 0,
+ },
+ );
+
+ const showOnboarding = !isLoading && !hasTracingConfigured;
+
+ return (
+ <Page
+ headerProps={{
+ title: "Tracing - Events Table (New)",
+ help: {
+ description:
+ "An observation captures a single function call in an application. This view uses the new ClickHouse events table.",
+ href: "https://langfuse.com/docs/observability/data-model",
+ },
+ tabsProps: {
+ tabs: getTracingTabs(projectId),
+ activeTab: TRACING_TABS.OBSERVATIONS,
+ },
+ }}
+ scrollable={showOnboarding}
+ >
+ {/* Show onboarding screen if user has no traces */}
+ {showOnboarding ? (
+ <TracesOnboarding projectId={projectId} />
+ ) : (
+ <ObservationsEventsTable
+ projectId={projectId}
+ showControlsInPageHeader
+ />
+ )}
+ </Page>
+ );
+}
diff --git a/web/src/features/experiments/ExperimentsPage.tsx b/web/src/features/experiments/ExperimentsPage.tsx
new file mode 100644
index 0000000000..6137a62019
--- /dev/null
+++ b/web/src/features/experiments/ExperimentsPage.tsx
@@ -0,0 +1,99 @@
+import Page from "@/src/components/layouts/page";
+import { Button } from "@/src/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogTrigger,
+} from "@/src/components/ui/dialog";
+import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";
+import { ExperimentsTable } from "@/src/features/experiments/components/table";
+import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";
+import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import { V4MigrationDelayBadge } from "@/src/features/v4-migration/V4MigrationDelayBadge";
+import { api } from "@/src/utils/api";
+import { FlaskConical } from "lucide-react";
+import { useEffect, useState } from "react";
+import { useRouter } from "next/router";
+import { Spinner } from "@/src/components/design-system/Spinner/Spinner";
+
+export default function ExperimentsPage() {
+ const router = useRouter();
+ const projectId = router.query.projectId as string;
+ const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =
+ useState(false);
+ const capture = usePostHogClientCapture();
+ const utils = api.useUtils();
+
+ const hasExperimentWriteAccess = useHasProjectAccess({
+ projectId,
+ scope: "promptExperiments:CUD",
+ });
+
+ const { canAccessExperiments, isInitializing } = useExperimentAccess();
+
+ const handleExperimentSuccess = async () => {
+ setIsCreateExperimentDialogOpen(false);
+ await Promise.all([
+ utils.experiments.all.invalidate(),
+ utils.experiments.countAll.invalidate(),
+ // The empty-window fallback is its own query, and a new run belongs in
+ // it: without this it keeps serving its cached list.
+ utils.experiments.mostRecent.invalidate(),
+ ]);
+ };
+
+ useEffect(() => {
+ if (isInitializing || canAccessExperiments || !projectId) return;
+
+ router.replace(`/project/${projectId}/datasets`);
+ }, [canAccessExperiments, isInitializing, projectId, router]);
+
+ if (!canAccessExperiments) {
+ return (
+ <Page headerProps={{ title: "Experiments" }}>
+ <div className="flex h-full items-center justify-center">
+ <Spinner size="xl" variant="muted" />
+ </div>
+ </Page>
+ );
+ }
+
+ return (
+ <Page
+ headerProps={{
+ title: "Experiments",
+ titleBadges: <V4MigrationDelayBadge page="experiments" />,
+ actionButtonsRight: (
+ <div className="flex items-center gap-2">
+ <Dialog
+ open={isCreateExperimentDialogOpen}
+ onOpenChange={setIsCreateExperimentDialogOpen}
+ >
+ <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>
+ <Button
+ disabled={!hasExperimentWriteAccess}
+ onClick={() => capture("dataset_run:new_form_open")}
+ >
+ <FlaskConical className="h-4 w-4" />
+ <span className="ml-2 hidden md:block">Run experiment</span>
+ </Button>
+ </DialogTrigger>
+ <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">
+ <CreateExperimentsForm
+ key="create-experiment-form-project-experiments"
+ projectId={projectId}
+ setFormOpen={setIsCreateExperimentDialogOpen}
+ handleExperimentSuccess={handleExperimentSuccess}
+ showSDKRunInfoPage
+ />
+ </DialogContent>
+ </Dialog>
+ </div>
+ ),
+ }}
+ >
+ <ExperimentsTable projectId={projectId} showControlsInPageHeader />
+ </Page>
+ );
+}
diff --git a/web/src/features/traces/TraceRedirectPage.tsx b/web/src/features/traces/TraceRedirectPage.tsx
new file mode 100644
index 0000000000..31c130e853
--- /dev/null
+++ b/web/src/features/traces/TraceRedirectPage.tsx
@@ -0,0 +1,45 @@
+// Redirect helper for /trace/[traceId] URLs
+// Looks up the projectId for a trace and redirects to /project/[projectId]/traces/[traceId]
+// which displays the current trace view
+
+import { ErrorPage } from "@/src/components/error-page";
+import { useRouter } from "next/router";
+
+const TraceRedirectPage = ({
+ notFound,
+ duplicatesFound,
+}: {
+ notFound?: boolean;
+ duplicatesFound?: boolean;
+}) => {
+ const router = useRouter();
+ if (router.isFallback) {
+ return <div className="p-3">Loading...</div>;
+ }
+
+ if (notFound) {
+ return (
+ <ErrorPage
+ title="Trace not found"
+ message="The trace is either still being processed or has been deleted."
+ additionalButton={{
+ label: "Retry",
+ onClick: () => window.location.reload(),
+ }}
+ />
+ );
+ }
+
+ if (duplicatesFound) {
+ return (
+ <ErrorPage
+ title="Trace not found"
+ message="Please upgrade the SDK as the URL schema has changed."
+ />
+ );
+ }
+
+ return <div>Redirecting...</div>;
+};
+
+export default TraceRedirectPage;
diff --git a/web/src/features/traces/server/getTraceRedirectPageServerSideProps.ts b/web/src/features/traces/server/getTraceRedirectPageServerSideProps.ts
new file mode 100644
index 0000000000..9cce3e60da
--- /dev/null
+++ b/web/src/features/traces/server/getTraceRedirectPageServerSideProps.ts
@@ -0,0 +1,39 @@
+import { getTracesByIdsForAnyProject } from "@langfuse/shared/src/server";
+import { type GetServerSideProps } from "next";
+
+export const getServerSideProps: GetServerSideProps = async (context) => {
+ if (!context.params) {
+ return {
+ props: {
+ notFound: true,
+ },
+ };
+ }
+
+ const traceId = context.params.traceId as string;
+
+ const traces = await getTracesByIdsForAnyProject([traceId]);
+
+ if (!traces || traces.length === 0) {
+ return {
+ props: {
+ notFound: true,
+ },
+ };
+ }
+
+ if (traces.length > 1) {
+ return {
+ props: {
+ duplicatesFound: true,
+ },
+ };
+ }
+
+ return {
+ redirect: {
+ destination: `/project/${traces[0].projectId}/traces/${traceId}`,
+ permanent: false,
+ },
+ };
+};
diff --git a/web/src/features/widgets/WidgetsPage.tsx b/web/src/features/widgets/WidgetsPage.tsx
new file mode 100644
index 0000000000..5641ea18b4
--- /dev/null
+++ b/web/src/features/widgets/WidgetsPage.tsx
@@ -0,0 +1,48 @@
+import { useRouter } from "next/router";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import Page from "@/src/components/layouts/page";
+import { ActionButton } from "@/src/components/ActionButton";
+import { PlusIcon } from "lucide-react";
+import { ConnectedDashboardWidgetTable } from "@/src/features/widgets";
+import {
+ getDashboardTabs,
+ DASHBOARD_TABS,
+} from "@/src/features/navigation/utils/dashboard-tabs";
+
+export default function WidgetsPage() {
+ const router = useRouter();
+ const { projectId } = router.query as { projectId: string };
+ const hasCUDAccess = useHasProjectAccess({
+ projectId,
+ scope: "prompts:CUD",
+ });
+
+ return (
+ <Page
+ headerProps={{
+ title: "Widgets",
+ help: {
+ description: "Manage and create widgets for your dashboard.",
+ href: "https://langfuse.com/docs/metrics/features/custom-dashboards",
+ },
+ tabsProps: {
+ tabs: getDashboardTabs(projectId),
+ activeTab: DASHBOARD_TABS.WIDGETS,
+ },
+ actionButtonsRight: (
+ <ActionButton
+ icon={<PlusIcon className="h-4 w-4" aria-hidden="true" />}
+ hasAccess={hasCUDAccess}
+ href={`/project/${projectId}/widgets/new`}
+ trackingEventName="dashboard:new_widget_form_open"
+ variant="default"
+ >
+ New widget
+ </ActionButton>
+ ),
+ }}
+ >
+ <ConnectedDashboardWidgetTable />
+ </Page>
+ );
+}
diff --git a/web/src/pages/auth/hf-spaces.tsx b/web/src/pages/auth/hf-spaces.tsx
index 93b9873c39..c525627708 100644
--- a/web/src/pages/auth/hf-spaces.tsx
+++ b/web/src/pages/auth/hf-spaces.tsx
@@ -1,71 +1,2 @@
-/**
- * When running Langfuse in HuggingFace Spaces, the app needs to be opened in a new tab.
- * Otherwise, the app will not be able to access the session cookie.
- */
-
-import { Button } from "@/src/components/ui/button";
-import { LangfuseIcon } from "@/src/components/design-system/LangfuseIcon/LangfuseIcon";
-import Head from "next/head";
-import Link from "next/link";
-import { type GetServerSideProps } from "next";
-import { env } from "@/src/env.mjs";
-import { PlusIcon } from "lucide-react";
-import { CodeView } from "@/src/components/ui/CodeJsonViewer";
-
-type PageProps = {
- deploymentDomain: string;
-};
-
-export const getServerSideProps: GetServerSideProps<PageProps> = async () => {
- // remove /api/auth from the URL as it needs to be added for custom base url
- const deploymentDomain = env.NEXTAUTH_URL?.replace("/api/auth", "");
- return {
- props: {
- deploymentDomain,
- },
- };
-};
-
-export default function HfSpaces({ deploymentDomain }: PageProps) {
- return (
- <>
- <Head>
- <title>Langfuse on Hugging Face</title>
- </Head>
- <div className="flex flex-1 flex-col py-6 sm:min-h-full sm:justify-center sm:px-6 sm:py-12 lg:px-8">
- <div className="sm:mx-auto sm:w-full sm:max-w-md">
- <div className="flex items-center justify-center gap-2">
- <LangfuseIcon />
- <PlusIcon size={12} className="ml-1" />
- {/* eslint-disable-next-line @next/next/no-img-element */}
- <img
- src="/assets/huggingface-logo.svg"
- alt="Hugging Face Logo"
- width={36}
- height={36}
- />
- </div>
- <h2 className="text-primary mt-4 text-center text-2xl leading-9 font-bold tracking-tight">
- Langfuse on Hugging Face
- </h2>
- </div>
-
- <div className="bg-background mt-14 px-6 py-10 shadow-sm sm:mx-auto sm:w-full sm:max-w-[480px] sm:rounded-lg sm:px-10">
- <div className="space-y-8">
- <CodeView content={deploymentDomain} title="HF Space Host" />
-
- <Button className="w-full" asChild>
- <Link
- href={deploymentDomain}
- target="_blank"
- rel="noopener noreferrer"
- >
- Open in new tab
- </Link>
- </Button>
- </div>
- </div>
- </div>
- </>
- );
-}
+export { default } from "@/src/features/auth/HfSpacesPage";
+export { getServerSideProps } from "@/src/features/auth/server/getHfSpacesPageServerSideProps";
diff --git a/web/src/pages/auth/sso-initiate.tsx b/web/src/pages/auth/sso-initiate.tsx
index 9c7e5fa6c6..560c85fa9a 100644
--- a/web/src/pages/auth/sso-initiate.tsx
+++ b/web/src/pages/auth/sso-initiate.tsx
@@ -1,63 +1 @@
-import { signIn } from "next-auth/react";
-import Head from "next/head";
-import { useEffect, useState } from "react";
-import { useRouter } from "next/router";
-import { ErrorPageWithSentry } from "@/src/components/error-page";
-import { Spinner } from "@/src/components/layouts/spinner";
-
-export default function SSOInitiate() {
- const router = useRouter();
- const [error, setError] = useState<string | null>(null);
-
- useEffect(() => {
- // Wait for router to be ready
- if (!router.isReady) {
- return;
- }
-
- const provider = router.query.provider as string | undefined;
-
- // If provider is missing or empty, show error
- if (!provider || provider === "") {
- setError("No SSO provider specified. Please contact your administrator.");
- return;
- }
-
- // Automatically trigger sign-in with the provider
- signIn(provider)
- .then(() => {
- // signIn will redirect automatically on success
- // No need to do anything here
- })
- .catch((error) => {
- console.error("SSO initiation error:", error);
- setError(
- error instanceof Error
- ? error.message
- : "Failed to initiate SSO sign-in. Please try again or contact support.",
- );
- });
- }, [router.isReady, router.query.provider]);
-
- // Show error page if sign-in failed
- if (error) {
- return (
- <>
- <Head>
- <title>Sign-in Error | Langfuse</title>
- </Head>
- <ErrorPageWithSentry title="SSO Sign-in Failed" message={error} />
- </>
- );
- }
-
- // Show loading spinner while processing
- return (
- <>
- <Head>
- <title>Signing in | Langfuse</title>
- </Head>
- <Spinner message="Redirecting to your identity provider..." />
- </>
- );
-}
+export { default } from "@/src/features/auth/SsoInitiatePage";
diff --git a/web/src/pages/project/[projectId]/dashboards/index.tsx b/web/src/pages/project/[projectId]/dashboards/index.tsx
index 039b89c393..4ed9dd1612 100644
--- a/web/src/pages/project/[projectId]/dashboards/index.tsx
+++ b/web/src/pages/project/[projectId]/dashboards/index.tsx
@@ -1,48 +1 @@
-import { useRouter } from "next/router";
-import Page from "@/src/components/layouts/page";
-import { ConnectedDashboardTable } from "@/src/features/dashboard/components/DashboardTable/ConnectedDashboardTable";
-import { ActionButton } from "@/src/components/ActionButton";
-import { PlusIcon } from "lucide-react";
-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import {
- getDashboardTabs,
- DASHBOARD_TABS,
-} from "@/src/features/navigation/utils/dashboard-tabs";
-
-export default function Dashboards() {
- const router = useRouter();
- const { projectId } = router.query as { projectId: string };
- const hasCUDAccess = useHasProjectAccess({
- projectId,
- scope: "dashboards:CUD",
- });
-
- return (
- <Page
- headerProps={{
- title: "Dashboards",
- help: {
- description: "Manage and create dashboards for your project.",
- href: "https://langfuse.com/docs/metrics/features/custom-dashboards",
- },
- tabsProps: {
- tabs: getDashboardTabs(projectId),
- activeTab: DASHBOARD_TABS.DASHBOARDS,
- },
- actionButtonsRight: (
- <ActionButton
- icon={<PlusIcon className="h-4 w-4" aria-hidden="true" />}
- hasAccess={hasCUDAccess}
- href={`/project/${projectId}/dashboards/new`}
- trackingEventName="dashboard:new_dashboard_form_open"
- variant="default"
- >
- New dashboard
- </ActionButton>
- ),
- }}
- >
- <ConnectedDashboardTable />
- </Page>
- );
-}
+export { default } from "@/src/features/dashboard/DashboardsPage";
diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/items/[itemId]/runs.tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/items/[itemId]/runs.tsx
index 909aefbab2..a3a52ad85b 100644
--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/items/[itemId]/runs.tsx
+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/items/[itemId]/runs.tsx
@@ -1,67 +1 @@
-import { useRouter } from "next/router";
-import { useEffect } from "react";
-import { DatasetRunItemsByItemTable } from "@/src/features/datasets/components/DatasetRunItemsByItemTable";
-import { DATASET_ITEM_TABS } from "@/src/features/navigation/utils/dataset-item-tabs";
-import { DatasetItemDetailPage } from "@/src/features/datasets/components/DatasetItemDetailPage";
-import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";
-import {
- RouteParamsPendingFallback,
- useReadyRouteParams,
-} from "@/src/hooks/useReadyRouteParams";
-
-export default function DatasetItemRunsPage() {
- const route = useReadyRouteParams(["projectId", "datasetId", "itemId"]);
- if (!route.ready) return <RouteParamsPendingFallback />;
- return (
- <DatasetItemRuns
- projectId={route.params.projectId}
- datasetId={route.params.datasetId}
- itemId={route.params.itemId}
- />
- );
-}
-
-function DatasetItemRuns({
- projectId,
- datasetId,
- itemId,
-}: {
- projectId: string;
- datasetId: string;
- itemId: string;
-}) {
- const router = useRouter();
-
- // The per-item runs view reads legacy dataset_run_items and has no
- // events-backed equivalent, so fast-preview (v4) users are redirected back to
- // the item detail (the Experiments tab is also hidden for them).
- const { isExperimentsBetaActive, isInitializing } = useExperimentAccess();
- useEffect(() => {
- if (isInitializing || !isExperimentsBetaActive || !projectId) return;
- router.replace(
- `/project/${projectId}/datasets/${datasetId}/items/${encodeURIComponent(itemId)}`,
- );
- }, [
- isExperimentsBetaActive,
- isInitializing,
- projectId,
- datasetId,
- itemId,
- router,
- ]);
-
- if (isExperimentsBetaActive) return null;
-
- return (
- <DatasetItemDetailPage
- withPadding={false}
- activeTab={DATASET_ITEM_TABS.RUNS}
- >
- <DatasetRunItemsByItemTable
- projectId={projectId}
- datasetItemId={itemId}
- datasetId={datasetId}
- />
- </DatasetItemDetailPage>
- );
-}
+export { default } from "@/src/features/datasets/DatasetItemRunsPage";
diff --git a/web/src/pages/project/[projectId]/datasets/index.tsx b/web/src/pages/project/[projectId]/datasets/index.tsx
index 688e3151f7..15ca3bcb68 100644
--- a/web/src/pages/project/[projectId]/datasets/index.tsx
+++ b/web/src/pages/project/[projectId]/datasets/index.tsx
@@ -1,87 +1 @@
-import { useRouter } from "next/router";
-import { DatasetsTable } from "@/src/features/datasets/components/DatasetsTable";
-import Page from "@/src/components/layouts/page";
-import { ButtonWithIcon } from "@/src/components/ButtonWithIcon";
-import { DialogTrigger } from "@/src/components/ui/dialog";
-import { CreateDatasetDialogController } from "@/src/features/datasets/components/CreateDatasetDialogController";
-import { api } from "@/src/utils/api";
-import { DatasetsOnboarding } from "@/src/components/onboarding/DatasetsOnboarding";
-import { LockIcon, PlusIcon } from "lucide-react";
-import { useQueryParam, StringParam } from "use-query-params";
-
-export default function Datasets() {
- const router = useRouter();
- const projectId = router.query.projectId as string;
- const [currentFolderPath] = useQueryParam("folder", StringParam);
-
- // Check if the project has any datasets
- const { data: hasAnyDataset, isLoading } = api.datasets.hasAny.useQuery(
- { projectId },
- {
- enabled: !!projectId,
- trpc: {
- context: {
- skipBatch: true,
- },
- },
- },
- );
-
- const showOnboarding = !isLoading && !hasAnyDataset;
-
- if (showOnboarding) {
- return (
- <Page
- headerProps={{
- title: "Datasets",
- help: {
- description:
- "Datasets in Langfuse are a collection of inputs (and expected outputs) of an LLM application. They are used to benchmark new releases before deployment to production. See docs to learn more.",
- href: "https://langfuse.com/docs/evaluation/dataset-runs/datasets",
- },
- }}
- scrollable
- >
- <DatasetsOnboarding projectId={projectId} />
- </Page>
- );
- }
-
- return (
- <Page
- headerProps={{
- title: "Datasets",
- help: {
- description:
- "Datasets in Langfuse are a collection of inputs (and expected outputs) of an LLM application. They are used to benchmark new releases before deployment to production. See docs to learn more.",
- href: "https://langfuse.com/docs/evaluation/dataset-runs/datasets",
- },
- actionButtonsRight: (
- <CreateDatasetDialogController
- projectId={projectId}
- target={
- currentFolderPath
- ? { type: "folder", prefix: currentFolderPath }
- : { type: "root" }
- }
- >
- {({ disabled, openDialog }) => (
- <DialogTrigger asChild>
- <ButtonWithIcon
- size="default"
- disabled={disabled !== undefined}
- onClick={openDialog}
- variant="default"
- icon={disabled === undefined ? PlusIcon : LockIcon}
- text="New dataset"
- />
- </DialogTrigger>
- )}
- </CreateDatasetDialogController>
- ),
- }}
- >
- <DatasetsTable projectId={projectId} />
- </Page>
- );
-}
+export { default } from "@/src/features/datasets/DatasetsPage";
diff --git a/web/src/pages/project/[projectId]/evals/configs/index.tsx b/web/src/pages/project/[projectId]/evals/configs/index.tsx
index 3e65dd2664..a3e2e6344f 100644
--- a/web/src/pages/project/[projectId]/evals/configs/index.tsx
+++ b/web/src/pages/project/[projectId]/evals/configs/index.tsx
@@ -1,28 +1,4 @@
-import { type GetServerSideProps } from "next";
-import { useRouter } from "next/router";
-
-// This url is deprecated, we keep this redirect page for backward compatibility
-export const getServerSideProps: GetServerSideProps = async (context) => {
- if (!context.params) {
- return {
- notFound: true,
- };
- }
- const projectId = context.params.projectId as string;
-
- return {
- redirect: {
- destination: `/project/${projectId}/evals/legacy`,
- permanent: false,
- },
- };
-};
-
-export default function RedirectPage() {
- const router = useRouter();
- if (router.isFallback) {
- return <div className="p-3">Loading...</div>;
- }
-
- return <div>Redirecting...</div>;
-}
+export {
+ default,
+ getServerSideProps,
+} from "@/src/features/evals/EvalConfigsIndexPage";
diff --git a/web/src/pages/project/[projectId]/evals/configs/new.tsx b/web/src/pages/project/[projectId]/evals/configs/new.tsx
index 5316f0a88c..4a3d881a9d 100644
--- a/web/src/pages/project/[projectId]/evals/configs/new.tsx
+++ b/web/src/pages/project/[projectId]/evals/configs/new.tsx
@@ -1,28 +1,4 @@
-import { type GetServerSideProps } from "next";
-import { useRouter } from "next/router";
-
-// This url is deprecated, we keep this redirect page for backward compatibility
-export const getServerSideProps: GetServerSideProps = async (context) => {
- if (!context.params) {
- return {
- notFound: true,
- };
- }
- const projectId = context.params.projectId as string;
-
- return {
- redirect: {
- destination: `/project/${projectId}/evals/legacy/new`,
- permanent: false,
- },
- };
-};
-
-export default function RedirectPage() {
- const router = useRouter();
- if (router.isFallback) {
- return <div className="p-3">Loading...</div>;
- }
-
- return <div>Redirecting...</div>;
-}
+export {
+ default,
+ getServerSideProps,
+} from "@/src/features/evals/EvalConfigsNewPage";
diff --git a/web/src/pages/project/[projectId]/experiments/index.tsx b/web/src/pages/project/[projectId]/experiments/index.tsx
index 1ebea98507..040fb7288d 100644
--- a/web/src/pages/project/[projectId]/experiments/index.tsx
+++ b/web/src/pages/project/[projectId]/experiments/index.tsx
@@ -1,99 +1 @@
-import Page from "@/src/components/layouts/page";
-import { Button } from "@/src/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogTrigger,
-} from "@/src/components/ui/dialog";
-import { CreateExperimentsForm } from "@/src/features/experiments/components/CreateExperimentsForm";
-import { ExperimentsTable } from "@/src/features/experiments/components/table";
-import { useExperimentAccess } from "@/src/features/experiments/hooks/useExperimentAccess";
-import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import { V4MigrationDelayBadge } from "@/src/features/v4-migration/V4MigrationDelayBadge";
-import { api } from "@/src/utils/api";
-import { FlaskConical } from "lucide-react";
-import { useEffect, useState } from "react";
-import { useRouter } from "next/router";
-import { Spinner } from "@/src/components/design-system/Spinner/Spinner";
-
-export default function Experiments() {
- const router = useRouter();
- const projectId = router.query.projectId as string;
- const [isCreateExperimentDialogOpen, setIsCreateExperimentDialogOpen] =
- useState(false);
- const capture = usePostHogClientCapture();
- const utils = api.useUtils();
-
- const hasExperimentWriteAccess = useHasProjectAccess({
- projectId,
- scope: "promptExperiments:CUD",
- });
-
- const { canAccessExperiments, isInitializing } = useExperimentAccess();
-
- const handleExperimentSuccess = async () => {
- setIsCreateExperimentDialogOpen(false);
- await Promise.all([
- utils.experiments.all.invalidate(),
- utils.experiments.countAll.invalidate(),
- // The empty-window fallback is its own query, and a new run belongs in
- // it: without this it keeps serving its cached list.
- utils.experiments.mostRecent.invalidate(),
- ]);
- };
-
- useEffect(() => {
- if (isInitializing || canAccessExperiments || !projectId) return;
-
- router.replace(`/project/${projectId}/datasets`);
- }, [canAccessExperiments, isInitializing, projectId, router]);
-
- if (!canAccessExperiments) {
- return (
- <Page headerProps={{ title: "Experiments" }}>
- <div className="flex h-full items-center justify-center">
- <Spinner size="xl" variant="muted" />
- </div>
- </Page>
- );
- }
-
- return (
- <Page
- headerProps={{
- title: "Experiments",
- titleBadges: <V4MigrationDelayBadge page="experiments" />,
- actionButtonsRight: (
- <div className="flex items-center gap-2">
- <Dialog
- open={isCreateExperimentDialogOpen}
- onOpenChange={setIsCreateExperimentDialogOpen}
- >
- <DialogTrigger asChild disabled={!hasExperimentWriteAccess}>
- <Button
- disabled={!hasExperimentWriteAccess}
- onClick={() => capture("dataset_run:new_form_open")}
- >
- <FlaskConical className="h-4 w-4" />
- <span className="ml-2 hidden md:block">Run experiment</span>
- </Button>
- </DialogTrigger>
- <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">
- <CreateExperimentsForm
- key="create-experiment-form-project-experiments"
- projectId={projectId}
- setFormOpen={setIsCreateExperimentDialogOpen}
- handleExperimentSuccess={handleExperimentSuccess}
- showSDKRunInfoPage
- />
- </DialogContent>
- </Dialog>
- </div>
- ),
- }}
- >
- <ExperimentsTable projectId={projectId} showControlsInPageHeader />
- </Page>
- );
-}
+export { default } from "@/src/features/experiments/ExperimentsPage";
diff --git a/web/src/pages/project/[projectId]/observations/new.tsx b/web/src/pages/project/[projectId]/observations/new.tsx
index b573e6ef6d..6ea3b6ec35 100644
--- a/web/src/pages/project/[projectId]/observations/new.tsx
+++ b/web/src/pages/project/[projectId]/observations/new.tsx
@@ -1,65 +1 @@
-import React from "react";
-import { useRouter } from "next/router";
-import ObservationsEventsTable from "@/src/features/events/components/EventsTable";
-import Page from "@/src/components/layouts/page";
-import { api } from "@/src/utils/api";
-import { TracesOnboarding } from "@/src/components/onboarding/TracesOnboarding";
-import {
- getTracingTabs,
- TRACING_TABS,
-} from "@/src/features/navigation/utils/tracing-tabs";
-import { useQueryProject } from "@/src/features/projects/hooks";
-
-export default function Events() {
- const router = useRouter();
- const projectId = router.query.projectId as string;
- const { project } = useQueryProject();
-
- // Check if the user has tracing configured
- // Skip polling entirely if the project flag is already set in the session
- const { data: hasTracingConfigured, isLoading } =
- api.traces.hasTracingConfigured.useQuery(
- { projectId },
- {
- enabled: !!projectId,
- trpc: {
- context: {
- skipBatch: true,
- },
- },
- refetchInterval: project?.hasTraces ? false : 10_000,
- initialData: project?.hasTraces ? true : undefined,
- staleTime: project?.hasTraces ? Infinity : 0,
- },
- );
-
- const showOnboarding = !isLoading && !hasTracingConfigured;
-
- return (
- <Page
- headerProps={{
- title: "Tracing - Events Table (New)",
- help: {
- description:
- "An observation captures a single function call in an application. This view uses the new ClickHouse events table.",
- href: "https://langfuse.com/docs/observability/data-model",
- },
- tabsProps: {
- tabs: getTracingTabs(projectId),
- activeTab: TRACING_TABS.OBSERVATIONS,
- },
- }}
- scrollable={showOnboarding}
- >
- {/* Show onboarding screen if user has no traces */}
- {showOnboarding ? (
- <TracesOnboarding projectId={projectId} />
- ) : (
- <ObservationsEventsTable
- projectId={projectId}
- showControlsInPageHeader
- />
- )}
- </Page>
- );
-}
+export { default } from "@/src/features/events/EventsPage";
diff --git a/web/src/pages/project/[projectId]/widgets/index.tsx b/web/src/pages/project/[projectId]/widgets/index.tsx
index 51b3f1e791..94ea914805 100644
--- a/web/src/pages/project/[projectId]/widgets/index.tsx
+++ b/web/src/pages/project/[projectId]/widgets/index.tsx
@@ -1,48 +1 @@
-import { useRouter } from "next/router";
-import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
-import Page from "@/src/components/layouts/page";
-import { ActionButton } from "@/src/components/ActionButton";
-import { PlusIcon } from "lucide-react";
-import { ConnectedDashboardWidgetTable } from "@/src/features/widgets";
-import {
- getDashboardTabs,
- DASHBOARD_TABS,
-} from "@/src/features/navigation/utils/dashboard-tabs";
-
-export default function Widgets() {
- const router = useRouter();
- const { projectId } = router.query as { projectId: string };
- const hasCUDAccess = useHasProjectAccess({
- projectId,
- scope: "prompts:CUD",
- });
-
- return (
- <Page
- headerProps={{
- title: "Widgets",
- help: {
- description: "Manage and create widgets for your dashboard.",
- href: "https://langfuse.com/docs/metrics/features/custom-dashboards",
- },
- tabsProps: {
- tabs: getDashboardTabs(projectId),
- activeTab: DASHBOARD_TABS.WIDGETS,
- },
- actionButtonsRight: (
- <ActionButton
- icon={<PlusIcon className="h-4 w-4" aria-hidden="true" />}
- hasAccess={hasCUDAccess}
- href={`/project/${projectId}/widgets/new`}
- trackingEventName="dashboard:new_widget_form_open"
- variant="default"
- >
- New widget
- </ActionButton>
- ),
- }}
- >
- <ConnectedDashboardWidgetTable />
- </Page>
- );
-}
+export { default } from "@/src/features/widgets/WidgetsPage";
diff --git a/web/src/pages/public/traces/[traceId].tsx b/web/src/pages/public/traces/[traceId].tsx
index 4e9355ee15..f09bdbdd49 100644
--- a/web/src/pages/public/traces/[traceId].tsx
+++ b/web/src/pages/public/traces/[traceId].tsx
@@ -1,9 +1,2 @@
-// This url is deprecated, we keep this redirect page for backward compatibility
-
-import TraceRedirectPage, {
- getServerSideProps,
-} from "@/src/pages/trace/[traceId]";
-
-export { getServerSideProps };
-
-export default TraceRedirectPage;
+export { default } from "@/src/features/traces/TraceRedirectPage";
+export { getServerSideProps } from "@/src/features/traces/server/getTraceRedirectPageServerSideProps";
diff --git a/web/src/pages/trace/[traceId].tsx b/web/src/pages/trace/[traceId].tsx
index 4c1ec6e3df..f09bdbdd49 100644
--- a/web/src/pages/trace/[traceId].tsx
+++ b/web/src/pages/trace/[traceId].tsx
@@ -1,84 +1,2 @@
-// Redirect helper for /trace/[traceId] URLs
-// Looks up the projectId for a trace and redirects to /project/[projectId]/traces/[traceId]
-// which displays the current trace view
-
-import { ErrorPage } from "@/src/components/error-page";
-import { getTracesByIdsForAnyProject } from "@langfuse/shared/src/server";
-import { type GetServerSideProps } from "next";
-import { useRouter } from "next/router";
-
-export const getServerSideProps: GetServerSideProps = async (context) => {
- if (!context.params) {
- return {
- props: {
- notFound: true,
- },
- };
- }
-
- const traceId = context.params.traceId as string;
-
- const traces = await getTracesByIdsForAnyProject([traceId]);
-
- if (!traces || traces.length === 0) {
- return {
- props: {
- notFound: true,
- },
- };
- }
-
- if (traces.length > 1) {
- return {
- props: {
- duplicatesFound: true,
- },
- };
- }
-
- return {
- redirect: {
- destination: `/project/${traces[0].projectId}/traces/${traceId}`,
- permanent: false,
- },
- };
-};
-
-const TraceRedirectPage = ({
- notFound,
- duplicatesFound,
-}: {
- notFound?: boolean;
- duplicatesFound?: boolean;
-}) => {
- const router = useRouter();
- if (router.isFallback) {
- return <div className="p-3">Loading...</div>;
- }
-
- if (notFound) {
- return (
- <ErrorPage
- title="Trace not found"
- message="The trace is either still being processed or has been deleted."
- additionalButton={{
- label: "Retry",
- onClick: () => window.location.reload(),
- }}
- />
- );
- }
-
- if (duplicatesFound) {
- return (
- <ErrorPage
- title="Trace not found"
- message="Please upgrade the SDK as the URL schema has changed."
- />
- );
- }
-
- return null;
-};
-
-export default TraceRedirectPage;
+export { default } from "@/src/features/traces/TraceRedirectPage";
+export { getServerSideProps } from "@/src/features/traces/server/getTraceRedirectPageServerSideProps";