🪢 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
chore: Check tracing configuration for data retention (#9045)
Max Deichmann6a7034a5ad42
diff --git a/web/src/features/setup/components/SetupPage.tsx b/web/src/features/setup/components/SetupPage.tsxindex 5934dc9b6f..7607f450e7 100644--- a/web/src/features/setup/components/SetupPage.tsx+++ b/web/src/features/setup/components/SetupPage.tsx@@ -50,7 +50,7 @@ export function SetupPage() {? 3: 2;- const hasAnyTrace = api.traces.hasAny.useQuery(+ const hasTracingConfigured = api.traces.hasTracingConfigured.useQuery({ projectId: queryProjectId as string },{enabled: queryProjectId !== undefined && stepInt === 4,@@ -65,10 +65,12 @@ export function SetupPage() {const capture = usePostHogClientCapture();useEffect(() => {- if (hasAnyTrace !== undefined) {- capture("onboarding:tracing_check_active", { active: hasAnyTrace });+ if (hasTracingConfigured !== undefined) {+ capture("onboarding:tracing_check_active", {+ active: hasTracingConfigured,+ });}- }, [hasAnyTrace, capture]);+ }, [hasTracingConfigured, capture]);return (<ContainerPage@@ -202,7 +204,7 @@ export function SetupPage() {stepInt === 4 && project && organization && (<TracingSetupprojectId={project.id}- hasAnyTrace={hasAnyTrace ?? false}+ hasTracingConfigured={hasTracingConfigured ?? false}/>)}@@ -223,9 +225,9 @@ export function SetupPage() {<ButtonclassName="mt-4 self-start"onClick={() => router.push(`/project/${project.id}`)}- variant={hasAnyTrace ? "default" : "secondary"}+ variant={hasTracingConfigured ? "default" : "secondary"}>- {hasAnyTrace ? "Open Dashboard" : "Skip for now"}+ {hasTracingConfigured ? "Open Dashboard" : "Skip for now"}</Button>)}@@ -235,10 +237,10 @@ export function SetupPage() {const TracingSetup = ({projectId,- hasAnyTrace,+ hasTracingConfigured,}: {projectId: string;- hasAnyTrace?: boolean;+ hasTracingConfigured?: boolean;}) => {const [apiKeys, setApiKeys] = useState<RouterOutput["projectApiKeys"]["create"] | null@@ -288,7 +290,7 @@ const TracingSetup = ({<div><Headertitle="Setup Tracing"- status={hasAnyTrace ? "active" : "pending"}+ status={hasTracingConfigured ? "active" : "pending"}/><p className="mb-4 text-sm text-muted-foreground">Tracing is used to track and analyze your LLM calls. You can alwaysdiff --git a/web/src/features/setup/components/SetupTracingButton.tsx b/web/src/features/setup/components/SetupTracingButton.tsxindex e625098fe1..2893de5a14 100644--- a/web/src/features/setup/components/SetupTracingButton.tsx+++ b/web/src/features/setup/components/SetupTracingButton.tsx@@ -15,34 +15,37 @@ const SetupTracingButton = () => {const router = useRouter();const queryProjectId = router.query.projectId as string | undefined;- const { data: hasAnyTrace, isLoading } = api.traces.hasAny.useQuery(- { projectId: queryProjectId as string },- {- enabled: queryProjectId !== undefined,- trpc: {- context: {- skipBatch: true,+ const { data: hasTracingConfigured, isLoading } =+ api.traces.hasTracingConfigured.useQuery(+ { projectId: queryProjectId as string },+ {+ enabled: queryProjectId !== undefined,+ trpc: {+ context: {+ skipBatch: true,+ },},},- },- );+ );// dedupe result via useRef, otherwise we'll capture the event multiple times on session refreshconst capturedEventAlready = useRef<boolean | undefined>(undefined);const capture = usePostHogClientCapture();useEffect(() => {- if (hasAnyTrace !== undefined && !capturedEventAlready.current) {- capture("onboarding:tracing_check_active", { active: hasAnyTrace });+ if (hasTracingConfigured !== undefined && !capturedEventAlready.current) {+ capture("onboarding:tracing_check_active", {+ active: hasTracingConfigured,+ });capturedEventAlready.current = true;}- }, [hasAnyTrace, capture]);+ }, [hasTracingConfigured, capture]);const hasAccess = useHasProjectAccess({projectId: project?.id,scope: "apiKeys:CUD",});- if (isLoading || hasAnyTrace || !project) {+ if (isLoading || hasTracingConfigured || !project) {return null;}diff --git a/web/src/pages/project/[projectId]/observations.tsx b/web/src/pages/project/[projectId]/observations.tsxindex 647ea3291d..69c00fde9c 100644--- a/web/src/pages/project/[projectId]/observations.tsx+++ b/web/src/pages/project/[projectId]/observations.tsx@@ -13,21 +13,22 @@ export default function Generations() {const router = useRouter();const projectId = router.query.projectId as string;- // Check if the user has any traces- const { data: hasAnyTrace, isLoading } = api.traces.hasAny.useQuery(- { projectId },- {- enabled: !!projectId,- trpc: {- context: {- skipBatch: true,+ // Check if the user has tracing configured+ const { data: hasTracingConfigured, isLoading } =+ api.traces.hasTracingConfigured.useQuery(+ { projectId },+ {+ enabled: !!projectId,+ trpc: {+ context: {+ skipBatch: true,+ },},+ refetchInterval: 10_000,},- refetchInterval: 10_000,- },- );+ );- const showOnboarding = !isLoading && !hasAnyTrace;+ const showOnboarding = !isLoading && !hasTracingConfigured;return (<Pagediff --git a/web/src/pages/project/[projectId]/traces.tsx b/web/src/pages/project/[projectId]/traces.tsxindex 9e8e4e34d2..f3a100d3c3 100644--- a/web/src/pages/project/[projectId]/traces.tsx+++ b/web/src/pages/project/[projectId]/traces.tsx@@ -13,21 +13,22 @@ export default function Traces() {const router = useRouter();const projectId = router.query.projectId as string;- // Check if the user has any traces- const { data: hasAnyTrace, isLoading } = api.traces.hasAny.useQuery(- { projectId },- {- enabled: !!projectId,- trpc: {- context: {- skipBatch: true,+ // Check if the user has tracing configured+ const { data: hasTracingConfigured, isLoading } =+ api.traces.hasTracingConfigured.useQuery(+ { projectId },+ {+ enabled: !!projectId,+ trpc: {+ context: {+ skipBatch: true,+ },},+ refetchInterval: 10_000,},- refetchInterval: 10_000,- },- );+ );- const showOnboarding = !isLoading && !hasAnyTrace;+ const showOnboarding = !isLoading && !hasTracingConfigured;return (<Pagediff --git a/web/src/server/api/routers/traces.ts b/web/src/server/api/routers/traces.tsindex 30509ff666..429e8c22b4 100644--- a/web/src/server/api/routers/traces.ts+++ b/web/src/server/api/routers/traces.ts@@ -72,14 +72,32 @@ export type ObservationReturnType = Omit<>;export const traceRouter = createTRPCRouter({- hasAny: protectedProjectProcedure+ hasTracingConfigured: protectedProjectProcedure.input(z.object({projectId: z.string(),}),)- .query(async ({ input }) => {- return hasAnyTrace(input.projectId);+ .query(async ({ input, ctx }) => {+ // Check if there are any traces in the database+ const hasTraces = await hasAnyTrace(input.projectId);++ if (hasTraces) {+ return true;+ }++ // If no traces, check if data retention is configured+ // This indicates the user has configured tracing even if data retention cleaned all traces+ const project = await ctx.prisma.project.findUnique({+ where: {+ id: input.projectId,+ },+ select: {+ retentionDays: true,+ },+ });++ return !!(project?.retentionDays && project.retentionDays > 0);}),all: protectedProjectProcedure.input(TraceFilterOptions)