: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): add log breadcrumb if no change for a schema via cdc sync (#64332)
Luke Belton18fb42378954
diff --git a/posthog/temporal/data_imports/cdc/activities.py b/posthog/temporal/data_imports/cdc/activities.pyindex 88188e1d4100..8763d7159ff8 100644--- a/posthog/temporal/data_imports/cdc/activities.py+++ b/posthog/temporal/data_imports/cdc/activities.py@@ -896,11 +896,15 @@ class CDCExtractActivity:def _finalize_success(self) -> None:now = dt.datetime.now(tz=dt.UTC)+ synced_tables = {tracker.table_name for tracker in self.write_trackers.values()}for schema in self.cdc_schemas:schema.status = ExternalDataSchema.Status.COMPLETEDschema.latest_error = Noneschema.last_synced_at = nowschema.save(update_fields=["status", "latest_error", "last_synced_at", "updated_at"])+ # Breadcrumb for idle tables; _handle_no_changes only covers the whole-source-quiet case.+ if schema.name not in synced_tables:+ self._schema_log(schema).info("cdc_extract_no_changes")@activity.defndiff --git a/posthog/temporal/data_imports/cdc/tests/test_extract_activity.py b/posthog/temporal/data_imports/cdc/tests/test_extract_activity.pyindex cf57fae34e83..311588fe2a7e 100644--- a/posthog/temporal/data_imports/cdc/tests/test_extract_activity.py+++ b/posthog/temporal/data_imports/cdc/tests/test_extract_activity.py@@ -818,6 +818,59 @@ class TestCDCExtractActivity:# Slot should advance to the last event's positionmock_reader.confirm_position.assert_called_once_with("0/300")+ @patch("posthog.temporal.data_imports.cdc.activities.activity")+ @patch("posthog.temporal.data_imports.cdc.activities.PostgresProducer")+ @patch("posthog.temporal.data_imports.cdc.activities.S3BatchWriter")+ @patch("posthog.temporal.data_imports.cdc.activities.get_cdc_adapter")+ @patch.object(CDCExtractActivity, "_get_cdc_schemas")+ @patch("posthog.temporal.data_imports.cdc.activities.ExternalDataSource")+ @patch("posthog.temporal.data_imports.cdc.activities.ExternalDataJob")+ @patch("posthog.temporal.data_imports.cdc.activities.close_old_connections")+ def test_unchanged_sibling_table_logs_no_changes_breadcrumb(+ self,+ mock_close_conns,+ MockJob,+ MockSourceModel,+ mock_get_schemas,+ mock_get_adapter,+ MockS3Writer,+ MockProducer,+ mock_activity,+ ):+ source = _make_source()+ users_schema = _make_schema("users", cdc_mode="streaming", source=source)+ orders_schema = _make_schema("orders", cdc_mode="streaming", source=source)+ # Only `users` changes this run; `orders` is idle.+ events = [_make_event(op="I", table="users", position="0/100", columns={"id": 1, "name": "Alice"})]++ _setup_mocks(+ mock_activity,+ MockProducer,+ MockS3Writer,+ mock_get_adapter,+ mock_get_schemas,+ MockSourceModel,+ MockJob,+ mock_close_conns,+ source,+ [users_schema, orders_schema],+ events,+ )++ schema_loggers: dict[str, MagicMock] = {}++ def fake_schema_log(schema):+ return schema_loggers.setdefault(schema.name, MagicMock())++ with patch.object(CDCExtractActivity, "_schema_log", side_effect=fake_schema_log):+ cdc_extract_activity(CDCExtractInput(team_id=1, source_id=source.id))++ def logged_events(name: str) -> list[str]:+ return [call.args[0] for call in schema_loggers[name].info.call_args_list]++ assert "cdc_extract_no_changes" in logged_events("orders")+ assert "cdc_extract_no_changes" not in logged_events("users")+@patch("posthog.temporal.data_imports.cdc.activities.unpause_external_data_schedule", create=True)@patch("posthog.temporal.data_imports.cdc.activities.activity")@patch("posthog.temporal.data_imports.cdc.activities.PostgresProducer")