Skip to content

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

feat(worker): add sfdc org id, user auth methods, and sso domain data to core data export (#14713)

Steffen Schmitz8f31d9f33880
diff --git a/worker/src/queues/__tests__/coreDataS3ExportQueue.test.ts b/worker/src/queues/__tests__/coreDataS3ExportQueue.test.ts
index 8151d4a56c..3113149751 100644
--- a/worker/src/queues/__tests__/coreDataS3ExportQueue.test.ts
+++ b/worker/src/queues/__tests__/coreDataS3ExportQueue.test.ts
@@ -1,7 +1,10 @@
import { describe, expect, it, vi } from "vitest";
import { Readable } from "node:stream";
import { type StorageService } from "@langfuse/shared/src/server";
-import { uploadPromptsCoreDataJsonl } from "../coreDataS3ExportQueue";
+import {
+ mapUserToCoreDataRow,
+ uploadPromptsCoreDataJsonl,
+} from "../coreDataS3ExportQueue";
const readStream = async (stream: Readable): Promise<string> => {
const chunks: string[] = [];
@@ -13,6 +16,38 @@ const readStream = async (stream: Readable): Promise<string> => {
return chunks.join("");
};
+describe("mapUserToCoreDataRow", () => {
+ it("derives auth methods from password and account providers", () => {
+ const row = mapUserToCoreDataRow({
+ id: "user-1",
+ email: "[email protected]",
+ password: "hashed-password",
+ accounts: [
+ { provider: "google" },
+ { provider: "okta" },
+ { provider: "google" },
+ ],
+ });
+
+ expect(row).toStrictEqual({
+ id: "user-1",
+ email: "[email protected]",
+ authMethods: ["credentials", "google", "okta"],
+ });
+ expect(JSON.stringify(row)).not.toContain("hashed-password");
+ });
+
+ it("returns no auth methods for users without password and accounts", () => {
+ const row = mapUserToCoreDataRow({
+ id: "user-2",
+ password: null,
+ accounts: [],
+ });
+
+ expect(row).toStrictEqual({ id: "user-2", authMethods: [] });
+ });
+});
+
describe("coreDataS3ExportQueue", () => {
it("streams prompt core data in pages", async () => {
const createdAt = new Date("2026-05-14T00:00:00.000Z");
diff --git a/worker/src/queues/coreDataS3ExportQueue.ts b/worker/src/queues/coreDataS3ExportQueue.ts
index d75ba83f84..83d83b2fc5 100644
--- a/worker/src/queues/coreDataS3ExportQueue.ts
+++ b/worker/src/queues/coreDataS3ExportQueue.ts
@@ -30,6 +30,26 @@ const getS3StorageServiceClient = (bucketName: string): StorageService => {
return s3StorageServiceClient;
};
+type UserCoreDataInput = {
+ password: string | null;
+ accounts: { provider: string }[];
+} & Record<string, unknown>;
+
+// Derives the auth methods per user from the linked next-auth accounts and the
+// presence of a password hash ("credentials"). The hash itself must never
+// reach the export.
+export const mapUserToCoreDataRow = ({
+ password,
+ accounts,
+ ...user
+}: UserCoreDataInput) => ({
+ ...user,
+ authMethods: [
+ ...(password ? ["credentials"] : []),
+ ...Array.from(new Set(accounts.map((account) => account.provider))),
+ ],
+});
+
type PromptCoreData = {
id: string;
name: string;
@@ -120,13 +140,15 @@ export const coreDataS3ExportProcessor: Processor = async (): Promise<void> => {
// Fetch table data
const [
projects,
- users,
+ usersWithAuthData,
organizations,
orgMemberships,
projectMemberships,
billingMeterBackup,
surveys,
blobStorageIntegrations,
+ ssoConfigs,
+ verifiedDomains,
] = await Promise.all([
prisma.project.findMany({
select: {
@@ -147,6 +169,14 @@ export const coreDataS3ExportProcessor: Processor = async (): Promise<void> => {
v4BetaEnabled: true,
createdAt: true,
updatedAt: true,
+ // password and accounts are mapped to authMethods below and must not
+ // be exported as-is
+ password: true,
+ accounts: {
+ select: {
+ provider: true,
+ },
+ },
},
}),
prisma.organization.findMany({
@@ -154,6 +184,7 @@ export const coreDataS3ExportProcessor: Processor = async (): Promise<void> => {
id: true,
name: true,
cloudConfig: true,
+ sfdcOrgId: true,
createdAt: true,
updatedAt: true,
},
@@ -215,8 +246,29 @@ export const coreDataS3ExportProcessor: Processor = async (): Promise<void> => {
updatedAt: true,
},
}),
+ // authConfig is excluded as it may contain client secrets
+ prisma.ssoConfig.findMany({
+ select: {
+ domain: true,
+ authProvider: true,
+ createdAt: true,
+ updatedAt: true,
+ },
+ }),
+ prisma.verifiedDomain.findMany({
+ select: {
+ id: true,
+ organizationId: true,
+ domain: true,
+ verifiedAt: true,
+ createdAt: true,
+ updatedAt: true,
+ },
+ }),
]);
+ const users = usersWithAuthData.map(mapUserToCoreDataRow);
+
// Iterate through the tables and upload them to S3 as JSONLs
await Promise.all(
Object.entries({
@@ -228,6 +280,8 @@ export const coreDataS3ExportProcessor: Processor = async (): Promise<void> => {
billingMeterBackup,
surveys,
blobStorageIntegrations,
+ ssoConfigs,
+ verifiedDomains,
}).map(async ([key, value]) =>
s3Client.uploadFile({
fileName: `${env.LANGFUSE_S3_CORE_DATA_UPLOAD_PREFIX}${key}.jsonl`,