{"record":{"id":"16596ca580451526","repo":"langfuse/langfuse","slug":"bad-request-16596c","errorCode":"BAD_REQUEST","errorMessage":"Missing environment variable: `ENCRYPTION_KEY`. Please consult our docs: https://langfuse.com/self-hosting","messagePattern":"Missing environment variable: `ENCRYPTION_KEY`\\. Please consult our docs: https://langfuse\\.com/self-hosting","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"web/src/features/posthog-integration/posthog-integration-router.ts","lineNumber":90,"sourceCode":"        // Drop the base schema default so an omitted value preserves the\n        // persisted source instead of rewriting it to the legacy default.\n        exportSource: z.enum(AnalyticsIntegrationExportSource).optional(),\n      }),\n    )\n    .mutation(async ({ input, ctx }) => {\n      throwIfNoProjectAccess({\n        session: ctx.session,\n        projectId: input.projectId,\n        scope: \"integrations:CRUD\",\n      });\n      if (!env.ENCRYPTION_KEY) {\n        if (env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION) {\n          throw new TRPCError({\n            code: \"INTERNAL_SERVER_ERROR\",\n            message: \"Internal server error\",\n          });\n        } else {\n          throw new TRPCError({\n            code: \"BAD_REQUEST\",\n            message:\n              \"Missing environment variable: `ENCRYPTION_KEY`. Please consult our docs: https://langfuse.com/self-hosting\",\n          });\n        }\n      }\n\n      // Validate PostHog hostname to prevent SSRF attacks\n      try {\n        await validateWebhookURL(input.posthogHostname);\n      } catch (error) {\n        throw new TRPCError({\n          code: \"BAD_REQUEST\",\n          message:\n            error instanceof Error\n              ? `Invalid PostHog hostname: ${error.message}`\n              : \"Invalid PostHog hostname\",\n        });","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/langfuse/langfuse/blob/59d92c7cf365150d10b753b5a0d1708902a2ed60/web/src/features/posthog-integration/posthog-integration-router.ts#L72-L108","documentation":"Same missing-ENCRYPTION_KEY guard, but on self-hosted (no cloud region) the error is surfaced honestly as BAD_REQUEST telling the operator to consult self-hosting docs, since storing the PostHog API key requires encryption at rest.","triggerScenarios":"Self-hosted deployment without ENCRYPTION_KEY configured, attempting to create/update a PostHog integration.","commonSituations":"Fresh self-hosted installs that skipped ENCRYPTION_KEY in docker-compose/.env.","solutions":["Generate a key (openssl rand -hex 16... per docs) and set ENCRYPTION_KEY in the web container env","Restart the web server after setting it"],"exampleFix":"# .env\nENCRYPTION_KEY=$(openssl rand -hex 16)  # 32 bytes as required","handlingStrategy":"validation","validationCode":"if (!process.env.ENCRYPTION_KEY) { /* show self-hosting setup instructions before save */ }","typeGuard":null,"tryCatchPattern":"catch BAD_REQUEST with 'ENCRYPTION_KEY' in message and link to self-hosting docs","preventionTips":["Include ENCRYPTION_KEY in .env from day one of self-hosting","Validate env at container startup"],"tags":["env-var","encryption","self-hosting","posthog"],"backgroundTag":"missing-env-var","analyzedSha":"59d92c7cf365150d10b753b5a0d1708902a2ed60","analyzedAt":"2026-08-27T22:22:00.402Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}