Skip to content

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

feat(worker): send email to project admins on blob storage export failure (#12617)

Valery Meleshkinaa6594ea6f4c
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index 88b2a3a49d..d170d0f103 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -380,6 +380,7 @@ export type BlobStorageIntegration = {
export_source: Generated<AnalyticsIntegrationExportSource>;
last_error: string | null;
last_error_at: Timestamp | null;
+ last_failure_notification_sent_at: Timestamp | null;
created_at: Generated<Timestamp>;
updated_at: Generated<Timestamp>;
};
diff --git a/packages/shared/prisma/migrations/20260316000000_add_blob_storage_failure_notification_sent_at/migration.sql b/packages/shared/prisma/migrations/20260316000000_add_blob_storage_failure_notification_sent_at/migration.sql
new file mode 100644
index 0000000000..bf3bb6589a
--- /dev/null
+++ b/packages/shared/prisma/migrations/20260316000000_add_blob_storage_failure_notification_sent_at/migration.sql
@@ -0,0 +1 @@
+ALTER TABLE "blob_storage_integrations" ADD COLUMN IF NOT EXISTS "last_failure_notification_sent_at" TIMESTAMP(3);
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 396e6e0904..6ecd9bd80d 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -1130,6 +1130,9 @@ model BlobStorageIntegration {
lastError String? @map("last_error")
lastErrorAt DateTime? @map("last_error_at")
+ // Notification tracking
+ lastFailureNotificationSentAt DateTime? @map("last_failure_notification_sent_at")
+
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
diff --git a/packages/shared/src/server/index.ts b/packages/shared/src/server/index.ts
index 7574e5b34b..108e6ba2dc 100644
--- a/packages/shared/src/server/index.ts
+++ b/packages/shared/src/server/index.ts
@@ -8,6 +8,7 @@ export * from "./services/email/cloudSpendAlert/sendCloudSpendAlertEmail";
export * from "./services/email/usageThresholdWarning/sendUsageThresholdWarningEmail";
export * from "./services/email/usageThresholdSuspension/sendUsageThresholdSuspensionEmail";
export * from "./services/email/commentMention/sendCommentMentionEmail";
+export * from "./services/email/blobStorageExportFailed/sendBlobStorageExportFailedEmail";
export * from "./services/PromptService";
export * from "./services/PromptService/types";
export * from "./services/traces-ui-table-service";
@@ -109,6 +110,7 @@ export * from "./services/TableViewService";
export * from "./services/DefaultViewService";
export * from "./services/DefaultEvaluationModelService";
export * from "./services/blockEvaluatorConfigs";
+export * from "./services/getProjectAdminEmails";
export * from "./clickhouse/measureAndReturn";
export * from "./services/SlackService";
export * from "./tableMappings";
diff --git a/packages/shared/src/server/services/email/blobStorageExportFailed/BlobStorageExportFailedEmailTemplate.tsx b/packages/shared/src/server/services/email/blobStorageExportFailed/BlobStorageExportFailedEmailTemplate.tsx
new file mode 100644
index 0000000000..cfa43af04b
--- /dev/null
+++ b/packages/shared/src/server/services/email/blobStorageExportFailed/BlobStorageExportFailedEmailTemplate.tsx
@@ -0,0 +1,80 @@
+import React from "react";
+import {
+ Body,
+ Button,
+ Container,
+ Head,
+ Heading,
+ Hr,
+ Html,
+ Img,
+ Preview,
+ Section,
+ Tailwind,
+ Text,
+} from "@react-email/components";
+
+type BlobStorageExportFailedEmailTemplateProps = {
+ projectName: string;
+ settingsUrl: string;
+};
+
+export const BlobStorageExportFailedEmailTemplate = ({
+ projectName,
+ settingsUrl,
+}: BlobStorageExportFailedEmailTemplateProps) => {
+ return (
+ <Html>
+ <Head />
+ <Preview>
+ Blob storage export failed for project &quot;{projectName}&quot;
+ </Preview>
+ <Tailwind>
+ <Body className="bg-background my-auto mx-auto font-sans">
+ <Container className="mx-auto my-10 w-[465px] rounded border border-solid border-[#eaeaea] p-5">
+ <Section className="mt-8">
+ <Img
+ src="https://static.langfuse.com/langfuse_logo_transactional_email.png"
+ width="40"
+ height="40"
+ alt="Langfuse"
+ className="mx-auto my-0"
+ />
+ </Section>
+
+ <Section>
+ <Heading className="mx-0 my-[30px] p-0 text-center text-2xl font-normal text-black">
+ Blob Storage Export Failed
+ </Heading>
+ <Text className="text-gray-700 text-sm leading-6">
+ The scheduled blob storage export for project &quot;
+ {projectName}&quot; has failed. Review the integration settings
+ to see the error details and resolve the issue.
+ </Text>
+ </Section>
+
+ <Section className="mt-8 text-center">
+ <Button
+ className="rounded bg-red-600 px-5 py-3 text-center text-xs font-semibold text-white no-underline"
+ href={settingsUrl}
+ >
+ Review Settings
+ </Button>
+ </Section>
+
+ <Hr className="border border-solid border-[#eaeaea] my-[26px] mx-0 w-full" />
+
+ <Section>
+ <Text className="text-[#666666] text-[12px] leading-[24px]">
+ This notification was sent to project admins regarding a failed
+ blob storage export for project &quot;{projectName}&quot;.
+ </Text>
+ </Section>
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+};
+
+export default BlobStorageExportFailedEmailTemplate;
diff --git a/packages/shared/src/server/services/email/blobStorageExportFailed/sendBlobStorageExportFailedEmail.ts b/packages/shared/src/server/services/email/blobStorageExportFailed/sendBlobStorageExportFailedEmail.ts
new file mode 100644
index 0000000000..de3d773da3
--- /dev/null
+++ b/packages/shared/src/server/services/email/blobStorageExportFailed/sendBlobStorageExportFailedEmail.ts
@@ -0,0 +1,80 @@
+import { createTransport } from "nodemailer";
+import { parseConnectionUrl } from "nodemailer/lib/shared/index.js";
+import { render } from "@react-email/render";
+import { z } from "zod/v4";
+import { sanitizeEmailSubject } from "../../../../utils/zod";
+import { logger } from "../../../logger";
+import { BlobStorageExportFailedEmailTemplate } from "./BlobStorageExportFailedEmailTemplate";
+
+export type SendBlobStorageExportFailedEmailParams = {
+ env: Partial<
+ Record<
+ | "EMAIL_FROM_ADDRESS"
+ | "SMTP_CONNECTION_URL"
+ | "NEXTAUTH_URL"
+ | "CLOUD_CRM_EMAIL",
+ string | undefined
+ >
+ >;
+ projectName: string;
+ settingsUrl: string;
+ receiverEmails: string[];
+};
+
+export const sendBlobStorageExportFailedEmail = async ({
+ env,
+ projectName,
+ settingsUrl,
+ receiverEmails,
+}: SendBlobStorageExportFailedEmailParams) => {
+ if (!env.EMAIL_FROM_ADDRESS || !env.SMTP_CONNECTION_URL) {
+ logger.error(
+ "Missing environment variables for sending blob storage export failed email.",
+ );
+ return;
+ }
+
+ if (receiverEmails.length === 0) {
+ return;
+ }
+
+ try {
+ const mailer = createTransport(parseConnectionUrl(env.SMTP_CONNECTION_URL));
+ const safeProjectName = sanitizeEmailSubject(projectName);
+ const subject = `Blob storage export failed for "${safeProjectName}" – action required`;
+ const html = await render(
+ BlobStorageExportFailedEmailTemplate({
+ projectName: safeProjectName,
+ settingsUrl,
+ }),
+ );
+
+ const mailOptions: Record<string, unknown> = {
+ to: receiverEmails,
+ from: {
+ address: env.EMAIL_FROM_ADDRESS,
+ name: "Langfuse",
+ },
+ replyTo: "[email protected]",
+ subject,
+ html,
+ };
+
+ if (env.CLOUD_CRM_EMAIL) {
+ const emailSchema = z.string().email();
+ const validationResult = emailSchema.safeParse(env.CLOUD_CRM_EMAIL);
+
+ if (validationResult.success) {
+ mailOptions.bcc = validationResult.data;
+ } else {
+ logger.warn(
+ `Invalid CLOUD_CRM_EMAIL format: ${env.CLOUD_CRM_EMAIL}. Skipping BCC.`,
+ );
+ }
+ }
+
+ await mailer.sendMail(mailOptions);
+ } catch (error) {
+ logger.error("Failed to send blob storage export failed email", error);
+ }
+};
diff --git a/worker/src/env.ts b/worker/src/env.ts
index 24d78e5697..d786b02583 100644
--- a/worker/src/env.ts
+++ b/worker/src/env.ts
@@ -160,6 +160,11 @@ const EnvSchema = z.object({
.enum(["true", "false"])
.default("true"),
+ LANGFUSE_BLOB_STORAGE_FAILURE_NOTIFICATION_COOLDOWN_HOURS: z.coerce
+ .number()
+ .positive()
+ .default(24),
+
// Comma-separated list of project IDs that should only export traces table (skip observations and scores)
LANGFUSE_BLOB_STORAGE_EXPORT_TRACE_ONLY_PROJECT_IDS: z
.string()
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index cc411723ad..8946bfe1a3 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -16,6 +16,8 @@ import {
BlobStorageIntegrationProcessingQueue,
queryClickhouse,
QueueJobs,
+ sendBlobStorageExportFailedEmail,
+ getProjectAdminEmails,
} from "@langfuse/shared/src/server";
import {
BlobStorageIntegrationType,
@@ -463,8 +465,9 @@ export const handleBlobStorageIntegrationProjectJob = async (
`[BLOB INTEGRATION] Successfully processed blob storage integration for project ${projectId}`,
);
} catch (error) {
+ const errorMessage = extractStorageErrorMessage(error);
+
try {
- const errorMessage = extractStorageErrorMessage(error);
await prisma.blobStorageIntegration.update({
where: { projectId },
data: {
@@ -478,6 +481,9 @@ export const handleBlobStorageIntegrationProjectJob = async (
persistError,
);
}
+
+ notifyBlobStorageExportFailedInBackground(projectId);
+
logger.error(
`[BLOB INTEGRATION] Error processing blob storage integration for project ${projectId}`,
error,
@@ -486,6 +492,85 @@ export const handleBlobStorageIntegrationProjectJob = async (
}
};
+function notifyBlobStorageExportFailedInBackground(projectId: string): void {
+ void (async () => {
+ try {
+ const cooldownMs =
+ env.LANGFUSE_BLOB_STORAGE_FAILURE_NOTIFICATION_COOLDOWN_HOURS *
+ 60 *
+ 60 *
+ 1000;
+
+ // Atomic claim: set timestamp before sending to prevent duplicate emails on concurrent retries.
+ // If the email send subsequently fails, the cooldown still applies — the next failure
+ // after cooldown expiry will retry the notification.
+ const claimed = await prisma.blobStorageIntegration.updateMany({
+ where: {
+ projectId,
+ OR: [
+ { lastFailureNotificationSentAt: null },
+ {
+ lastFailureNotificationSentAt: {
+ lt: new Date(Date.now() - cooldownMs),
+ },
+ },
+ ],
+ },
+ data: { lastFailureNotificationSentAt: new Date() },
+ });
+
+ if (claimed.count === 0) {
+ logger.info(
+ `[BLOB INTEGRATION] Skipping failure notification for project ${projectId}, cooldown still active`,
+ );
+ return;
+ }
+
+ const emailEnv = {
+ EMAIL_FROM_ADDRESS: env.EMAIL_FROM_ADDRESS,
+ SMTP_CONNECTION_URL: env.SMTP_CONNECTION_URL,
+ NEXTAUTH_URL: env.NEXTAUTH_URL,
+ CLOUD_CRM_EMAIL: env.CLOUD_CRM_EMAIL,
+ };
+
+ if (
+ !emailEnv.EMAIL_FROM_ADDRESS ||
+ !emailEnv.SMTP_CONNECTION_URL ||
+ !emailEnv.NEXTAUTH_URL
+ ) {
+ return;
+ }
+
+ const [adminEmails, project] = await Promise.all([
+ getProjectAdminEmails(projectId),
+ prisma.project.findUnique({
+ where: { id: projectId },
+ select: { name: true },
+ }),
+ ]);
+
+ if (adminEmails.length === 0) {
+ return;
+ }
+
+ const projectName = project?.name ?? projectId;
+ const settingsUrl = `${emailEnv.NEXTAUTH_URL}/project/${projectId}/settings/integrations/blobstorage`;
+
+ await sendBlobStorageExportFailedEmail({
+ env: emailEnv,
+ projectName,
+ settingsUrl,
+ receiverEmails: adminEmails,
+ });
+ } catch (error) {
+ logger.error(
+ `[BLOB INTEGRATION] Failed to send failure notification for project ${projectId}`,
+ error,
+ );
+ }
+ })();
+}
+
function extractStorageErrorMessage(error: unknown): string {
if (!(error instanceof Error)) return String(error).slice(0, 1000);