🪢 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
fix: warn if missing encryption_key when updating posthog integration (#7560)
Marc Klingena73156bbe51b
diff --git a/web/src/features/posthog-integration/posthog-integration-router.ts b/web/src/features/posthog-integration/posthog-integration-router.tsindex 8ebe8cd3c1..905ce6859c 100644--- a/web/src/features/posthog-integration/posthog-integration-router.ts+++ b/web/src/features/posthog-integration/posthog-integration-router.ts@@ -9,6 +9,7 @@ import {import { decrypt, encrypt } from "@langfuse/shared/encryption";import { posthogIntegrationFormSchema } from "@/src/features/posthog-integration/types";import { TRPCError } from "@trpc/server";+import { env } from "@/src/env.mjs";export const posthogIntegrationRouter = createTRPCRouter({get: protectedProjectProcedure@@ -47,44 +48,51 @@ export const posthogIntegrationRouter = createTRPCRouter({update: protectedProjectProcedure.input(posthogIntegrationFormSchema.extend({ projectId: z.string() })).mutation(async ({ input, ctx }) => {- try {- throwIfNoProjectAccess({- session: ctx.session,- projectId: input.projectId,- scope: "integrations:CRUD",- });- await auditLog({- session: ctx.session,- action: "update",- resourceType: "posthogIntegration",- resourceId: input.projectId,- });- const { posthogProjectApiKey, ...config } = input;+ throwIfNoProjectAccess({+ session: ctx.session,+ projectId: input.projectId,+ scope: "integrations:CRUD",+ });+ if (!env.ENCRYPTION_KEY) {+ if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {+ throw new TRPCError({+ code: "INTERNAL_SERVER_ERROR",+ message: "Internal server error",+ });+ } else {+ throw new TRPCError({+ code: "BAD_REQUEST",+ message:+ "Missing environment variable: `ENCRYPTION_KEY`. Please consult our docs: https://langfuse.com/self-hosting",+ });+ }+ }+ await auditLog({+ session: ctx.session,+ action: "update",+ resourceType: "posthogIntegration",+ resourceId: input.projectId,+ });+ const { posthogProjectApiKey, ...config } = input;- const encryptedPosthogApiKey = encrypt(posthogProjectApiKey);+ const encryptedPosthogApiKey = encrypt(posthogProjectApiKey);- await ctx.prisma.posthogIntegration.upsert({- where: {- projectId: input.projectId,- },- create: {- projectId: input.projectId,- posthogHostName: config.posthogHostname,- encryptedPosthogApiKey,- enabled: config.enabled,- },- update: {- encryptedPosthogApiKey,- posthogHostName: config.posthogHostname,- enabled: config.enabled,- },- });- } catch (e) {- console.log("posthog integration update", e);- throw new TRPCError({- code: "INTERNAL_SERVER_ERROR",- });- }+ await ctx.prisma.posthogIntegration.upsert({+ where: {+ projectId: input.projectId,+ },+ create: {+ projectId: input.projectId,+ posthogHostName: config.posthogHostname,+ encryptedPosthogApiKey,+ enabled: config.enabled,+ },+ update: {+ encryptedPosthogApiKey,+ posthogHostName: config.posthogHostname,+ enabled: config.enabled,+ },+ });}),delete: protectedProjectProcedure.input(z.object({ projectId: z.string() }))