Skip to content

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

feat: add optional `LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES` (#2026)

Marc Klingen90f89f8b3360
diff --git a/.env.prod.example b/.env.prod.example
index f8fccb3d76..082e41c835 100644
--- a/.env.prod.example
+++ b/.env.prod.example
@@ -80,6 +80,17 @@ LANGFUSE_CSP_ENFORCE_HTTPS="true"
# ENABLE_EVENT_LOG=false
+
+### START Envs to be deprecated in Langfuse v3.0
+
+# Disable the expensive analytics queries and related features
+# LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES="true"
+
+### END Envs to be deprecated in Langfuse v3.0
+
+
+
+
### START Langfuse Cloud Config
# Used for Langfuse Cloud deployments
# Not recommended for self-hosted deployments as these are NOT COVERED BY SEMVER
diff --git a/web/src/env.mjs b/web/src/env.mjs
index 170f06671f..9ed27afe09 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -30,6 +30,7 @@ export const env = createEnv({
LANGFUSE_NEW_USER_SIGNUP_WEBHOOK: z.string().url().optional(),
// Add `.min(1) on ID and SECRET if you want to make sure they're not empty
LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES: z.enum(["true", "false"]).optional(),
+ LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES: z.enum(["true", "false"]).optional().default("false"),
SALT: z.string({
required_error:
"A strong Salt is required to encrypt API keys securely. See: https://langfuse.com/docs/deployment/self-host#deploy-the-container",
@@ -121,6 +122,8 @@ export const env = createEnv({
NEXT_PUBLIC_SIGN_UP_DISABLED: process.env.NEXT_PUBLIC_SIGN_UP_DISABLED,
LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES:
process.env.LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES,
+ LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES:
+ process.env.LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES,
LANGFUSE_TEAM_SLACK_WEBHOOK: process.env.LANGFUSE_TEAM_SLACK_WEBHOOK,
LANGFUSE_TEAM_BETTERSTACK_TOKEN:
process.env.LANGFUSE_TEAM_BETTERSTACK_TOKEN,
diff --git a/web/src/pages/project/[projectId]/index.tsx b/web/src/pages/project/[projectId]/index.tsx
index db2a3aacf0..e4638a65f7 100644
--- a/web/src/pages/project/[projectId]/index.tsx
+++ b/web/src/pages/project/[projectId]/index.tsx
@@ -46,6 +46,8 @@ export default function Start() {
const capture = usePostHogClientCapture();
const session = useSession();
+ const disableExpensiveDashboardComponents =
+ session.data?.environment.disableExpensivePostgresQueries ?? true;
const project = session.data?.user?.projects.find(
(project) => project.id === projectId,
);
@@ -187,11 +189,13 @@ export default function Start() {
projectId={projectId}
globalFilterState={mergedFilterState}
/>
- <MetricTable
- className="col-span-1 xl:col-span-2"
- projectId={projectId}
- globalFilterState={mergedFilterState}
- />
+ {!disableExpensiveDashboardComponents && (
+ <MetricTable
+ className="col-span-1 xl:col-span-2"
+ projectId={projectId}
+ globalFilterState={mergedFilterState}
+ />
+ )}
<ScoresTable
className="col-span-1 xl:col-span-2"
projectId={projectId}
@@ -203,34 +207,42 @@ export default function Start() {
globalFilterState={mergedFilterState}
agg={agg}
/>
- <ModelUsageChart
- className="col-span-1 min-h-24 xl:col-span-3"
- projectId={projectId}
- globalFilterState={mergedFilterState}
- agg={agg}
- />
- <UserChart
- className="col-span-1 xl:col-span-3"
- projectId={projectId}
- globalFilterState={mergedFilterState}
- agg={agg}
- />
+ {!disableExpensiveDashboardComponents && (
+ <ModelUsageChart
+ className="col-span-1 min-h-24 xl:col-span-3"
+ projectId={projectId}
+ globalFilterState={mergedFilterState}
+ agg={agg}
+ />
+ )}
+ {!disableExpensiveDashboardComponents && (
+ <UserChart
+ className="col-span-1 xl:col-span-3"
+ projectId={projectId}
+ globalFilterState={mergedFilterState}
+ agg={agg}
+ />
+ )}
<ChartScores
className="col-span-1 xl:col-span-3"
agg={agg}
projectId={projectId}
globalFilterState={mergedFilterState}
/>
- <LatencyTables
- projectId={projectId}
- globalFilterState={mergedFilterState}
- />
- <GenerationLatencyChart
- className="col-span-1 flex-auto justify-between lg:col-span-full"
- projectId={projectId}
- agg={agg}
- globalFilterState={mergedFilterState}
- />
+ {!disableExpensiveDashboardComponents && (
+ <LatencyTables
+ projectId={projectId}
+ globalFilterState={mergedFilterState}
+ />
+ )}
+ {!disableExpensiveDashboardComponents && (
+ <GenerationLatencyChart
+ className="col-span-1 flex-auto justify-between lg:col-span-full"
+ projectId={projectId}
+ agg={agg}
+ globalFilterState={mergedFilterState}
+ />
+ )}
</div>
</div>
);
diff --git a/web/src/server/auth.ts b/web/src/server/auth.ts
index 7c6ab82d4a..d794071a53 100644
--- a/web/src/server/auth.ts
+++ b/web/src/server/auth.ts
@@ -246,6 +246,8 @@ export async function getAuthOptions(): Promise<NextAuthOptions> {
environment: {
enableExperimentalFeatures:
env.LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES === "true",
+ disableExpensivePostgresQueries:
+ env.LANGFUSE_DISABLE_EXPENSIVE_POSTGRES_QUERIES === "true",
},
user:
dbUser !== null
diff --git a/web/types/next-auth.d.ts b/web/types/next-auth.d.ts
index 5a241cdaff..ebda77de59 100644
--- a/web/types/next-auth.d.ts
+++ b/web/types/next-auth.d.ts
@@ -18,6 +18,7 @@ declare module "next-auth" {
environment: {
// Run-time environment variables that need to be available client-side
enableExperimentalFeatures: boolean;
+ disableExpensivePostgresQueries: boolean;
};
}