: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
fix(data-imports): don't report transient app-db blips in cdc setup (#80110)
Tom Owerse367c1a227cc
diff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.pyindex c8d3ba877173..ea4c03126d50 100644--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/activities.py@@ -18,7 +18,7 @@ import datetime as dtimport dataclassesfrom collections.abc import Callable-from django.db import close_old_connections+from django.db import InterfaceError, OperationalError, close_old_connectionsimport psycopgimport pyarrow as pa@@ -28,6 +28,7 @@ from temporalio import activityfrom posthog.settings import WAREHOUSE_SOURCES_DATABASE_URLfrom posthog.temporal.common.activity_context import current_workflow_id, current_workflow_run_id+from posthog.temporal.common.errors import NonReportableErrorfrom posthog.temporal.common.heartbeat_sync import HeartbeaterSyncfrom posthog.utils import get_machine_id@@ -711,8 +712,18 @@ class CDCExtractActivity:self._run_started_at = time.monotonic()self.log.info("cdc_extract_started")- if not self._setup():- return+ try:+ if not self._setup():+ return+ except (OperationalError, InterfaceError) as exc:+ # `_setup` only reads our own app DB (source + schema rows), never a customer's — every+ # CDC source is read over a raw driver connection, not Django's ORM — so this can only be+ # a transient connection-pool blip on our side (e.g. PgBouncer dropping an idle+ # connection), the same class already re-raised as `NonReportableError` for own-DB blips+ # in import_data_sync.py. Temporal's retry policy isn't `NonRetryableException`-gated+ # here, so it still retries; this only keeps a self-resolving blip out of error tracking.+ self.log.warning("cdc_setup_transient_app_db_error", exc_info=True)+ raise NonReportableError(str(exc)) from excif self._previous_load_still_pending():returndiff --git a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.pyindex 53dd4964984d..f1c69e6cf1d2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py+++ b/products/warehouse_sources/backend/temporal/data_imports/cdc/tests/test_extract_activity.py@@ -6,12 +6,14 @@ from typing import Literalimport pytestfrom unittest.mock import MagicMock, patch-from django.db.utils import OperationalError+from django.db.utils import InterfaceError, OperationalErrorimport pyarrow as paimport psycopg.errorsfrom parameterized import parameterized+from posthog.temporal.common.errors import NonReportableError+from products.warehouse_sources.backend.models.external_data_job import ExternalDataJobfrom products.warehouse_sources.backend.models.external_data_schema import ExternalDataSchemafrom products.warehouse_sources.backend.models.external_data_source import ExternalDataSource@@ -826,6 +828,37 @@ class TestCDCExtractActivity:mock_get_adapter.assert_not_called()+ @parameterized.expand([("operational", OperationalError), ("interface", InterfaceError)])+ @patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.activity")+ @patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.get_cdc_adapter")+ @patch.object(CDCExtractActivity, "_get_cdc_schemas")+ @patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.ExternalDataSource")+ @patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.close_old_connections")+ def test_setup_app_db_connection_blip_is_not_reported(+ self,+ _name,+ exception_cls,+ mock_close_conns,+ MockSourceModel,+ mock_get_schemas,+ mock_get_adapter,+ mock_activity,+ ):+ # `_setup` only reads our own app DB (never a customer's), so a dropped connection here+ # (e.g. PgBouncer closing an idle connection) is a transient blip, not a broken sync. It+ # must still be retried by Temporal, but shouldn't page as a fresh, reportable bug on+ # every attempt.+ MockSourceModel.DoesNotExist = ExternalDataSource.DoesNotExist+ MockSourceModel.objects.get.side_effect = exception_cls("server closed the connection unexpectedly")++ inputs = CDCExtractInput(team_id=1, source_id=uuid.uuid4())++ with pytest.raises(NonReportableError, match="server closed the connection unexpectedly"):+ cdc_extract_activity(inputs)++ mock_get_schemas.assert_not_called()+ mock_get_adapter.assert_not_called()+@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.activity")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.PostgresProducer")@patch("products.warehouse_sources.backend.temporal.data_imports.cdc.activities.S3BatchWriter")