🪢 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
/* 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",
divider: false,
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",
divider: false,
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,
},
}}
>
{/* 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. */}
{!isResolved ? null : isV4 ? (
<ObservationsEventsTable
projectId={projectId}
showControlsInPageHeader
enableAppRootDefault
/>
) : (
<TracesTable projectId={projectId} showControlsInPageHeader />
)}
</Page>
);
}