Skip to content

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

refactor(web): move traces table into features/traces (#17417)

Nikita Kabardinb2359f6071fc
diff --git a/web/src/features/evals/components/inner-evaluator-form.tsx b/web/src/features/evals/components/inner-evaluator-form.tsx
index f20b48f6c0..b819978e02 100644
--- a/web/src/features/evals/components/inner-evaluator-form.tsx
+++ b/web/src/features/evals/components/inner-evaluator-form.tsx
@@ -122,9 +122,7 @@ import { cn } from "@/src/utils/tailwind";
import { PeekTableStateProvider } from "@/src/components/table/peek/contexts/PeekTableStateContext";
// Lazy load tables
-const TracesTable = lazy(
- () => import("@/src/components/table/use-cases/traces"),
-);
+const TracesTable = lazy(() => import("@/src/features/traces/TracesTable"));
const ObservationsTable = lazy(
() => import("@/src/components/table/use-cases/observations"),
);
diff --git a/web/src/features/traces/TracesPage.tsx b/web/src/features/traces/TracesPage.tsx
new file mode 100644
index 0000000000..47dccb5fe0
--- /dev/null
+++ b/web/src/features/traces/TracesPage.tsx
@@ -0,0 +1,111 @@
+/* eslint-disable no-nested-ternary */
+import { useRouter } from "next/router";
+import TracesTable from "@/src/features/traces/TracesTable";
+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 { useReadPath } from "@/src/features/events/hooks/useReadPath";
+import ObservationsEventsTable from "@/src/features/events/components/EventsTable";
+import { useQueryProject } from "@/src/features/projects/hooks";
+import { V4MigrationDelayBadge } from "@/src/features/v4-migration/V4MigrationDelayBadge";
+
+export default function TracesPage() {
+ const router = useRouter();
+ const projectId = router.query.projectId as string;
+ const { isV4, isResolved } = useReadPath();
+ 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;
+
+ if (showOnboarding) {
+ return (
+ <Page
+ headerProps={{
+ title: "Tracing",
+ help: {
+ description:
+ "A trace represents a single function/api invocation. Traces contain observations. See [docs](https://langfuse.com/docs/observability/data-model) to learn more.",
+ href: "https://langfuse.com/docs/observability/data-model",
+ },
+ }}
+ scrollable
+ >
+ <TracesOnboarding projectId={projectId} />
+ </Page>
+ );
+ }
+
+ return (
+ <Page
+ headerProps={{
+ title: "Tracing",
+ titleBadges: <V4MigrationDelayBadge page="traces" />,
+ help: {
+ description: (
+ <>
+ A trace represents a single function/api invocation. Traces
+ contain observations. See{" "}
+ <a
+ href="https://langfuse.com/docs/observability/data-model"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="decoration-primary/30 hover:decoration-primary underline"
+ onClick={(e) => e.stopPropagation()}
+ >
+ docs
+ </a>{" "}
+ to learn more.
+ </>
+ ),
+ href: "https://langfuse.com/docs/observability/data-model",
+ },
+ tabsProps:
+ isV4 || !isResolved
+ ? undefined
+ : {
+ tabs: getTracingTabs(projectId),
+ activeTab: TRACING_TABS.TRACES,
+ },
+ }}
+ >
+ {!isResolved ? (
+ <>
+ {/* Wait for the beta flag before mounting either table. Otherwise the
+ legacy table can briefly mount, restore a v3 saved view, and
+ promote its viewId into the URL before the correct mode
+ resolves. */}
+ </>
+ ) : isV4 ? (
+ <ObservationsEventsTable
+ projectId={projectId}
+ showControlsInPageHeader
+ enableAppRootDefault
+ />
+ ) : (
+ <TracesTable projectId={projectId} showControlsInPageHeader />
+ )}
+ </Page>
+ );
+}
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/features/traces/TracesTable.tsx
similarity index 100%
rename from web/src/components/table/use-cases/traces.tsx
rename to web/src/features/traces/TracesTable.tsx
diff --git a/web/src/features/traces/index.ts b/web/src/features/traces/index.ts
index c6c864075a..d29a6c6b70 100644
--- a/web/src/features/traces/index.ts
+++ b/web/src/features/traces/index.ts
@@ -46,3 +46,5 @@ export {
type CommentRange,
type CommentedPathsByField,
} from "@/src/features/traces/components/AdvancedJsonViewer/utils/commentRanges";
+
+export { default as TracesTable } from "@/src/features/traces/TracesTable";
diff --git a/web/src/features/users/UserDetailPage.tsx b/web/src/features/users/UserDetailPage.tsx
index a5ef715dcb..1fe217096d 100644
--- a/web/src/features/users/UserDetailPage.tsx
+++ b/web/src/features/users/UserDetailPage.tsx
@@ -5,7 +5,7 @@ import {
RouteParamsPendingFallback,
useReadyRouteParams,
} from "@/src/hooks/useReadyRouteParams";
-import TracesTable from "@/src/components/table/use-cases/traces";
+import { TracesTable } from "@/src/features/traces";
import { ScoresTable } from "@/src/features/scores";
import { TablePeekViewTraceDetail } from "@/src/components/table/peek/peek-trace-detail";
import { compactNumberFormatter, usdFormatter } from "@/src/utils/numbers";
diff --git a/web/src/pages/project/[projectId]/traces/index.tsx b/web/src/pages/project/[projectId]/traces/index.tsx
index 3a1017a08a..0a40ff11b0 100644
--- a/web/src/pages/project/[projectId]/traces/index.tsx
+++ b/web/src/pages/project/[projectId]/traces/index.tsx
@@ -1,111 +1 @@
-/* eslint-disable no-nested-ternary */
-import { useRouter } from "next/router";
-import TracesTable from "@/src/components/table/use-cases/traces";
-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 { useReadPath } from "@/src/features/events/hooks/useReadPath";
-import ObservationsEventsTable from "@/src/features/events/components/EventsTable";
-import { useQueryProject } from "@/src/features/projects/hooks";
-import { V4MigrationDelayBadge } from "@/src/features/v4-migration/V4MigrationDelayBadge";
-
-export default function Traces() {
- const router = useRouter();
- const projectId = router.query.projectId as string;
- const { isV4, isResolved } = useReadPath();
- 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;
-
- if (showOnboarding) {
- return (
- <Page
- headerProps={{
- title: "Tracing",
- help: {
- description:
- "A trace represents a single function/api invocation. Traces contain observations. See [docs](https://langfuse.com/docs/observability/data-model) to learn more.",
- href: "https://langfuse.com/docs/observability/data-model",
- },
- }}
- scrollable
- >
- <TracesOnboarding projectId={projectId} />
- </Page>
- );
- }
-
- return (
- <Page
- headerProps={{
- title: "Tracing",
- titleBadges: <V4MigrationDelayBadge page="traces" />,
- help: {
- description: (
- <>
- A trace represents a single function/api invocation. Traces
- contain observations. See{" "}
- <a
- href="https://langfuse.com/docs/observability/data-model"
- target="_blank"
- rel="noopener noreferrer"
- className="decoration-primary/30 hover:decoration-primary underline"
- onClick={(e) => e.stopPropagation()}
- >
- docs
- </a>{" "}
- to learn more.
- </>
- ),
- href: "https://langfuse.com/docs/observability/data-model",
- },
- tabsProps:
- isV4 || !isResolved
- ? undefined
- : {
- tabs: getTracingTabs(projectId),
- activeTab: TRACING_TABS.TRACES,
- },
- }}
- >
- {!isResolved ? (
- <>
- {/* Wait for the beta flag before mounting either table. Otherwise the
- legacy table can briefly mount, restore a v3 saved view, and
- promote its viewId into the URL before the correct mode
- resolves. */}
- </>
- ) : isV4 ? (
- <ObservationsEventsTable
- projectId={projectId}
- showControlsInPageHeader
- enableAppRootDefault
- />
- ) : (
- <TracesTable projectId={projectId} showControlsInPageHeader />
- )}
- </Page>
- );
-}
+export { default } from "@/src/features/traces/TracesPage";