Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(web): Add region selector to user menu (#13270)

Ben Bachemc735ea914a66
diff --git a/web/src/components/EnvLabel.tsx b/web/src/components/EnvLabel.tsx
index 6b3d8e9620..7f5a36b98b 100644
--- a/web/src/components/EnvLabel.tsx
+++ b/web/src/components/EnvLabel.tsx
@@ -1,3 +1,4 @@
+import { isRegionProduction } from "@/src/features/organizations/cloudRegions";
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { cn } from "@/src/utils/tailwind";
import { useSession } from "next-auth/react";
@@ -7,6 +8,9 @@ export const EnvLabel = ({ className }: { className?: string }) => {
const [isHidden, setIsHidden] = useState(false);
const session = useSession();
const { isLangfuseCloud, region } = useLangfuseCloudRegion();
+ const label =
+ region && isRegionProduction(region) ? `PROD-${region}` : region;
+
if (!isLangfuseCloud) return null;
if (!session.data?.user?.email?.endsWith("@langfuse.com")) return null;
if (isHidden) return null;
@@ -23,9 +27,7 @@ export const EnvLabel = ({ className }: { className?: string }) => {
)}
onClick={() => setIsHidden(true)}
>
- {region && ["EU", "US", "HIPAA", "JP"].includes(region)
- ? `PROD-${region}`
- : region}
+ {label}
</div>
);
};
diff --git a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
index 844328c4bc..5489781120 100644
--- a/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
+++ b/web/src/components/layouts/app-layout/variants/AuthenticatedLayout.tsx
@@ -12,6 +12,8 @@ import { Toaster } from "@/src/components/ui/sonner";
import { TopBannerProvider } from "@/src/features/top-banner";
import { ResizableContent } from "../components/ResizableContent";
import { ThemeToggle } from "@/src/features/theming/ThemeToggle";
+import { getAvailableCloudRegionOptions } from "@/src/features/organizations/cloudRegions";
+import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import type { Session } from "next-auth";
import type { NavigationItem } from "@/src/components/layouts/utilities/routes";
import type { RouteGroup } from "@/src/components/layouts/routes";
@@ -96,6 +98,8 @@ export function AuthenticatedLayout({
metadata,
onSignOut,
}: AuthenticatedLayoutProps) {
+ const { isLangfuseCloud, region: currentRegion } = useLangfuseCloudRegion();
+
// Safe assertion: AuthenticatedLayout is only rendered after auth checks pass
// in AppLayout, which guarantees session.user exists at this point
const user = session.user;
@@ -104,6 +108,17 @@ export function AuthenticatedLayout({
return null;
}
+ const regionMenuItems = getAvailableCloudRegionOptions(currentRegion).map(
+ (region) => ({
+ name: region.name,
+ content: `${region.flag} ${region.name}`,
+ onClick: () => {
+ if (!region.rootUrl) return;
+ window.open(region.rootUrl, "_blank", "noopener,noreferrer");
+ },
+ }),
+ );
+
// User navigation items for sidebar dropdown
const userNavProps = {
user: {
@@ -114,6 +129,22 @@ export function AuthenticatedLayout({
items: [
{ name: "Account Settings", href: "/account/settings" },
{ name: "Theme", onClick: () => {}, content: <ThemeToggle /> },
+ ...(isLangfuseCloud
+ ? [
+ {
+ name: "Regions",
+ subItems: regionMenuItems,
+ content: (
+ <>
+ Regions
+ <div className="ml-2 inline-flex rounded bg-black/5 p-1 text-xs dark:bg-white/10">
+ Current: {currentRegion}
+ </div>
+ </>
+ ),
+ },
+ ]
+ : []),
{ name: "Sign out", onClick: onSignOut },
],
};
diff --git a/web/src/components/nav/nav-user.tsx b/web/src/components/nav/nav-user.tsx
index 202c0129c2..7f265ed592 100644
--- a/web/src/components/nav/nav-user.tsx
+++ b/web/src/components/nav/nav-user.tsx
@@ -15,6 +15,9 @@ import {
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
+ DropdownMenuSub,
+ DropdownMenuSubContent,
+ DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from "@/src/components/ui/dropdown-menu";
import {
@@ -29,6 +32,7 @@ export type UserNavigationItem = {
onClick?: () => void;
content?: React.ReactNode;
href?: string;
+ subItems?: UserNavigationItem[];
};
export type UserNavigationProps = {
@@ -50,6 +54,35 @@ export function NavUser({ user, items }: UserNavigationProps) {
.join("")
.toUpperCase();
+ const renderMenuItem = (item: UserNavigationItem) => {
+ if (item.subItems?.length) {
+ return (
+ <DropdownMenuSub key={item.name}>
+ <DropdownMenuSubTrigger>
+ {item.content ?? item.name}
+ </DropdownMenuSubTrigger>
+ <DropdownMenuSubContent>
+ {item.subItems.map(renderMenuItem)}
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ );
+ }
+
+ if (item.href) {
+ return (
+ <DropdownMenuItem key={item.name} asChild>
+ <Link href={item.href}>{item.content ?? item.name}</Link>
+ </DropdownMenuItem>
+ );
+ }
+
+ return (
+ <DropdownMenuItem key={item.name} onClick={item.onClick}>
+ {item.content ?? item.name}
+ </DropdownMenuItem>
+ );
+ };
+
return (
<SidebarMenu>
<SidebarMenuItem>
@@ -97,19 +130,7 @@ export function NavUser({ user, items }: UserNavigationProps) {
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
- <DropdownMenuGroup>
- {items.map((item) =>
- item.href ? (
- <DropdownMenuItem key={item.name} asChild>
- <Link href={item.href}>{item.content ?? item.name}</Link>
- </DropdownMenuItem>
- ) : (
- <DropdownMenuItem key={item.name} onClick={item.onClick}>
- {item.content ?? item.name}
- </DropdownMenuItem>
- ),
- )}
- </DropdownMenuGroup>
+ <DropdownMenuGroup>{items.map(renderMenuItem)}</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
diff --git a/web/src/features/auth/components/AuthCloudRegionSwitch.tsx b/web/src/features/auth/components/AuthCloudRegionSwitch.tsx
index 67174c8fb3..44c0b80e17 100644
--- a/web/src/features/auth/components/AuthCloudRegionSwitch.tsx
+++ b/web/src/features/auth/components/AuthCloudRegionSwitch.tsx
@@ -17,64 +17,7 @@ import {
DialogTrigger,
} from "@/src/components/ui/dialog";
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
-
-const regions =
- env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "STAGING"
- ? [
- {
- name: "STAGING",
- hostname: "staging.langfuse.com",
- flag: "πŸ‡ͺπŸ‡Ί",
- },
- ]
- : env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "DEV"
- ? [
- {
- name: "DEV",
- hostname: null,
- flag: "🚧",
- },
- ]
- : env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION === "JP"
- ? [
- {
- name: "JP",
- hostname: "jp.cloud.langfuse.com",
- flag: "οΈπŸ‡―πŸ‡΅",
- },
- {
- name: "US",
- hostname: "us.cloud.langfuse.com",
- flag: "πŸ‡ΊπŸ‡Έ",
- },
- {
- name: "EU",
- hostname: "cloud.langfuse.com",
- flag: "πŸ‡ͺπŸ‡Ί",
- },
- {
- name: "HIPAA",
- hostname: "hipaa.cloud.langfuse.com",
- flag: "βš•οΈ",
- },
- ]
- : [
- {
- name: "US",
- hostname: "us.cloud.langfuse.com",
- flag: "πŸ‡ΊπŸ‡Έ",
- },
- {
- name: "EU",
- hostname: "cloud.langfuse.com",
- flag: "πŸ‡ͺπŸ‡Ί",
- },
- {
- name: "HIPAA",
- hostname: "hipaa.cloud.langfuse.com",
- flag: "βš•οΈ",
- },
- ];
+import { getAvailableCloudRegionOptions } from "@/src/features/organizations/cloudRegions";
export function CloudRegionSwitch({
isSignUpPage,
@@ -83,6 +26,9 @@ export function CloudRegionSwitch({
}) {
const capture = usePostHogClientCapture();
const { isLangfuseCloud, region: cloudRegion } = useLangfuseCloudRegion();
+ const regions = getAvailableCloudRegionOptions(
+ env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION ?? cloudRegion,
+ );
if (!isLangfuseCloud) return null;
diff --git a/web/src/features/organizations/cloudRegions.ts b/web/src/features/organizations/cloudRegions.ts
new file mode 100644
index 0000000000..acb3675e16
--- /dev/null
+++ b/web/src/features/organizations/cloudRegions.ts
@@ -0,0 +1,81 @@
+const cloudRegions = [
+ {
+ name: "DEV",
+ flag: "🚧",
+ hostname: null,
+ rootUrl: null,
+ isProduction: false,
+ },
+ {
+ name: "STAGING",
+ flag: "πŸ‡ͺπŸ‡Ί",
+ hostname: "staging.langfuse.com",
+ rootUrl: "https://staging.langfuse.com",
+ isProduction: false,
+ },
+ {
+ name: "EU",
+ flag: "πŸ‡ͺπŸ‡Ί",
+ hostname: "cloud.langfuse.com",
+ rootUrl: "https://cloud.langfuse.com",
+ isProduction: true,
+ },
+ {
+ name: "US",
+ flag: "πŸ‡ΊπŸ‡Έ",
+ hostname: "us.cloud.langfuse.com",
+ rootUrl: "https://us.cloud.langfuse.com",
+ isProduction: true,
+ },
+ {
+ name: "JP",
+ flag: "πŸ‡―πŸ‡΅",
+ hostname: "jp.cloud.langfuse.com",
+ rootUrl: "https://jp.cloud.langfuse.com",
+ isProduction: true,
+ },
+ {
+ name: "HIPAA",
+ flag: "βš•οΈ",
+ hostname: "hipaa.cloud.langfuse.com",
+ rootUrl: "https://hipaa.cloud.langfuse.com",
+ isProduction: true,
+ },
+] as const;
+
+const availableRegionsByCurrentRegion = {
+ STAGING: ["STAGING"],
+ DEV: ["DEV"],
+ JP: ["JP", "US", "EU", "HIPAA"],
+ default: ["US", "EU", "HIPAA"],
+} as const;
+
+const getCloudRegion = (name: (typeof cloudRegions)[number]["name"]) => {
+ const region = cloudRegions.find((region) => region.name === name);
+ if (!region) {
+ throw new Error(`Unknown cloud region: ${name}`);
+ }
+
+ return region;
+};
+
+export const getAvailableCloudRegionOptions = (currentRegion?: string) => {
+ if (currentRegion === "STAGING") {
+ return availableRegionsByCurrentRegion.STAGING.map(getCloudRegion);
+ }
+
+ if (currentRegion === "DEV") {
+ return availableRegionsByCurrentRegion.DEV.map(getCloudRegion);
+ }
+
+ if (currentRegion === "JP") {
+ return availableRegionsByCurrentRegion.JP.map(getCloudRegion);
+ }
+
+ return availableRegionsByCurrentRegion.default.map(getCloudRegion);
+};
+
+export const isRegionProduction = (regionName: string): boolean => {
+ const region = cloudRegions.find((r) => r.name === regionName);
+ return region ? region.isProduction : false;
+};