Skip to content

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

chore(export): tag freshness lag with catch-up state (#17899)

Niklas Semmler3b3c71610205
diff --git a/worker/src/__tests__/exportFreshnessLagMetric.test.ts b/worker/src/__tests__/exportFreshnessLagMetric.test.ts
index 4957c1ac2f..52b4775da4 100644
--- a/worker/src/__tests__/exportFreshnessLagMetric.test.ts
+++ b/worker/src/__tests__/exportFreshnessLagMetric.test.ts
@@ -32,6 +32,7 @@ describe("recordExportFreshnessLag", () => {
integration: "blob_storage",
window: "20m",
status: "success",
+ catchup: "unknown",
unit: "seconds",
},
);
@@ -57,11 +58,38 @@ describe("recordExportFreshnessLag", () => {
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",
diff --git a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
index 89b2e6fae1..5af4b290ac 100644
--- a/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
+++ b/worker/src/features/blobstorage/handleBlobStorageIntegrationProjectJob.ts
@@ -1295,6 +1295,8 @@ export const handleBlobStorageIntegrationProjectJob = async (
status: "success",
runStartTime,
maxExportedTimestamp: blobStorageIntegration.lastSyncAt,
+ // Empty window means nothing newer to export: fully caught up.
+ catchup: false,
});
return;
}
@@ -1543,6 +1545,7 @@ export const handleBlobStorageIntegrationProjectJob = async (
status: "success",
runStartTime,
maxExportedTimestamp: maxTimestamp,
+ catchup: !caughtUp,
});
watermarkAdvanced = true;
diff --git a/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts b/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts
index 9de828c236..e583481019 100644
--- a/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts
+++ b/worker/src/features/mixpanel/handleMixpanelIntegrationProjectJob.ts
@@ -323,6 +323,9 @@ export const handleMixpanelIntegrationProjectJob = async (
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}`,
diff --git a/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts b/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts
index 8c8c966c5a..6e3b5dfa3a 100644
--- a/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts
+++ b/worker/src/features/posthog/handlePostHogIntegrationProjectJob.ts
@@ -336,6 +336,7 @@ export const handlePostHogIntegrationProjectJob = async (
status: "success",
runStartTime,
maxExportedTimestamp: postHogIntegration.lastSyncAt,
+ catchup: false,
});
return;
}
@@ -441,6 +442,10 @@ export const handlePostHogIntegrationProjectJob = async (
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}`,
diff --git a/worker/src/services/exportFreshnessLagMetric.ts b/worker/src/services/exportFreshnessLagMetric.ts
index 740b2899ec..982a0d4cb3 100644
--- a/worker/src/services/exportFreshnessLagMetric.ts
+++ b/worker/src/services/exportFreshnessLagMetric.ts
@@ -29,11 +29,23 @@ export const windowClassFromBlobFrequency = (
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,
@@ -41,12 +53,14 @@ export const recordExportFreshnessLag = ({
status,
runStartTime,
maxExportedTimestamp,
+ catchup,
}: {
integration: ExportFreshnessIntegration;
window: ExportFreshnessWindow;
status: ExportFreshnessStatus;
runStartTime: Date;
maxExportedTimestamp: Date | null | undefined;
+ catchup?: ExportFreshnessCatchup;
}): void => {
if (!maxExportedTimestamp) {
return;
@@ -57,6 +71,7 @@ export const recordExportFreshnessLag = ({
integration,
window,
status,
+ catchup: catchup === undefined ? "unknown" : String(catchup),
unit: "seconds",
});
};