Skip to content

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

feat: support for staging environment

Marc Klingend5c117cf5da3
diff --git a/src/env.mjs b/src/env.mjs
index 1ce027f113..5e94a2fe84 100644
--- a/src/env.mjs
+++ b/src/env.mjs
@@ -49,7 +49,7 @@ export const env = createEnv({
*/
client: {
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
- NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: z.enum(["US", "EU"]).optional(),
+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: z.enum(["US", "EU", "STAGING"]).optional(),
NEXT_PUBLIC_DEMO_PROJECT_ID: z.string().optional(),
NEXT_PUBLIC_SIGN_UP_DISABLED: z.enum(["true", "false"]).optional(),
},
diff --git a/src/features/auth/components/AuthCloudRegionSwitch.tsx b/src/features/auth/components/AuthCloudRegionSwitch.tsx
index 60b8ca9a8b..4c79d6023d 100644
--- a/src/features/auth/components/AuthCloudRegionSwitch.tsx
+++ b/src/features/auth/components/AuthCloudRegionSwitch.tsx
@@ -3,18 +3,27 @@ import { Tabs, TabsList, TabsTrigger } from "@/src/components/ui/tabs";
import { Divider } from "@tremor/react";
import { usePostHog } from "posthog-js/react";
-const regions = [
- {
- name: "US",
- hostname: "us.cloud.langfuse.com",
- flag: "🇺🇸",
- },
- {
- name: "EU",
- hostname: "cloud.langfuse.com",
- flag: "🇪🇺",
- },
-];
+const regions =
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "STAGING"
+ ? [
+ {
+ name: "EU (Staging)",
+ hostname: "staging.langfuse.com",
+ flag: "🇪🇺",
+ },
+ ]
+ : [
+ {
+ name: "US",
+ hostname: "us.cloud.langfuse.com",
+ flag: "🇺🇸",
+ },
+ {
+ name: "EU",
+ hostname: "cloud.langfuse.com",
+ flag: "🇪🇺",
+ },
+ ];
export function CloudRegionSwitch({
isSignUpPage,
diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx
index 4693c7935c..c3a24ecb05 100644
--- a/src/pages/_app.tsx
+++ b/src/pages/_app.tsx
@@ -105,6 +105,7 @@ function UserTracking() {
process.env.NEXT_PUBLIC_POSTHOG_HOST
)
posthog.identify(session.data.user?.id ?? undefined, {
+ environment: process.env.NODE_ENV,
email: session.data.user?.email ?? undefined,
name: session.data.user?.name ?? undefined,
featureFlags: session.data.user?.featureFlags ?? undefined,
diff --git a/src/pages/api/auth/signup.ts b/src/pages/api/auth/signup.ts
index 16272d9276..eed05650bf 100644
--- a/src/pages/api/auth/signup.ts
+++ b/src/pages/api/auth/signup.ts
@@ -70,7 +70,8 @@ export default async function handler(
// Trigger new user signup event
if (
env.LANGFUSE_NEW_USER_SIGNUP_WEBHOOK &&
- env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION &&
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== "STAGING"
) {
await fetch(env.LANGFUSE_NEW_USER_SIGNUP_WEBHOOK, {
method: "POST",
diff --git a/src/pages/api/cron/ingestion-metrics.ts b/src/pages/api/cron/ingestion-metrics.ts
index f78c56c704..6f2bdd62e6 100644
--- a/src/pages/api/cron/ingestion-metrics.ts
+++ b/src/pages/api/cron/ingestion-metrics.ts
@@ -16,6 +16,11 @@ export default async function handler(
message: "Only runs on Langfuse Cloud, no LANGFUSE_CLOUD_REGION provided",
});
+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "STAGING")
+ return res.status(200).json({
+ message: "Does not run on staging, LANGFUSE_CLOUD_REGION is STAGING",
+ });
+
const posthog_event_user_id =
env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "US"
? "langfuse-cloud-us"
diff --git a/src/server/auth.ts b/src/server/auth.ts
index 87879ef942..0df63dd0d9 100644
--- a/src/server/auth.ts
+++ b/src/server/auth.ts
@@ -239,7 +239,8 @@ export const authOptions: NextAuthOptions = {
createUser: async ({ user }) => {
if (
env.LANGFUSE_NEW_USER_SIGNUP_WEBHOOK &&
- env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION &&
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== "STAGING"
) {
await fetch(env.LANGFUSE_NEW_USER_SIGNUP_WEBHOOK, {
method: "POST",