:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(data-warehouse): emit delta revival and vacuum telemetry events (#69283)
Tom Owers1713413a0696
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.pyindex d1032e31cfe9..a9abb96043d6 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py@@ -11,6 +11,7 @@ from temporalio import activityfrom posthog.exceptions_capture import capture_exceptionfrom posthog.redis import get_async_clientfrom posthog.sync import database_sync_to_async_pool+from posthog.utils import get_machine_idfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.common.load import get_incremental_field_valuefrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.cdp_producer import CDPProducer@@ -276,6 +277,29 @@ async def handle_reset_or_full_refresh(await database_sync_to_async_pool(schema.update_sync_type_config_for_reset_pipeline)()+def _capture_delta_revived(+ schema: "ExternalDataSchema", job: "ExternalDataJob", *, outcome: str, made_non_billable: bool+) -> None:+ """Emit a `warehouse_delta_revived` event so corrupt-log recoveries are observable (how many, salvaged+ vs reset+rebuild, and whether the rebuild was made non-billable). Best-effort — never blocks the sync."""+ try:+ posthoganalytics.capture(+ distinct_id=get_machine_id(),+ event="warehouse_delta_revived",+ properties={+ "team_id": schema.team_id,+ "schema_id": str(schema.id),+ "source_id": str(schema.source_id),+ "resource_name": schema.name,+ "job_id": str(job.id),+ "outcome": outcome,+ "made_non_billable": made_non_billable,+ },+ )+ except Exception as e:+ capture_exception(e)++async def handle_corrupted_delta_log(schema: "ExternalDataSchema",job: "ExternalDataJob",@@ -340,6 +364,7 @@ async def handle_corrupted_delta_log(f"handle_corrupted_delta_log: salvaged from interrupted swap schema_id={schema.id}",schema_id=str(schema.id),)+ _capture_delta_revived(schema, job, outcome="salvaged", made_non_billable=False)return Trueexcept Exception as e:capture_exception(e)@@ -355,10 +380,12 @@ async def handle_corrupted_delta_log(await database_sync_to_async_pool(update_sync_type_config_keys)(schema.id, schema.team_id, removes=["repartition_pending", "repartition_swap"])+ was_billable = bool(job.billable)if job.billable:job.billable = Falseawait database_sync_to_async_pool(job.save)(update_fields=["billable"])+ _capture_delta_revived(schema, job, outcome="reset_rebuild", made_non_billable=was_billable)await logger.awarning(f"handle_corrupted_delta_log: reset corrupt table for non-billable rebuild schema_id={schema.id}",schema_id=str(schema.id),diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.pyindex 807936fda15b..506a7a36c491 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py@@ -137,12 +137,14 @@ class TestHandleCorruptedDeltaLog:schema, job = self._schema_and_job(team)helper = MagicMock(is_table_corrupted=AsyncMock(return_value=False), reset_table=AsyncMock())- result = async_to_sync(handle_corrupted_delta_log)(schema, job, helper, self._logger())+ with patch(f"{_EXTRACT_MODULE}.posthoganalytics") as ph:+ result = async_to_sync(handle_corrupted_delta_log)(schema, job, helper, self._logger())assert result is Falsehelper.reset_table.assert_not_awaited()job.refresh_from_db()assert job.billable is True+ ph.capture.assert_not_called() # no revival event for a healthy tabledef test_corrupt_table_without_salvage_resets_non_billable(self, team):# A corrupt table with no recoverable repartition swap is reset for an in-run rebuild, and the job@@ -150,12 +152,17 @@ class TestHandleCorruptedDeltaLog:schema, job = self._schema_and_job(team) # sync_type_config has no repartition_swap → no salvage pathhelper = MagicMock(is_table_corrupted=AsyncMock(return_value=True), reset_table=AsyncMock())- result = async_to_sync(handle_corrupted_delta_log)(schema, job, helper, self._logger())+ with patch(f"{_EXTRACT_MODULE}.posthoganalytics") as ph:+ result = async_to_sync(handle_corrupted_delta_log)(schema, job, helper, self._logger())assert result is Truehelper.reset_table.assert_awaited_once()job.refresh_from_db()assert job.billable is False+ # A revival must be observable, tagged with how it recovered and that the rebuild was made non-billable.+ assert ph.capture.call_args.kwargs["event"] == "warehouse_delta_revived"+ assert ph.capture.call_args.kwargs["properties"]["outcome"] == "reset_rebuild"+ assert ph.capture.call_args.kwargs["properties"]["made_non_billable"] is Truedef test_corrupt_table_with_ready_swap_is_salvaged(self, team):# A corrupt table whose interrupted repartition swap left a `ready` temp table is finished from temp@@ -180,6 +187,7 @@ class TestHandleCorruptedDeltaLog:with (patch(f"{repartition_module}._resume_swap_with_missing_live", resume),patch(f"{repartition_table_module}._target_from_schema", return_value=MagicMock()),+ patch(f"{_EXTRACT_MODULE}.posthoganalytics") as ph,):result = async_to_sync(handle_corrupted_delta_log)(schema, job, helper, self._logger())@@ -188,3 +196,7 @@ class TestHandleCorruptedDeltaLog:helper.reset_table.assert_not_awaited()job.refresh_from_db()assert job.billable is True+ # A salvage must be observable too, tagged as recovered-from-temp with the rebuild left billable.+ assert ph.capture.call_args.kwargs["event"] == "warehouse_delta_revived"+ assert ph.capture.call_args.kwargs["properties"]["outcome"] == "salvaged"+ assert ph.capture.call_args.kwargs["properties"]["made_non_billable"] is Falsediff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.pyindex 5a281f3e9eeb..555df882487a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/delta_table_helper.py@@ -9,12 +9,14 @@ import numpy as npimport pyarrow as paimport deltalake as deltalakeimport pyarrow.compute as pc+import posthoganalyticsimport deltalake.exceptionsfrom dlt.common.libs.deltalake import ensure_delta_compatible_arrow_schemafrom structlog.types import FilteringBoundLoggerfrom posthog.exceptions_capture import capture_exceptionfrom posthog.sync import database_sync_to_async_pool+from posthog.utils import get_machine_idfrom products.data_warehouse.backend.facade.api import aget_s3_client, ensure_bucket_existsfrom products.warehouse_sources.backend.models.external_data_job import ExternalDataJob@@ -733,6 +735,23 @@ class DeltaTableHelper:f"vacuum_if_stale: {commits_since} commits since last vacuum (>= {commit_threshold}), vacuuming")await self.vacuum_table()+ try:+ # Observability for the maintenance path — how often tables vacuum and how much log churn+ # accrued between vacuums. Best-effort: telemetry must never break the sync.+ posthoganalytics.capture(+ distinct_id=get_machine_id(),+ event="warehouse_delta_vacuumed",+ properties={+ "team_id": self._job.team_id,+ "schema_id": str(self._job.schema_id),+ "source_id": str(self._job.pipeline_id),+ "resource_name": self._resource_name,+ "commits_since_last_vacuum": commits_since,+ "delta_version": version,+ },+ )+ except Exception as e:+ capture_exception(e)return versionasync def compact_if_fragmented(diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.pyindex 56871ff8f15f..b49cb0286b71 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_delta_table_helper.py@@ -728,17 +728,23 @@ class TestVacuumIfStale:async def test_vacuum_cadence(self, _name: str, last_version: int | None, expect_vacuum: bool, expected_return: int | None):+ module = "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.delta_table_helper"helper = self._helper()table = MagicMock()table.version = MagicMock(return_value=150)with (patch.object(helper, "get_delta_table", new=AsyncMock(return_value=table)),patch.object(helper, "vacuum_table", new=AsyncMock()) as vacuum,+ patch(f"{module}.posthoganalytics") as ph,):result = await helper.vacuum_if_stale(last_version, 100)assert result == expected_returnassert vacuum.await_count == (1 if expect_vacuum else 0)+ # The observability event fires exactly when a vacuum runs — not on seed/skip — so the cadence is measurable.+ assert ph.capture.call_count == (1 if expect_vacuum else 0)+ if expect_vacuum:+ assert ph.capture.call_args.kwargs["event"] == "warehouse_delta_vacuumed"class TestRunMaintenance: