🪢 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(notifications): add a posthog-export-failed project notification event (#16135)
Niklas Semmlerc4be5aeca7a9
diff --git a/packages/shared/prisma/migrations/20260813120000_add_posthog_integration_error_fields/migration.sql b/packages/shared/prisma/migrations/20260813120000_add_posthog_integration_error_fields/migration.sqlnew file mode 100644index 0000000000..feb2bfcb99--- /dev/null+++ b/packages/shared/prisma/migrations/20260813120000_add_posthog_integration_error_fields/migration.sql@@ -0,0 +1,2 @@+ALTER TABLE "posthog_integrations" ADD COLUMN IF NOT EXISTS "last_error" TEXT;+ALTER TABLE "posthog_integrations" ADD COLUMN IF NOT EXISTS "last_error_at" TIMESTAMP(3);diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prismaindex 88ca872fbb..f46335c8ca 100644--- a/packages/shared/prisma/schema.prisma+++ b/packages/shared/prisma/schema.prisma@@ -1070,6 +1070,12 @@ model PosthogIntegration {createdAt DateTime @default(now()) @map("created_at")exportSource AnalyticsIntegrationExportSource @default(TRACES_OBSERVATIONS) @map("export_source")+ // Last deterministic customer-config fault (bad hostname) that disabled the+ // integration. Written by the worker, surfaced in the integration settings+ // status section, and cleared on a successful run.+ lastError String? @map("last_error")+ lastErrorAt DateTime? @map("last_error_at")+@@map("posthog_integrations")}diff --git a/packages/shared/src/domain/automations.ts b/packages/shared/src/domain/automations.tsindex ac1305cd59..246c416631 100644--- a/packages/shared/src/domain/automations.ts+++ b/packages/shared/src/domain/automations.ts@@ -29,6 +29,7 @@ export const TriggerEventSourceSchema = z.enum([*/export const ProjectNotificationEventTypeSchema = z.enum(["blob-export-failed",+ "posthog-export-failed","evaluator-blocked",]);export type ProjectNotificationEventType = z.infer<diff --git a/packages/shared/src/server/index.ts b/packages/shared/src/server/index.tsindex 3f9d7434e4..ebca27edee 100644--- a/packages/shared/src/server/index.ts+++ b/packages/shared/src/server/index.ts@@ -20,6 +20,7 @@ export * from "./services/email/usageThresholdWarning/sendUsageThresholdWarningEexport * from "./services/email/usageThresholdSuspension/sendUsageThresholdSuspensionEmail";export * from "./services/email/commentMention/sendCommentMentionEmail";export * from "./services/email/blobStorageExportFailed/sendBlobStorageExportFailedEmail";+export * from "./services/email/posthogExportFailed/sendPostHogExportFailedEmail";export * from "./services/PromptService";export * from "./services/PromptService/types";export * from "./services/traces-ui-table-service";diff --git a/packages/shared/src/server/notifications/buildProjectNotificationSlackMessage.ts b/packages/shared/src/server/notifications/buildProjectNotificationSlackMessage.tsindex 352e5f1915..b41de9f888 100644--- a/packages/shared/src/server/notifications/buildProjectNotificationSlackMessage.ts+++ b/packages/shared/src/server/notifications/buildProjectNotificationSlackMessage.ts@@ -9,6 +9,7 @@ import {/** projectNotificationTitle maps an event type to a human-readable Slack title. */const projectNotificationTitle: Record<ProjectNotificationEventType, string> = {"blob-export-failed": "Blob storage export failed",+ "posthog-export-failed": "PostHog export failed","evaluator-blocked": "Evaluator blocked",};diff --git a/packages/shared/src/server/notifications/dispatchProjectNotification.ts b/packages/shared/src/server/notifications/dispatchProjectNotification.tsindex 24b7e4f0c8..60297130a3 100644--- a/packages/shared/src/server/notifications/dispatchProjectNotification.ts+++ b/packages/shared/src/server/notifications/dispatchProjectNotification.ts@@ -9,6 +9,7 @@ import { QueueJobs, QueueName } from "../queues";import { WebhookQueue } from "../redis/webhookQueue";import { getAutomations } from "../repositories/automation-repository";import { sendBlobStorageExportFailedEmail } from "../services/email/blobStorageExportFailed/sendBlobStorageExportFailedEmail";+import { sendPostHogExportFailedEmail } from "../services/email/posthogExportFailed/sendPostHogExportFailedEmail";import { sendEvaluatorBlockedEmail } from "../services/email/evaluatorBlocked/sendEvaluatorBlockedEmail";import { getProjectAdminEmails } from "../services/getProjectAdminEmails";import { type ProjectNotificationEvent } from "./types";@@ -176,6 +177,16 @@ async function sendEventAdminEmails({});return;}+ case "posthog-export-failed": {+ await sendPostHogExportFailedEmail({+ env: emailEnv,+ projectName: event.projectName,+ settingsUrl: `${emailEnv.NEXTAUTH_URL}/project/${event.projectId}/settings/integrations/posthog`,+ receiverEmails,+ disabled: event.disabled ?? false,+ });+ return;+ }case "evaluator-blocked": {const resolutionUrl = `${emailEnv.NEXTAUTH_URL}${getEvaluatorBlockResolutionPath({diff --git a/packages/shared/src/server/notifications/types.ts b/packages/shared/src/server/notifications/types.tsindex 2710c38444..1b3ccd2b05 100644--- a/packages/shared/src/server/notifications/types.ts+++ b/packages/shared/src/server/notifications/types.ts@@ -50,6 +50,14 @@ export const ProjectNotificationEventSchema = z.discriminatedUnion(// (terminal event; selects the "disabled" email variant).disabled: z.boolean().optional(),}),+ projectNotificationEventBaseSchema.extend({+ eventType: z.literal(+ ProjectNotificationEventTypeSchema.enum["posthog-export-failed"],+ ),+ // true when the integration was auto-disabled after a deterministic+ // customer-config fault (terminal event; selects the "disabled" variant).+ disabled: z.boolean().optional(),+ }),projectNotificationEventBaseSchema.extend({eventType: z.literal(ProjectNotificationEventTypeSchema.enum["evaluator-blocked"],diff --git a/packages/shared/src/server/services/email/posthogExportFailed/sendPostHogExportFailedEmail.tsx b/packages/shared/src/server/services/email/posthogExportFailed/sendPostHogExportFailedEmail.tsxnew file mode 100644index 0000000000..02fbef0c2f--- /dev/null+++ b/packages/shared/src/server/services/email/posthogExportFailed/sendPostHogExportFailedEmail.tsx@@ -0,0 +1,28 @@+import React from "react";+import {+ sendIntegrationExportFailedEmail,+ type SendIntegrationExportFailedEmailParams,+} from "../integrationExportFailed/sendIntegrationExportFailedEmail";+import { type IntegrationExportFailedEmailCopy } from "../integrationExportFailed/IntegrationExportFailedEmailTemplate";++export type SendPostHogExportFailedEmailParams =+ SendIntegrationExportFailedEmailParams;++export const postHogExportFailedEmailCopy: IntegrationExportFailedEmailCopy = {+ subjectLabel: "PostHog",+ headingLabel: "PostHog",+ inlineLabel: "PostHog",+ disabledBody: (projectName) => (+ <>+ The PostHog export for project "{projectName}+ " has been disabled after a configuration fault. This usually means+ the PostHog host is no longer reachable or valid. Once you have updated+ it, simply re-enable the export in the integration settings and it will+ pick up right where it left off.+ </>+ ),+};++export const sendPostHogExportFailedEmail = (+ params: SendPostHogExportFailedEmailParams,+) => sendIntegrationExportFailedEmail(postHogExportFailedEmailCopy, params);diff --git a/web/src/features/posthog-integration/posthog-integration-router.ts b/web/src/features/posthog-integration/posthog-integration-router.tsindex bfc4c86f8c..2310f5b57e 100644--- a/web/src/features/posthog-integration/posthog-integration-router.ts+++ b/web/src/features/posthog-integration/posthog-integration-router.ts@@ -192,6 +192,8 @@ export const posthogIntegrationRouter = createTRPCRouter({// undefined → Prisma omits the column → preserves the persisted// value on partial updates (LFE-10296).exportSource: config.exportSource,+ // lastError is deliberately left intact so the last fault stays+ // visible until a successful run clears it.},});