Skip to content

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

refactor: remove PagerDuty Langfuse Cloud admin restriction (#19584)

Mark Salpeter0ca8994b00d4
diff --git a/web/src/__tests__/server/automations-trpc.servertest.ts b/web/src/__tests__/server/automations-trpc.servertest.ts
index aa0c381159..746dc2a1e1 100644
--- a/web/src/__tests__/server/automations-trpc.servertest.ts
+++ b/web/src/__tests__/server/automations-trpc.servertest.ts
@@ -24,7 +24,6 @@ import {
} from "@langfuse/shared/encryption";
import { TRPCError } from "@trpc/server";
import { type MockInstance } from "vitest";
-import { env } from "@/src/env.mjs";
// Fake Slack workspace: the bot is in private channels "G_PRIVATE" and archived
// "G_ARCHIVED". Slack API calls are faked; the access logic is real.
@@ -3392,17 +3391,6 @@ describe("automations trpc", () => {
describe("PagerDuty actions", () => {
const routingKey = "R0abcdefghijklmnopqrstuvwxyz9xYz";
const newRoutingKey = "N3wkeyabcdefghijklmnopqrstuv7uVw";
- const mutableEnv = env as { NEXT_PUBLIC_LANGFUSE_CLOUD_REGION?: string };
- const originalCloudRegion = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;
-
- beforeAll(() => {
- mutableEnv.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "STAGING";
- });
-
- afterAll(() => {
- mutableEnv.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = originalCloudRegion;
- });
-
const createInput = (
projectId: string,
actionConfig: {
@@ -3482,34 +3470,15 @@ describe("automations trpc", () => {
});
}
- it("rejects users who are not Langfuse Cloud admins", async () => {
+ it("lets project owners who are not admins create PagerDuty automations", async () => {
const { project, session } = await prepare();
const owner = callerWithUser(session, { admin: false });
- await expect(
- owner.automations.createAutomation(createInput(project.id)),
- ).rejects.toMatchObject({ code: "FORBIDDEN" });
- await expect(
- owner.automations.sendPagerDutyTestEvent({
- projectId: project.id,
- region: "US",
- routingKey,
- step: "trigger",
- }),
- ).rejects.toMatchObject({ code: "FORBIDDEN" });
- });
-
- it("rejects admins on self-hosted instances", async () => {
- const { project, caller } = await prepare();
- mutableEnv.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = undefined;
+ const result = await owner.automations.createAutomation(
+ createInput(project.id),
+ );
- try {
- await expect(
- caller.automations.createAutomation(createInput(project.id)),
- ).rejects.toMatchObject({ code: "FORBIDDEN" });
- } finally {
- mutableEnv.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "STAGING";
- }
+ expect(result.action.type).toBe("PAGERDUTY");
});
it("rejects a create without a routing key", async () => {
diff --git a/web/src/features/automations/components/AutomationForm.tsx b/web/src/features/automations/components/AutomationForm.tsx
index d4bad69f7d..2dd456b0f0 100644
--- a/web/src/features/automations/components/AutomationForm.tsx
+++ b/web/src/features/automations/components/AutomationForm.tsx
@@ -54,7 +54,6 @@ import { useLangfuseCloudRegion } from "@/src/features/organizations";
import { useHasProjectAccess } from "@/src/features/rbac";
import { ActionHandlerRegistry } from "./actions";
import { actionTypeLabel } from "@/src/features/automations/actionTypeLabels";
-import { useAvailableActionTypes } from "@/src/features/automations/useAvailableActionTypes";
import { webhookSchema } from "./actions/WebhookActionForm";
import { Alert } from "@/src/components/design-system/Alert/Alert";
import Link from "next/link";
@@ -417,9 +416,8 @@ export const AutomationForm = ({
projectId,
scope: "automations:CUD",
});
- const availableActionTypes = useAvailableActionTypes(
- allowedActionTypes ?? ActionHandlerRegistry.getAllActionTypes(),
- );
+ const availableActionTypes =
+ allowedActionTypes ?? ActionHandlerRegistry.getAllActionTypes();
const utils = api.useUtils();
diff --git a/web/src/features/automations/index.ts b/web/src/features/automations/index.ts
index 40bc058324..9abe09559d 100644
--- a/web/src/features/automations/index.ts
+++ b/web/src/features/automations/index.ts
@@ -6,5 +6,4 @@
export { AutomationButton } from "@/src/features/automations/components/AutomationButton";
export { AutomationForm } from "@/src/features/automations/components/AutomationForm";
export { actionTypeLabel } from "@/src/features/automations/actionTypeLabels";
-export { useAvailableActionTypes } from "@/src/features/automations/useAvailableActionTypes";
export { WebhookSecretRender } from "@/src/features/automations/components/WebhookSecretRender";
diff --git a/web/src/features/automations/server/router.ts b/web/src/features/automations/server/router.ts
index 695c2346df..7e9901eeb9 100644
--- a/web/src/features/automations/server/router.ts
+++ b/web/src/features/automations/server/router.ts
@@ -35,7 +35,6 @@ import { processGitHubDispatchActionConfig } from "./githubDispatchHelpers";
import {
processPagerDutyActionConfig,
sendPagerDutyTestEvent,
- throwIfPagerDutyUnavailable,
} from "@/src/features/pagerduty/server";
import { maskActionForViewer, processSlackActionConfig } from "./slackHelpers";
import { updateTriggerEventActions } from "./automationService";
@@ -340,7 +339,6 @@ export const automationsRouter = createTRPCRouter({
finalActionConfig = githubResult.finalActionConfig;
newUnencryptedWebhookSecret = githubResult.githubToken;
} else if (input.actionType === "PAGERDUTY") {
- throwIfPagerDutyUnavailable(ctx.session);
finalActionConfig = await processPagerDutyActionConfig({
actionConfig: input.actionConfig,
projectId: input.projectId,
@@ -457,7 +455,6 @@ export const automationsRouter = createTRPCRouter({
});
finalActionConfig = githubResult.finalActionConfig;
} else if (input.actionType === "PAGERDUTY") {
- throwIfPagerDutyUnavailable(ctx.session);
finalActionConfig = await processPagerDutyActionConfig({
actionConfig: input.actionConfig,
actionId: existingAutomation.action.id,
@@ -691,7 +688,6 @@ export const automationsRouter = createTRPCRouter({
scope: "automations:CUD",
});
- throwIfPagerDutyUnavailable(ctx.session);
await sendPagerDutyTestEvent(input);
if (input.actionId) {
diff --git a/web/src/features/automations/useAvailableActionTypes.ts b/web/src/features/automations/useAvailableActionTypes.ts
deleted file mode 100644
index f58ab7e22b..0000000000
--- a/web/src/features/automations/useAvailableActionTypes.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { useSession } from "next-auth/react";
-
-import { type ActionTypes } from "@langfuse/shared";
-import { useLangfuseCloudRegion } from "@/src/features/organizations";
-
-const cloudAdminActionTypes: readonly ActionTypes[] = ["PAGERDUTY"];
-
-/** useAvailableActionTypes drops action types limited to Langfuse Cloud admins for everyone else. */
-export function useAvailableActionTypes(
- actionTypes: readonly ActionTypes[],
-): ActionTypes[] {
- const session = useSession();
- const { isLangfuseCloud } = useLangfuseCloudRegion();
- if (isLangfuseCloud && session.data?.user?.admin === true) {
- return [...actionTypes];
- }
- return actionTypes.filter(
- (actionType) => !cloudAdminActionTypes.includes(actionType),
- );
-}
diff --git a/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.clienttest.tsx b/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.clienttest.tsx
index c95e9d51fe..83c0516966 100644
--- a/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.clienttest.tsx
+++ b/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.clienttest.tsx
@@ -24,9 +24,6 @@ vi.mock("@/src/utils/api", () => ({
},
},
}));
-vi.mock("@/src/features/automations", () => ({
- useAvailableActionTypes: (types: string[]) => types,
-}));
vi.mock("@/src/features/pagerduty", () => ({
usePagerDutyTestEvent: () => ({}),
}));
diff --git a/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.tsx b/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.tsx
index 0f11966253..b7d4617cd2 100644
--- a/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.tsx
+++ b/web/src/features/monitors/automations/ConnectedNewMonitorAutomationDialog.tsx
@@ -1,5 +1,4 @@
import { type ActionTypes } from "@langfuse/shared";
-import { useAvailableActionTypes } from "@/src/features/automations";
import { usePagerDutyTestEvent } from "@/src/features/pagerduty";
import { useHasProjectAccess } from "@/src/features/rbac";
import {
@@ -33,7 +32,6 @@ export function ConnectedNewMonitorAutomationDialog({
lockedActionType?: ActionTypes;
onCreated: (automation: CreatedMonitorAutomation) => void;
}) {
- const availableActionTypes = useAvailableActionTypes(monitorActionTypes);
const slack = useSlackFieldsState(projectId);
const pagerDuty = usePagerDutyTestEvent(projectId);
const createAutomation = useCreateMonitorAutomation();
@@ -41,7 +39,7 @@ export function ConnectedNewMonitorAutomationDialog({
return (
<NewMonitorAutomationDialog
- actionTypes={offeredActionTypes(lockedActionType, availableActionTypes)}
+ actionTypes={offeredActionTypes(lockedActionType)}
slack={slack}
pagerDuty={pagerDuty}
isSubmitting={createAutomation.isPending}
@@ -133,10 +131,9 @@ function useSubmit(
/** offeredActionTypes limits the dialog to the locked action, if there is one. */
function offeredActionTypes(
lockedActionType: ActionTypes | undefined,
- availableActionTypes: ActionTypes[],
): ActionTypes[] {
if (lockedActionType) return [lockedActionType];
- return availableActionTypes;
+ return [...monitorActionTypes];
}
/** rejectionMessage is the reason the server gave for refusing the automation. */
diff --git a/web/src/features/monitors/components/MonitorAutomationsPanel.tsx b/web/src/features/monitors/components/MonitorAutomationsPanel.tsx
index 25b450d8fe..37fa122d69 100644
--- a/web/src/features/monitors/components/MonitorAutomationsPanel.tsx
+++ b/web/src/features/monitors/components/MonitorAutomationsPanel.tsx
@@ -13,10 +13,7 @@ import { api } from "@/src/utils/api";
import { Button } from "@/src/components/ui/button";
import { Card, CardContent } from "@/src/components/ui/card";
import { DropdownMenu } from "@/src/components/design-system/DropdownMenu/DropdownMenu";
-import {
- actionTypeLabel,
- useAvailableActionTypes,
-} from "@/src/features/automations";
+import { actionTypeLabel } from "@/src/features/automations";
import { NewMonitorAutomationDialogController } from "@/src/features/monitors/automations/NewMonitorAutomationDialogController";
import { cn } from "@/src/utils/tailwind";
import {
@@ -252,7 +249,7 @@ const AddAutomationDropdown = ({
isDisabled?: boolean;
onAutomationCreated: (automationId: string) => void;
}) => {
- const actionTypes = useAvailableActionTypes(ActionTypeSchema.options);
+ const actionTypes = ActionTypeSchema.options;
return (
<NewMonitorAutomationDialogController
diff --git a/web/src/features/monitors/components/MonitorsOnboarding.clienttest.tsx b/web/src/features/monitors/components/MonitorsOnboarding.clienttest.tsx
index fb954e7d5a..102bfafa27 100644
--- a/web/src/features/monitors/components/MonitorsOnboarding.clienttest.tsx
+++ b/web/src/features/monitors/components/MonitorsOnboarding.clienttest.tsx
@@ -2,7 +2,6 @@ import { fireEvent, render, screen } from "@testing-library/react";
import { type Session } from "next-auth";
-import type * as EnvModule from "@/src/env.mjs";
import { MonitorsOnboarding } from "./MonitorsOnboarding";
vi.mock(
@@ -20,28 +19,12 @@ const sessionMock = vi.hoisted(() => ({ data: null as Session | null }));
vi.mock("next-auth/react", () => ({
useSession: () => ({ data: sessionMock.data, status: "authenticated" }),
}));
-const cloudRegion = vi.hoisted(() => ({
- value: undefined as string | undefined,
-}));
-vi.mock("@/src/env.mjs", async (importOriginal) => {
- const actual = await importOriginal<typeof EnvModule>();
- return {
- env: new Proxy(actual.env, {
- get: (target, key) =>
- key === "NEXT_PUBLIC_LANGFUSE_CLOUD_REGION"
- ? cloudRegion.value
- : Reflect.get(target, key),
- }),
- };
-});
-
-/** signIn sets the session user's admin flag and the deployment's Cloud region. */
-const signIn = ({ admin, region }: { admin: boolean; region?: string }) => {
+/** signIn sets the session user's admin flag. */
+const signIn = ({ admin }: { admin: boolean }) => {
sessionMock.data = {
expires: "1",
user: { admin, organizations: [] },
} as unknown as Session;
- cloudRegion.value = region;
};
const PROJECT_ID = "proj_test123";
@@ -49,7 +32,6 @@ const PROJECT_ID = "proj_test123";
describe("MonitorsOnboarding", () => {
afterEach(() => {
sessionMock.data = null;
- cloudRegion.value = undefined;
});
it("renders the splash header, step titles, and four CTAs", () => {
@@ -105,28 +87,10 @@ describe("MonitorsOnboarding", () => {
).toBeDisabled();
});
- it("hides the PagerDuty CTA from users who are not admins", () => {
- signIn({ admin: false, region: "EU" });
- render(<MonitorsOnboarding projectId={PROJECT_ID} hasCUDAccess={true} />);
-
- expect(
- screen.queryByRole("button", { name: /Connect PagerDuty/i }),
- ).not.toBeInTheDocument();
- });
-
- it("hides the PagerDuty CTA from admins on self-hosted instances", () => {
+ it("shows the PagerDuty CTA without a Langfuse Cloud region", () => {
signIn({ admin: true });
render(<MonitorsOnboarding projectId={PROJECT_ID} hasCUDAccess={true} />);
- expect(
- screen.queryByRole("button", { name: /Connect PagerDuty/i }),
- ).not.toBeInTheDocument();
- });
-
- it("shows the PagerDuty CTA to Langfuse Cloud admins", () => {
- signIn({ admin: true, region: "EU" });
- render(<MonitorsOnboarding projectId={PROJECT_ID} hasCUDAccess={true} />);
-
const button = screen.getByRole("button", { name: /Connect PagerDuty/i });
expect(button).not.toHaveTextContent("Internal");
fireEvent.click(button);
diff --git a/web/src/features/monitors/components/MonitorsOnboarding.tsx b/web/src/features/monitors/components/MonitorsOnboarding.tsx
index 2a52140386..b5e2876793 100644
--- a/web/src/features/monitors/components/MonitorsOnboarding.tsx
+++ b/web/src/features/monitors/components/MonitorsOnboarding.tsx
@@ -5,7 +5,6 @@ import { DropdownIndicator } from "@/src/components/design-system/DropdownIndica
import { ActionButton } from "@/src/components/ActionButton";
import { Button } from "@/src/components/ui/button";
import { SplashScreen } from "@/src/components/ui/SplashScreen";
-import { useAvailableActionTypes } from "@/src/features/automations";
import { NewMonitorAutomationDialogController } from "@/src/features/monitors/automations/NewMonitorAutomationDialogController";
import { useHasProjectAccess } from "@/src/features/rbac";
import { type ActionTypes } from "@langfuse/shared";
@@ -49,13 +48,6 @@ export function MonitorsOnboarding({
projectId: string;
hasCUDAccess: boolean;
}) {
- const actionTypes = useAvailableActionTypes(
- channels.map((channel) => channel.actionType),
- );
- const visibleChannels = channels.filter((channel) =>
- actionTypes.includes(channel.actionType),
- );
-
return (
<div className="mx-auto w-full max-w-xl pt-12">
<SplashScreen
@@ -64,12 +56,10 @@ export function MonitorsOnboarding({
steps={[
{
title: "Choose where alerts should go",
- description: channelsDescription(actionTypes),
+ description:
+ "Send alerts to Slack, Webhooks, GitHub Actions, or PagerDuty so your team and your workflows can respond automatically.",
content: (
- <ChannelButtons
- projectId={projectId}
- channels={visibleChannels}
- />
+ <ChannelButtons projectId={projectId} channels={channels} />
),
},
{
@@ -132,11 +122,3 @@ function ChannelButtons({
</NewMonitorAutomationDialogController>
);
}
-
-/** channelsDescription names the channels the user can connect. */
-function channelsDescription(actionTypes: ActionTypes[]): string {
- if (actionTypes.includes("PAGERDUTY")) {
- return "Send alerts to Slack, Webhooks, GitHub Actions, or PagerDuty so your team and your workflows can respond automatically.";
- }
- return "Send alerts to Slack, Webhooks, or GitHub Actions so your team and your workflows can respond automatically.";
-}
diff --git a/web/src/features/pagerduty/server/index.ts b/web/src/features/pagerduty/server/index.ts
index 715b232bd2..81b6a95608 100644
--- a/web/src/features/pagerduty/server/index.ts
+++ b/web/src/features/pagerduty/server/index.ts
@@ -1,5 +1,4 @@
export {
processPagerDutyActionConfig,
sendPagerDutyTestEvent,
- throwIfPagerDutyUnavailable,
} from "@/src/features/pagerduty/server/pagerdutyHelpers";
diff --git a/web/src/features/pagerduty/server/pagerdutyHelpers.ts b/web/src/features/pagerduty/server/pagerdutyHelpers.ts
index 9c232eae77..f56bd87bd8 100644
--- a/web/src/features/pagerduty/server/pagerdutyHelpers.ts
+++ b/web/src/features/pagerduty/server/pagerdutyHelpers.ts
@@ -1,7 +1,5 @@
-import { type Session } from "next-auth";
import {
BaseError,
- ForbiddenError,
InvalidRequestError,
isPagerDutyActionConfig,
type ActionCreate,
@@ -18,14 +16,6 @@ import {
type PagerDutyTestEventStep,
} from "@langfuse/shared/pagerduty/server";
import { getProductBaseUrl, logger } from "@langfuse/shared/src/server";
-import { env } from "@/src/env.mjs";
-
-/** throwIfPagerDutyUnavailable limits PagerDuty actions to Langfuse Cloud admins. */
-export function throwIfPagerDutyUnavailable(session: Session): void {
- if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION && session.user?.admin === true)
- return;
- throw new ForbiddenError("PagerDuty actions are not available yet");
-}
/** processPagerDutyActionConfig encrypts a new routing key, or keeps the stored one when the update omits it. */
export async function processPagerDutyActionConfig({