Skip to content

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

feat(web): offer export sources by deployment capability, not per-user beta (#16149)

Niklas Semmlerc42d3b76b925
diff --git a/web/src/features/analytics-integrations/exportSource.clienttest.ts b/web/src/features/analytics-integrations/exportSource.clienttest.ts
index 8bef098932..6bbd6d9590 100644
--- a/web/src/features/analytics-integrations/exportSource.clienttest.ts
+++ b/web/src/features/analytics-integrations/exportSource.clienttest.ts
@@ -8,6 +8,7 @@ import {
import {
buildExportSourceContext,
+ getExportSourceFieldState,
getExportSourceFormValue,
getExportSourceOptions,
getExportSourceUnavailableMessage,
@@ -402,6 +403,123 @@ describe("write mode drives the settings-page selector", () => {
);
});
+// The pages consume only this composite, so the pieces being correct
+// individually is not enough — visibility and the default must agree.
+describe("getExportSourceFieldState", () => {
+ const ctxFor = (
+ writeMode: BlobExportWriteMode,
+ over: Partial<
+ Omit<ExportSourceContext, "enrichedAvailable" | "legacyWritesActive">
+ > = {},
+ ): ExportSourceContext =>
+ buildExportSourceContext({ writeMode, isCloud: false, ...over });
+
+ it.each<BlobExportWriteMode>(["legacy", "dual", "events_only"])(
+ "%s: a hidden selector always leaves a selectable default",
+ (mode) => {
+ const ctx = ctxFor(mode);
+ const { showField, defaultValue } = getExportSourceFieldState(
+ undefined,
+ ctx,
+ );
+ if (!showField) {
+ expect(isExportSourceSelectable(defaultValue, ctx)).toBe(true);
+ }
+ },
+ );
+
+ it("dual offers the choice, with the events source defaulted", () => {
+ const { showField, defaultValue, options } = getExportSourceFieldState(
+ undefined,
+ ctxFor("dual"),
+ );
+ expect(showField).toBe(true);
+ expect(options).toHaveLength(3);
+ expect(defaultValue).toBe(AnalyticsIntegrationExportSource.EVENTS);
+ });
+
+ it.each<[BlobExportWriteMode, AnalyticsIntegrationExportSource]>([
+ ["legacy", AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS],
+ ["events_only", AnalyticsIntegrationExportSource.EVENTS],
+ ])("%s hides the selector and defaults to %s", (mode, expected) => {
+ const { showField, defaultValue } = getExportSourceFieldState(
+ undefined,
+ ctxFor(mode),
+ );
+ expect(showField).toBe(false);
+ expect(defaultValue).toBe(expected);
+ });
+
+ // Kept as the default even though unselectable: the blocked-save alert
+ // names it.
+ it("keeps the selector for a persisted source the deployment can no longer write", () => {
+ const ctx = ctxFor("events_only");
+ const { showField, defaultValue } = getExportSourceFieldState(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ ctx,
+ );
+ expect(showField).toBe(true);
+ expect(defaultValue).toBe(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ );
+ expect(isExportSourceSelectable(defaultValue, ctx)).toBe(false);
+ });
+
+ it("post-cutoff Cloud leaves only the events source to offer", () => {
+ const { showField, defaultValue } = getExportSourceFieldState(
+ undefined,
+ ctxFor("dual", {
+ isCloud: true,
+ projectCreatedAt: PROJECT_POST,
+ integrationCreatedAt: ROW_PRE,
+ }),
+ );
+ expect(showField).toBe(false);
+ expect(defaultValue).toBe(AnalyticsIntegrationExportSource.EVENTS);
+ });
+
+ // The cutoff gates newly chosen sources only. Hiding the field and pinning
+ // the events source instead would rewrite a persisted legacy source on the
+ // next save of any other field on the page.
+ it("post-cutoff Cloud keeps a persisted legacy source visible and blocked", () => {
+ const ctx = ctxFor("dual", {
+ isCloud: true,
+ projectCreatedAt: PROJECT_POST,
+ integrationCreatedAt: ROW_PRE,
+ });
+ const { showField, defaultValue, options } = getExportSourceFieldState(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ ctx,
+ );
+ expect(showField).toBe(true);
+ expect(defaultValue).toBe(
+ AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
+ );
+ expect(isExportSourceSelectable(defaultValue, ctx)).toBe(false);
+ expect(options.find((o) => o.value === defaultValue)?.unavailable).toBe(
+ true,
+ );
+ });
+
+ // Pre-cutoff projects are exempt from the cutoff, leaving only the write
+ // mode.
+ it.each<BlobExportWriteMode>(["legacy", "dual", "events_only"])(
+ "%s: pre-cutoff Cloud matches self-hosted",
+ (mode) => {
+ expect(
+ getExportSourceFieldState(
+ undefined,
+ ctxFor(mode, {
+ isCloud: true,
+ projectCreatedAt: PROJECT_PRE,
+ integrationCreatedAt: ROW_PRE,
+ }),
+ ),
+ ).toEqual(getExportSourceFieldState(undefined, ctxFor(mode)));
+ },
+ );
+});
+
describe("getExportSourceUnavailableMessage", () => {
it("names the write mode for enriched-unavailable (self-hosted operator-facing)", () => {
const message = getExportSourceUnavailableMessage("enriched-unavailable");
diff --git a/web/src/features/analytics-integrations/exportSource.ts b/web/src/features/analytics-integrations/exportSource.ts
index d60f7e4349..b8b9f32d25 100644
--- a/web/src/features/analytics-integrations/exportSource.ts
+++ b/web/src/features/analytics-integrations/exportSource.ts
@@ -89,6 +89,29 @@ export function getExportSourceOptions(
});
}
+export type ExportSourceFieldState = {
+ options: SelectableExportSourceOption[];
+ showField: boolean;
+ defaultValue: AnalyticsIntegrationExportSource;
+};
+
+// Visibility and the default have to agree: a hidden selector whose default is
+// not selectable blocks every save with no field left to fix it with. Both
+// therefore derive from the same option list, with no per-context override —
+// the persisted value survives even where it can no longer be chosen, so the
+// blocked-save alert names it instead of a save quietly replacing it.
+export function getExportSourceFieldState(
+ persisted: AnalyticsIntegrationExportSource | null | undefined,
+ ctx: ExportSourceContext,
+): ExportSourceFieldState {
+ const options = getExportSourceOptions(persisted ?? null, ctx);
+ return {
+ options,
+ showField: !shouldHideExportSourceSelector(options),
+ defaultValue: getExportSourceFormValue(persisted, ctx),
+ };
+}
+
// Blocked-save alert body per policy reason.
const EXPORT_SOURCE_UNAVAILABLE_MESSAGES: Record<
ExportSourceBlockedReason,
diff --git a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx
index a77d485b84..adc51ede0c 100644
--- a/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx
+++ b/web/src/pages/project/[projectId]/settings/integrations/mixpanel.tsx
@@ -33,7 +33,6 @@ import {
type MixpanelRegion,
} from "@/src/features/mixpanel-integration/types";
import {
- AnalyticsIntegrationExportSource,
validateExportSource,
type BlobExportWriteMode,
type ExportSourceContext,
@@ -42,12 +41,10 @@ import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
// Shared export-source UI adapters; policy in export-source-policy.ts.
import {
buildExportSourceContext,
- getExportSourceOptions,
+ getExportSourceFieldState,
getExportSourceUnavailableMessage,
isExportSourceSelectable,
- shouldHideExportSourceSelector,
} from "@/src/features/analytics-integrations/exportSource";
-import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { useQueryProject } from "@/src/features/projects/hooks";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
@@ -171,7 +168,6 @@ const MixpanelIntegrationSettingsForm = ({
projectCreatedAt: string;
}) => {
const capture = usePostHogClientCapture();
- const { isBetaEnabled } = useV4Beta();
const { isLangfuseCloud } = useLangfuseCloudRegion();
const exportSourceCtx: ExportSourceContext = useMemo(
() =>
@@ -182,27 +178,11 @@ const MixpanelIntegrationSettingsForm = ({
}),
[writeMode, isLangfuseCloud, projectCreatedAt],
);
- const legacyValidation = validateExportSource(
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
- exportSourceCtx,
- );
- // Post-cutoff Cloud projects: field hidden, form value pinned to EVENTS via
- // the default below (LFE-9688 / 9830 behavior, unchanged).
- const isPostCutoffCloud =
- !legacyValidation.ok && legacyValidation.reason === "cloud-cutoff";
- const exportSourceOptions = getExportSourceOptions(
- state?.exportSource ?? null,
- exportSourceCtx,
- );
- // Selector is beta-gated, except a persisted source blocked by capability
- // forces it visible so the blocked-save alert has something to point at.
- const persistedBlockedByCapability =
- state?.exportSource != null &&
- !isPostCutoffCloud &&
- !isExportSourceSelectable(state.exportSource, exportSourceCtx);
- const showExportSourceField =
- ((isBetaEnabled && !isPostCutoffCloud) || persistedBlockedByCapability) &&
- !shouldHideExportSourceSelector(exportSourceOptions);
+ const {
+ options: exportSourceOptions,
+ showField: showExportSourceField,
+ defaultValue: defaultExportSource,
+ } = getExportSourceFieldState(state?.exportSource, exportSourceCtx);
// Blocked-save validation instead of silent rewrite (LFE-10296).
const formSchema = useMemo(
@@ -229,13 +209,6 @@ const MixpanelIntegrationSettingsForm = ({
[exportSourceCtx, state],
);
- const defaultExportSource = isPostCutoffCloud
- ? AnalyticsIntegrationExportSource.EVENTS
- : (state?.exportSource ??
- (isBetaEnabled || !exportSourceCtx.legacyWritesActive
- ? AnalyticsIntegrationExportSource.EVENTS
- : AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS));
-
const mixpanelForm = useForm({
resolver: zodResolver(formSchema),
defaultValues: {
diff --git a/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx b/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx
index aded193d25..8c72160612 100644
--- a/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx
+++ b/web/src/pages/project/[projectId]/settings/integrations/posthog.tsx
@@ -31,7 +31,6 @@ import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePos
import { posthogIntegrationFormSchema } from "@/src/features/posthog-integration/types";
import { PostHogStatusSection } from "@/src/features/posthog-integration/components/PostHogStatusSection";
import {
- AnalyticsIntegrationExportSource,
validateExportSource,
type BlobExportWriteMode,
type ExportSourceContext,
@@ -40,12 +39,10 @@ import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert";
// Shared export-source UI adapters; policy in export-source-policy.ts.
import {
buildExportSourceContext,
- getExportSourceOptions,
+ getExportSourceFieldState,
getExportSourceUnavailableMessage,
isExportSourceSelectable,
- shouldHideExportSourceSelector,
} from "@/src/features/analytics-integrations/exportSource";
-import { useV4Beta } from "@/src/features/events/hooks/useV4Beta";
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { useQueryProject } from "@/src/features/projects/hooks";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
@@ -165,7 +162,6 @@ const PostHogIntegrationSettings = ({
projectCreatedAt: string;
}) => {
const capture = usePostHogClientCapture();
- const { isBetaEnabled } = useV4Beta();
const { isLangfuseCloud } = useLangfuseCloudRegion();
const exportSourceCtx: ExportSourceContext = useMemo(
() =>
@@ -176,27 +172,11 @@ const PostHogIntegrationSettings = ({
}),
[writeMode, isLangfuseCloud, projectCreatedAt],
);
- const legacyValidation = validateExportSource(
- AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS,
- exportSourceCtx,
- );
- // Post-cutoff Cloud projects: field hidden, form value pinned to EVENTS via
- // the default below (LFE-9688 / 9830 behavior, unchanged).
- const isPostCutoffCloud =
- !legacyValidation.ok && legacyValidation.reason === "cloud-cutoff";
- const exportSourceOptions = getExportSourceOptions(
- state?.exportSource ?? null,
- exportSourceCtx,
- );
- // Selector is beta-gated, except a persisted source blocked by capability
- // forces it visible so the blocked-save alert has something to point at.
- const persistedBlockedByCapability =
- state?.exportSource != null &&
- !isPostCutoffCloud &&
- !isExportSourceSelectable(state.exportSource, exportSourceCtx);
- const showExportSourceField =
- ((isBetaEnabled && !isPostCutoffCloud) || persistedBlockedByCapability) &&
- !shouldHideExportSourceSelector(exportSourceOptions);
+ const {
+ options: exportSourceOptions,
+ showField: showExportSourceField,
+ defaultValue: defaultExportSource,
+ } = getExportSourceFieldState(state?.exportSource, exportSourceCtx);
// Blocked-save validation instead of silent rewrite (LFE-10296).
const formSchema = useMemo(
@@ -223,13 +203,6 @@ const PostHogIntegrationSettings = ({
[exportSourceCtx, state],
);
- const defaultExportSource = isPostCutoffCloud
- ? AnalyticsIntegrationExportSource.EVENTS
- : (state?.exportSource ??
- (isBetaEnabled || !exportSourceCtx.legacyWritesActive
- ? AnalyticsIntegrationExportSource.EVENTS
- : AnalyticsIntegrationExportSource.TRACES_OBSERVATIONS));
-
const posthogForm = useForm({
resolver: zodResolver(formSchema),
defaultValues: {