🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(billing): send cloud provider, region and cell in CHB project events (#16941)
Steffen Schmitz76149b8822fe
diff --git a/web/src/__tests__/server/unit/chb-project-events.servertest.ts b/web/src/__tests__/server/unit/chb-project-events.servertest.tsindex 324b06fe5f..d47a0eb4c3 100644--- a/web/src/__tests__/server/unit/chb-project-events.servertest.ts+++ b/web/src/__tests__/server/unit/chb-project-events.servertest.ts@@ -6,7 +6,7 @@ const EVENT_BUS_ARN =const mocks = vi.hoisted(() => ({env: {- NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: "eu" as string | undefined,+ NEXT_PUBLIC_LANGFUSE_CLOUD_REGION: "EU" as string | undefined,CLICKHOUSE_BILLING_EVENT_BUS_ARN:"arn:aws:events:eu-central-1:720474339533:event-bus/control-plane-events" as| string@@ -92,6 +92,7 @@ const waitFor = (assertion: () => void) =>describe("chbProjectEvents", () => {beforeEach(() => {vi.clearAllMocks();+ mocks.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = "EU";mocks.env.CLICKHOUSE_BILLING_EVENT_BUS_ARN = EVENT_BUS_ARN;mocks.send.mockResolvedValue({ FailedEntryCount: 0 });mocks.findProjects.mockResolvedValue([]);@@ -117,11 +118,42 @@ describe("chbProjectEvents", () => {expect(entry.Source).toBe("langfuse");// The event carries CHB's organization id, not ours -- CHB's registry is// keyed by its own org id.- expect(JSON.parse(entry.Detail)).toMatchObject({+ const detail = JSON.parse(entry.Detail);+ expect(detail).toMatchObject({type: "LANGFUSE_PROJECT_CREATED",organizationId: CHB_ORG_ID,projectId: PROJECT_ID,- regionId: "eu",+ // Where this deployment runs: the provider region it lives in plus our+ // own cell name, lowercased.+ cloudProvider: "aws",+ region: "eu-west-1",+ cell: "eu",+ });+ expect(detail).not.toHaveProperty("regionId");+ });++ // CHB locates a deployment by provider region plus cell, not by our cell+ // name alone. HIPAA and US share us-west-2, so the cell is what still tells+ // them apart.+ it.each([+ ["US", "us-west-2", "us"],+ ["EU", "eu-west-1", "eu"],+ ["HIPAA", "us-west-2", "hipaa"],+ ["JP", "ap-northeast-1", "jp"],+ ["STAGING", "eu-west-1", "staging"],+ ])("locates cell %s in %s", async (cloudRegion, awsRegion, cell) => {+ mocks.env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION = cloudRegion;++ await sendChbProjectEvent({+ type: "LANGFUSE_PROJECT_CREATED",+ chbOrganizationId: CHB_ORG_ID,+ projectId: PROJECT_ID,+ });++ expect(publishedDetails()[0]).toMatchObject({+ cloudProvider: "aws",+ region: awsRegion,+ cell,});});diff --git a/web/src/ee/features/billing/server/chb/chbProjectEvents.ts b/web/src/ee/features/billing/server/chb/chbProjectEvents.tsindex a29b318419..fe38d3be27 100644--- a/web/src/ee/features/billing/server/chb/chbProjectEvents.ts+++ b/web/src/ee/features/billing/server/chb/chbProjectEvents.ts@@ -45,21 +45,46 @@ const EVENT_BUS_REQUEST_TIMEOUT_MS = 5_000;// hundred bytes each, so the 256KB per-call limit is never the binding one.const EVENT_BUS_MAX_ENTRIES_PER_CALL = 10;-// The envelope (type, CHB organizationId, Langfuse projectId, regionId) still-// needs a final confirmation from CHB before rollout, so it is isolated here:-// a contract change stays a one-function edit. `type` is repeated here and in-// detail-type so a consumer reading either one sees it.+type CloudCell = NonNullable<typeof env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION>;++// Where each cell runs, mirroring the per-environment AWS region in the+// infrastructure repo. Exhaustive on purpose: a new cell does not compile until+// its location is filled in. DEV is a developer machine with no fixed+// location, so it reports none.+const CELL_LOCATION: Record<+ CloudCell,+ { cloudProvider: "aws"; region: string } | null+> = {+ US: { cloudProvider: "aws", region: "us-west-2" },+ EU: { cloudProvider: "aws", region: "eu-west-1" },+ HIPAA: { cloudProvider: "aws", region: "us-west-2" },+ JP: { cloudProvider: "aws", region: "ap-northeast-1" },+ STAGING: { cloudProvider: "aws", region: "eu-west-1" },+ DEV: null,+};++// The envelope is the contract with CHB, so it is isolated here: a contract+// change stays a one-function edit. `type` is repeated here and in detail-type+// so a consumer reading either one sees it.const buildChbProjectEventPayload = (params: {type: ChbProjectEventType;chbOrganizationId: string;projectId: string;-}) => ({- type: params.type,- organizationId: params.chbOrganizationId,- projectId: params.projectId,- regionId: env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION,- createdAt: new Date().toISOString(),-});+}) => {+ const cell = env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION;++ return {+ type: params.type,+ organizationId: params.chbOrganizationId,+ projectId: params.projectId,+ // CHB locates a deployment by provider region plus cell, not by our cell+ // name alone: two cells can share one region (US and HIPAA both run in+ // us-west-2), so the cell is what still tells them apart.+ ...(cell ? CELL_LOCATION[cell] : null),+ cell: cell?.toLowerCase(),+ createdAt: new Date().toISOString(),+ };+};// One bus per deployment, so one client: the ARN comes from env and cannot// change at runtime. Lazy so a web instance that never touches CHB billing