Skip to content

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

refactor: access evals ui via cloud only (#1721)

Max Deichmanne6be67bb8295
diff --git a/packages/shared/src/db.ts b/packages/shared/src/db.ts
index 2336724573..f1c4f5e3f6 100644
--- a/packages/shared/src/db.ts
+++ b/packages/shared/src/db.ts
@@ -16,7 +16,6 @@ import { DB } from ".";
// https://www.prisma.io/docs/orm/more/help-and-troubleshooting/help-articles/nextjs-prisma-client-dev-practices
const prismaClientSingleton = () => {
- console.log("Creating new PrismaClient");
return new PrismaClient({
log:
env.NODE_ENV === "development"
@@ -26,7 +25,6 @@ const prismaClientSingleton = () => {
};
const kyselySingleton = (prismaClient: PrismaClient) => {
- console.log("Creating new Kysely client");
return prismaClient.$extends(
kyselyExtension({
kysely: (driver) =>
diff --git a/web/src/components/layouts/layout.tsx b/web/src/components/layouts/layout.tsx
index 5b7ae1a90a..fba8eaca7f 100644
--- a/web/src/components/layouts/layout.tsx
+++ b/web/src/components/layouts/layout.tsx
@@ -75,6 +75,14 @@ export default function Layout(props: PropsWithChildren) {
)
return null;
+ // cloud only
+ if (
+ route.cloudOnly !== undefined &&
+ // the feature should be available in local development
+ route.cloudOnly !== (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== undefined)
+ )
+ return null;
+
// RBAC
if (
route.rbacScope !== undefined &&
diff --git a/web/src/components/layouts/routes.ts b/web/src/components/layouts/routes.ts
index fe913ddee2..7369d4db3b 100644
--- a/web/src/components/layouts/routes.ts
+++ b/web/src/components/layouts/routes.ts
@@ -23,6 +23,7 @@ export type Route = {
children?: Array<Route>; // folder
bottom?: boolean; // bottom of the sidebar, only for first level routes
newTab?: boolean; // open in new tab
+ cloudOnly?: boolean; // only available in cloud
};
export const ROUTES: Route[] = [
@@ -58,11 +59,13 @@ export const ROUTES: Route[] = [
{
name: "Templates",
pathname: `/project/[projectId]/evals/templates`,
+ cloudOnly: true,
featureFlag: "evals",
},
{
name: "Configs",
pathname: `/project/[projectId]/evals/configs`,
+ cloudOnly: true,
featureFlag: "evals",
},
],
diff --git a/web/src/env.mjs b/web/src/env.mjs
index 2684543d99..491d133adb 100644
--- a/web/src/env.mjs
+++ b/web/src/env.mjs
@@ -86,13 +86,13 @@ export const env = createEnv({
* Specify your client-side environment variables schema here. This way you can ensure the app
* isn't built with invalid env vars. To expose them to the client, prefix them with
* `NEXT_PUBLIC_`.
- *
+ *
* WARNING: They do not work when used in Docker builds as NEXT_PUBLIC variables are not runtime but compile-time.
*/
client: {
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: z
- .enum(["US", "EU", "STAGING"])
+ .enum(["US", "EU", "STAGING", "DEV"])
.optional(),
NEXT_PUBLIC_DEMO_PROJECT_ID: z.string().optional(),
NEXT_PUBLIC_SIGN_UP_DISABLED: z.enum(["true", "false"]).optional(),
diff --git a/web/src/features/email/lib/project-invitation.ts b/web/src/features/email/lib/project-invitation.ts
index 6b2c6ac098..e904708ab2 100644
--- a/web/src/features/email/lib/project-invitation.ts
+++ b/web/src/features/email/lib/project-invitation.ts
@@ -11,9 +11,12 @@ const langfuseUrls = {
STAGING: "https://staging.langfuse.com",
};
-const authUrl = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
- ? langfuseUrls[env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION]
- : env.NEXTAUTH_URL;
+const authUrl =
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "US" ||
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "EU" ||
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "STAGING"
+ ? langfuseUrls[env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION]
+ : env.NEXTAUTH_URL;
export const sendProjectInvitation = async (
to: string,
diff --git a/web/src/features/evals/server/router.ts b/web/src/features/evals/server/router.ts
index 82378b346b..4138910e8e 100644
--- a/web/src/features/evals/server/router.ts
+++ b/web/src/features/evals/server/router.ts
@@ -13,6 +13,7 @@ import {
singleFilter,
variableMapping,
} from "@langfuse/shared";
+import { env } from "@/src/env.mjs";
export const CreateEvalTemplate = z.object({
name: z.string().min(1),
@@ -37,6 +38,10 @@ export const evalRouter = createTRPCRouter({
}),
)
.query(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
+
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -75,6 +80,9 @@ export const evalRouter = createTRPCRouter({
}),
)
.query(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -102,6 +110,9 @@ export const evalRouter = createTRPCRouter({
}),
)
.query(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -126,6 +137,9 @@ export const evalRouter = createTRPCRouter({
z.object({ projectId: z.string(), page: z.number(), limit: z.number() }),
)
.query(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -166,6 +180,9 @@ export const evalRouter = createTRPCRouter({
}),
)
.query(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -191,6 +208,9 @@ export const evalRouter = createTRPCRouter({
}),
)
.query(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -234,6 +254,9 @@ export const evalRouter = createTRPCRouter({
)
.mutation(async ({ input, ctx }) => {
try {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -282,6 +305,9 @@ export const evalRouter = createTRPCRouter({
createTemplate: protectedProjectProcedure
.input(CreateEvalTemplate)
.mutation(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
@@ -327,6 +353,9 @@ export const evalRouter = createTRPCRouter({
}),
)
.mutation(async ({ input, ctx }) => {
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === undefined) {
+ throw new Error("Evals available in cloud only");
+ }
throwIfNoAccess({
session: ctx.session,
projectId: input.projectId,
diff --git a/web/src/pages/api/public/ingestion.ts b/web/src/pages/api/public/ingestion.ts
index 4f321f0866..8d920ea7b6 100644
--- a/web/src/pages/api/public/ingestion.ts
+++ b/web/src/pages/api/public/ingestion.ts
@@ -424,7 +424,11 @@ export const sendToWorkerIfEnvironmentConfigured = async (
projectId: string,
): Promise<void> => {
try {
- if (env.LANGFUSE_WORKER_HOST && env.LANGFUSE_WORKER_PASSWORD) {
+ if (
+ env.LANGFUSE_WORKER_HOST &&
+ env.LANGFUSE_WORKER_PASSWORD &&
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
+ ) {
const traceEvents = batchResults
.filter((result) => result.type === eventTypes.TRACE_CREATE) // we only have create, no update.
.map((result) =>
diff --git a/web/src/server/api/routers/environment.ts b/web/src/server/api/routers/environment.ts
index 50f5f69ef3..a8d9501185 100644
--- a/web/src/server/api/routers/environment.ts
+++ b/web/src/server/api/routers/environment.ts
@@ -2,6 +2,8 @@ import { env } from "@/src/env.mjs";
import { createTRPCRouter, publicProcedure } from "@/src/server/api/trpc";
export const environmentRouter = createTRPCRouter({
+ // NEXT_PUBLIC_ does not work on Docker containers.
+ // Hence, this needs to be pulled form the server.
enableExperimentalFeatures: publicProcedure.query(
() => env.LANGFUSE_ENABLE_EXPERIMENTAL_FEATURES === "true",
),