🪢 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
chore(export): remove per-run export freshness lag metric (#18005)
Niklas Semmler0d91524fe42d
diff --git a/.agents/skills/datadog-query-recipes/SKILL.md b/.agents/skills/datadog-query-recipes/SKILL.mdindex dcb907caa3..5a6891bb82 100644--- a/.agents/skills/datadog-query-recipes/SKILL.md+++ b/.agents/skills/datadog-query-recipes/SKILL.md@@ -43,8 +43,6 @@ data domain you need: traces, logs, metrics, and visualizations.[`references/queue-consumers.md`](references/queue-consumers.md)- Scheduled-export staleness (blob / PostHog / Mixpanel):[`references/export-staleness.md`](references/export-staleness.md)- - Scheduled-export freshness lag (legacy per-run metric):- [`references/export-freshness-lag.md`](references/export-freshness-lag.md)3. Start with aggregate queries, grouped by environment, service, route,queue, project, org, status, or error facets as appropriate.4. Fetch raw spans, logs, or traces only after aggregation identifies thediff --git a/.agents/skills/datadog-query-recipes/references/export-freshness-lag.md b/.agents/skills/datadog-query-recipes/references/export-freshness-lag.mddeleted file mode 100644index 7b77156c80..0000000000--- a/.agents/skills/datadog-query-recipes/references/export-freshness-lag.md+++ /dev/null@@ -1,43 +0,0 @@-# Export freshness lag--Scheduled integrations (blob, PostHog, Mixpanel) emit a pooled distribution at-the end of each run. Provenance: the shape from LFE-15853.--## Metric--- Name: `langfuse.export.freshness_lag_seconds`-- Type: distribution-- Value: `runStartTime − maxExportedTimestamp` (seconds, clamped at 0)-- Watermark: `lastSyncAt` after a successful window (`maxTimestamp` just- written). Failing runs use the **unchanged** watermark so stall shows as- rising lag. Do not treat intended window end as the watermark.-- Tags: `integration` (`blob_storage` / `posthog` / `mixpanel`), `window`- (`20m` / `1h` / `1d` / `1w`), `status` (`success` / `failure`), `unit:seconds`.- `env` comes from the agent. **No `project_id`.**-- PostHog and Mixpanel are tagged `window:1h` (hourly cron). Blob uses the- configured cadence.--## Baseline P95 (both Datadog sites)--EU (`prod-eu`) and US (`prod-us`, `prod-hipaa`, `prod-jp`):--```text-p95:langfuse.export.freshness_lag_seconds{*} by {integration,window,env}-```--Split success vs failure while baselining:--```text-p95:langfuse.export.freshness_lag_seconds{*} by {integration,window,status}-```--Catch-up (historic backfill) sits in the tail. P95 is the planned SLI **if**-those runs stay under ~5% of pooled volume. If they do not, filter runs whose-target window is older than N× the cadence (follow-up, not this metric).--## Emit sites--- `worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts`-- `worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts`-- `worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts`-- Helper: `worker/src/services/exportFreshnessLagMetric.ts`diff --git a/.agents/skills/datadog-query-recipes/references/export-staleness.md b/.agents/skills/datadog-query-recipes/references/export-staleness.mdindex 93131b5d70..b549337c1c 100644--- a/.agents/skills/datadog-query-recipes/references/export-staleness.md+++ b/.agents/skills/datadog-query-recipes/references/export-staleness.md@@ -1,8 +1,7 @@# Export stalenessScheduled integrations (blob, PostHog, Mixpanel) emit one sample per enabled-integration on every scheduler tick. Provenance: LFE-16783, replacing the-per-run freshness lag from LFE-15853.+integration on every scheduler tick. Provenance: LFE-16783.## Metricdiff --git a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts b/worker/src/__tests__/blobStorageIntegrationProcessing.test.tsindex 58cc5eb53e..cddf5b5251 100644--- a/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts+++ b/worker/src/__tests__/blobStorageIntegrationProcessing.test.ts@@ -15,11 +15,10 @@ const originalCloudRegion = vi.hoisted(() => {return cloudRegion;});-// Override recordIncrement + recordHistogram + recordDistribution so the-// attempt counter, per-stage timing, and freshness-lag metrics are assertable.+// Override recordIncrement + recordHistogram so the attempt counter and+// per-stage timing metrics are assertable.const mockRecordIncrement = vi.hoisted(() => vi.fn());const mockRecordHistogram = vi.hoisted(() => vi.fn());-const mockRecordDistribution = vi.hoisted(() => vi.fn());// Stubbable endpoint preflight — the customer-fault tests reject it to drive an// in-try failure without infra. Defaults to the real impl for other tests.const mockValidateBlobStorageEndpoint = vi.hoisted(() => vi.fn());@@ -42,7 +41,6 @@ vi.mock("@langfuse/shared/src/server", async (importOriginal) => {...actual,recordIncrement: mockRecordIncrement,recordHistogram: mockRecordHistogram,- recordDistribution: mockRecordDistribution,validateBlobStorageEndpoint: mockValidateBlobStorageEndpoint,dispatchProjectNotification: mockDispatchProjectNotification,};@@ -66,7 +64,6 @@ import {StorageServiceFactory,BlobStorageIntegrationProcessingQueue,} from "@langfuse/shared/src/server";-import { EXPORT_FRESHNESS_LAG_METRIC } from "../services/exportFreshnessLagMetric";import { prisma } from "@langfuse/shared/src/db";import { Job, UnrecoverableError } from "bullmq";import {@@ -1991,7 +1988,7 @@ describe("BlobStorageIntegrationProcessingJob", () => {expect(timeDiff).toBeLessThan(5000); // Within 5 seconds});- it("records freshness success when catch-up enqueue fails after the watermark advances", async () => {+ it("keeps the advanced watermark when catch-up enqueue fails", async () => {const { projectId } = await createOrgProjectAndApiKey();s3Prefix = projectId;const now = new Date();@@ -2027,7 +2024,6 @@ describe("BlobStorageIntegrationProcessingJob", () => {const getInstanceSpy = vi.spyOn(BlobStorageIntegrationProcessingQueue, "getInstance").mockReturnValue({ add } as never);- mockRecordDistribution.mockClear();try {await expect(@@ -2044,20 +2040,6 @@ describe("BlobStorageIntegrationProcessingJob", () => {twoDaysAgo.getTime() + 60 * 60 * 1000,);expect(add).toHaveBeenCalled();- expect(mockRecordDistribution).toHaveBeenCalledWith(- EXPORT_FRESHNESS_LAG_METRIC,- expect.any(Number),- expect.objectContaining({- integration: "blob_storage",- window: "1h",- status: "success",- }),- );- expect(mockRecordDistribution).not.toHaveBeenCalledWith(- EXPORT_FRESHNESS_LAG_METRIC,- expect.anything(),- expect.objectContaining({ status: "failure" }),- );} finally {getInstanceSpy.mockRestore();}diff --git a/worker/src/__tests__/exportFreshnessLagMetric.test.ts b/worker/src/__tests__/exportFreshnessLagMetric.test.tsdeleted file mode 100644index 52b4775da4..0000000000--- a/worker/src/__tests__/exportFreshnessLagMetric.test.ts+++ /dev/null@@ -1,140 +0,0 @@-import { describe, it, expect, vi, beforeEach } from "vitest";--const recordDistribution = vi.fn();-vi.mock("@langfuse/shared/src/server", () => ({- recordDistribution: (...args: unknown[]) => recordDistribution(...args),-}));--import {- recordExportFreshnessLag,- windowClassFromBlobFrequency,- EXPORT_FRESHNESS_LAG_METRIC,-} from "../services/exportFreshnessLagMetric";--describe("recordExportFreshnessLag", () => {- const runStartTime = new Date("2026-09-08T12:00:00.000Z");-- beforeEach(() => recordDistribution.mockClear());-- it("emits runStart − watermark in seconds as a distribution, without project_id", () => {- recordExportFreshnessLag({- integration: "blob_storage",- window: "20m",- status: "success",- runStartTime,- maxExportedTimestamp: new Date("2026-09-08T11:40:00.000Z"),- });-- expect(recordDistribution).toHaveBeenCalledWith(- EXPORT_FRESHNESS_LAG_METRIC,- 1200,- {- integration: "blob_storage",- window: "20m",- status: "success",- catchup: "unknown",- unit: "seconds",- },- );- expect(recordDistribution.mock.calls[0][2]).not.toHaveProperty(- "project_id",- );- expect(recordDistribution.mock.calls[0][2]).not.toHaveProperty("projectId");- });-- it("emits failing runs against the unchanged watermark so stall shows as rising lag", () => {- recordExportFreshnessLag({- integration: "posthog",- window: "1h",- status: "failure",- runStartTime,- maxExportedTimestamp: new Date("2026-09-08T06:00:00.000Z"),- });-- expect(recordDistribution).toHaveBeenCalledWith(- EXPORT_FRESHNESS_LAG_METRIC,- 6 * 60 * 60,- {- integration: "posthog",- window: "1h",- status: "failure",- catchup: "unknown",- unit: "seconds",- },- );- });-- it("tags catch-up runs true|false and omitted runs as unknown", () => {- recordExportFreshnessLag({- integration: "blob_storage",- window: "20m",- status: "success",- runStartTime,- maxExportedTimestamp: new Date("2026-09-08T11:40:00.000Z"),- catchup: true,- });- recordExportFreshnessLag({- integration: "blob_storage",- window: "20m",- status: "success",- runStartTime,- maxExportedTimestamp: new Date("2026-09-08T11:40:00.000Z"),- catchup: false,- });-- expect(recordDistribution.mock.calls[0][2]).toMatchObject({- catchup: "true",- });- expect(recordDistribution.mock.calls[1][2]).toMatchObject({- catchup: "false",- });- });-- it("skips when there is no watermark yet", () => {- recordExportFreshnessLag({- integration: "mixpanel",- window: "1h",- status: "failure",- runStartTime,- maxExportedTimestamp: null,- });- recordExportFreshnessLag({- integration: "mixpanel",- window: "1h",- status: "success",- runStartTime,- maxExportedTimestamp: undefined,- });- expect(recordDistribution).not.toHaveBeenCalled();- });-- it("clamps a watermark ahead of run start to zero", () => {- recordExportFreshnessLag({- integration: "blob_storage",- window: "1d",- status: "success",- runStartTime,- maxExportedTimestamp: new Date("2026-09-08T12:05:00.000Z"),- });- expect(recordDistribution).toHaveBeenCalledWith(- EXPORT_FRESHNESS_LAG_METRIC,- 0,- expect.objectContaining({ status: "success", window: "1d" }),- );- });-});--describe("windowClassFromBlobFrequency", () => {- it("maps configured blob cadences to window classes", () => {- expect(windowClassFromBlobFrequency("every_20_minutes")).toBe("20m");- expect(windowClassFromBlobFrequency("hourly")).toBe("1h");- expect(windowClassFromBlobFrequency("daily")).toBe("1d");- expect(windowClassFromBlobFrequency("weekly")).toBe("1w");- });-- it("rejects an unknown frequency", () => {- expect(() => windowClassFromBlobFrequency("monthly")).toThrow(- /Unsupported export frequency/,- );- });-});diff --git a/worker/src/__tests__/mixpanelIntegrationProjectJob.test.ts b/worker/src/__tests__/mixpanelIntegrationProjectJob.test.tsindex 5cd10db86a..a631f40d57 100644--- a/worker/src/__tests__/mixpanelIntegrationProjectJob.test.ts+++ b/worker/src/__tests__/mixpanelIntegrationProjectJob.test.ts@@ -128,7 +128,6 @@ vi.mock("@langfuse/shared/src/server", () => ({QueueName: { MixpanelIntegrationProcessingQueue: "mixpanel" },logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },recordIncrement: vi.fn(),- recordDistribution: vi.fn(),getCurrentSpan: vi.fn(() => undefined),getTracesForAnalyticsIntegrations: vi.fn(() => h.fakeStream("traces")),getGenerationsForAnalyticsIntegrations: vi.fn(() =>@@ -146,10 +145,7 @@ import {import {getScoresForAnalyticsIntegrations,recordIncrement,- recordDistribution,} from "@langfuse/shared/src/server";-import { decrypt } from "@langfuse/shared/encryption";-import { EXPORT_FRESHNESS_LAG_METRIC } from "../services/exportFreshnessLagMetric";import { env } from "../env";// Mirrors the real queue's defaultJobOptions (mixpanelIntegrationProcessingQueue.ts).@@ -366,26 +362,4 @@ describe("handleMixpanelIntegrationProjectJob customer-fault observability", ()expect(recordIncrement).not.toHaveBeenCalled();});-- it("emits freshness failure when decrypt throws before export work starts", async () => {- vi.mocked(decrypt).mockImplementationOnce(() => {- throw new Error("bad token");- });- vi.mocked(recordDistribution).mockClear();-- await expect(- handleMixpanelIntegrationProjectJob(makeJob()),- ).rejects.toThrow(/bad token/);-- expect(recordDistribution).toHaveBeenCalledWith(- EXPORT_FRESHNESS_LAG_METRIC,- expect.any(Number),- expect.objectContaining({- integration: "mixpanel",- window: "1h",- status: "failure",- }),- );- expect(h.mixpanelIntegrationUpdate).not.toHaveBeenCalled();- });});diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.tsindex c000b1faf4..98c114b64c 100644--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts@@ -76,10 +76,6 @@ import { SpanKind } from "@opentelemetry/api";import { env } from "../../env";import { assertExportSourceWritable } from "../exportWriteModeGuard";import { recordExportVolume } from "../../services/exportVolumeMetric";-import {- recordExportFreshnessLag,- windowClassFromBlobFrequency,-} from "../../services/exportFreshnessLagMetric";import {buildBlobExportManifest,buildBlobExportManifestKey,@@ -1306,17 +1302,6 @@ export const handleBlobStorageIntegrationProjectJob = async (lastErrorAt: null,},});- recordExportFreshnessLag({- integration: "blob_storage",- window: windowClassFromBlobFrequency(- blobStorageIntegration.exportFrequency,- ),- status: "success",- runStartTime,- maxExportedTimestamp: blobStorageIntegration.lastSyncAt,- // Empty window means nothing newer to export: fully caught up.- catchup: false,- });return;}@@ -1324,7 +1309,6 @@ export const handleBlobStorageIntegrationProjectJob = async (// self-hosted), so the deprecation notice below is Cloud-only too.const isCloud = Boolean(env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION);- let watermarkAdvanced = false;try {// The catch persists lastError and notifies admins.assertExportSourceWritable(@@ -1553,21 +1537,6 @@ export const handleBlobStorageIntegrationProjectJob = async (return;}- // The export watermark is committed. Catch-up enqueue below can still- // fail (Redis); that must not be recorded as an export-freshness failure- // against the pre-run lastSyncAt.- recordExportFreshnessLag({- integration: "blob_storage",- window: windowClassFromBlobFrequency(- blobStorageIntegration.exportFrequency,- ),- status: "success",- runStartTime,- maxExportedTimestamp: maxTimestamp,- catchup: !caughtUp,- });- watermarkAdvanced = true;-// If still catching up, immediately queue the next chunk jobif (!caughtUp) {const queue = BlobStorageIntegrationProcessingQueue.getInstance();@@ -1624,18 +1593,6 @@ export const handleBlobStorageIntegrationProjectJob = async (throw persistError;}- if (!watermarkAdvanced) {- recordExportFreshnessLag({- integration: "blob_storage",- window: windowClassFromBlobFrequency(- blobStorageIntegration.exportFrequency,- ),- status: "failure",- runStartTime,- maxExportedTimestamp: blobStorageIntegration.lastSyncAt,- });- }-// Cooldown-gated, not bypassed: the integration stays enabled and the// watermark does not advance, so every scheduled run re-attempts the same// too-large window and re-enters here. The cooldown caps this to one alert@@ -1673,18 +1630,6 @@ export const handleBlobStorageIntegrationProjectJob = async (return; // obsolete job: complete it rather than fail it}- if (!watermarkAdvanced) {- recordExportFreshnessLag({- integration: "blob_storage",- window: windowClassFromBlobFrequency(- blobStorageIntegration.exportFrequency,- ),- status: "failure",- runStartTime,- maxExportedTimestamp: blobStorageIntegration.lastSyncAt,- });- }-switch (outcome.kind) {case "disabled-by-us":// Awaited: the integration is now off, so the scheduler never revisitsdiff --git a/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts b/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.tsindex e583481019..868d384ed2 100644--- a/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts+++ b/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts@@ -14,7 +14,6 @@ import {import { decrypt } from "@langfuse/shared/encryption";import { MixpanelClient } from "./mixpanelClient";import { recordExportVolume } from "../../services/exportVolumeMetric";-import { recordExportFreshnessLag } from "../../services/exportFreshnessLagMetric";import {transformTraceForMixpanel,transformGenerationForMixpanel,@@ -250,8 +249,6 @@ export const handleMixpanelIntegrationProjectJob = async (return;}- const runStartTime = new Date();-try {// Fetch relevant data and send it to Mixpanelconst executionConfig: MixpanelExecutionConfig = {@@ -317,27 +314,10 @@ export const handleMixpanelIntegrationProjectJob = async (bytes: mixpanel.getSerializedBytes(),projectId,});- recordExportFreshnessLag({- integration: "mixpanel",- window: "1h",- status: "success",- runStartTime,- maxExportedTimestamp: executionConfig.maxTimestamp,- // maxTimestamp is always present-minus-30min (no per-run window cap), so- // a successful run has reached the tail rather than chunking a backlog.- catchup: false,- });logger.info(`[MIXPANEL] Mixpanel integration processing complete for project ${projectId}`,);} catch (error) {- recordExportFreshnessLag({- integration: "mixpanel",- window: "1h",- status: "failure",- runStartTime,- maxExportedTimestamp: mixpanelIntegration.lastSyncAt,- });const mixpanelFaultReason = classifyCustomerFault(error);if (mixpanelFaultReason !== undefined) {recordIncrement(MIXPANEL_INTEGRATION_CUSTOMER_FAULT_METRIC, 1, {diff --git a/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts b/worker/src/features/posthog/handlePostHogIntegrationProjectJob.tsindex 6e3b5dfa3a..075705b29e 100644--- a/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts+++ b/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts@@ -28,7 +28,6 @@ import {import { decrypt } from "@langfuse/shared/encryption";import { PostHog } from "posthog-node";import { recordExportVolume } from "../../services/exportVolumeMetric";-import { recordExportFreshnessLag } from "../../services/exportFreshnessLagMetric";import { assertExportSourceWritable } from "../exportWriteModeGuard";import { classifyCustomerFault } from "../integrations/customerFaultClassification";import { isRecordNotFoundError } from "../integrations/prismaErrors";@@ -285,8 +284,6 @@ export const handlePostHogIntegrationProjectJob = async (return;}- const runStartTime = new Date();-try {// Validate PostHog hostname to prevent SSRF attacks before sending data.// Rewrap preserving { cause } so the single catch below can classify the@@ -330,14 +327,6 @@ export const handlePostHogIntegrationProjectJob = async (logger.info(`[POSTHOG] Skipping PostHog integration for project ${projectId}: empty sync window (min: ${minTimestamp.toISOString()}, max: ${maxTimestamp.toISOString()})`,);- recordExportFreshnessLag({- integration: "posthog",- window: "1h",- status: "success",- runStartTime,- maxExportedTimestamp: postHogIntegration.lastSyncAt,- catchup: false,- });return;}@@ -436,17 +425,6 @@ export const handlePostHogIntegrationProjectJob = async (bytes: executionConfig.volume.bytes,projectId,});- recordExportFreshnessLag({- integration: "posthog",- window: "1h",- status: "success",- runStartTime,- maxExportedTimestamp: executionConfig.maxTimestamp,- // maxTimestamp is capped at the next UTC day boundary, so a window that- // ends before present-day means the integration is still working- // through a backlog.- catchup: maxTimestamp < uncappedMaxTimestamp,- });logger.info(`[POSTHOG] PostHog integration processing complete for project ${projectId}`,);@@ -466,14 +444,6 @@ export const handlePostHogIntegrationProjectJob = async (error instanceof Error ? error.message : String(error)).slice(0, 1000);- recordExportFreshnessLag({- integration: "posthog",- window: "1h",- status: "failure",- runStartTime,- maxExportedTimestamp: postHogIntegration.lastSyncAt,- });-if (reason === undefined) {// Defensive fallback: every code today either classifies above and// disables (including one raised on a redirect hop, reached through thediff --git a/worker/src/services/exportFreshnessLagMetric.ts b/worker/src/services/exportFreshnessLagMetric.tsdeleted file mode 100644index 982a0d4cb3..0000000000--- a/worker/src/services/exportFreshnessLagMetric.ts+++ /dev/null@@ -1,77 +0,0 @@-import { recordDistribution } from "@langfuse/shared/src/server";--export const EXPORT_FRESHNESS_LAG_METRIC =- "langfuse.export.freshness_lag_seconds";--export type ExportFreshnessIntegration =- | "blob_storage"- | "posthog"- | "mixpanel";--export type ExportFreshnessWindow = "20m" | "1h" | "1d" | "1w";--export type ExportFreshnessStatus = "success" | "failure";--const BLOB_FREQUENCY_TO_WINDOW: Record<string, ExportFreshnessWindow> = {- every_20_minutes: "20m",- hourly: "1h",- daily: "1d",- weekly: "1w",-};--export const windowClassFromBlobFrequency = (- frequency: string,-): ExportFreshnessWindow => {- const window = BLOB_FREQUENCY_TO_WINDOW[frequency];- if (!window) {- throw new Error(`Unsupported export frequency: ${frequency}`);- }- return window;-};--/**- * Whether the run's export window was capped below present-day, i.e. the- * integration is still working through a backlog. Catch-up runs report a large- * lag by design, so the tag lets SLI queries filter them out deterministically- * instead of guessing from the P95 tail. "unknown" is emitted where a run- * failed before the window-capping fact could be determined.- */-export type ExportFreshnessCatchup = boolean | undefined;--/**- * Seconds the newest successfully-exported timestamp lags this run's start.- * On success, pass the watermark just written (this run's maxTimestamp).- * On failure, pass the unchanged lastSyncAt so lag climbs until recovery.- * First runs with no watermark yet are skipped.- *- * Pass `catchup` when the run knows whether its window was capped below- * present; omit it on failure paths that cannot determine this.- */-export const recordExportFreshnessLag = ({- integration,- window,- status,- runStartTime,- maxExportedTimestamp,- catchup,-}: {- integration: ExportFreshnessIntegration;- window: ExportFreshnessWindow;- status: ExportFreshnessStatus;- runStartTime: Date;- maxExportedTimestamp: Date | null | undefined;- catchup?: ExportFreshnessCatchup;-}): void => {- if (!maxExportedTimestamp) {- return;- }- const lagSeconds =- (runStartTime.getTime() - maxExportedTimestamp.getTime()) / 1000;- recordDistribution(EXPORT_FRESHNESS_LAG_METRIC, Math.max(0, lagSeconds), {- integration,- window,- status,- catchup: catchup === undefined ? "unknown" : String(catchup),- unit: "seconds",- });-};