: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): attach source/schema context to person-property sync failures (#89685)
Tom Owersf753b98743a7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/person_property_sync_job.py b/products/warehouse_sources/backend/temporal/data_imports/person_property_sync_job.pyindex b4e4485ff943..8d36e6b228af 100644--- a/products/warehouse_sources/backend/temporal/data_imports/person_property_sync_job.py+++ b/products/warehouse_sources/backend/temporal/data_imports/person_property_sync_job.py@@ -84,7 +84,7 @@ async def sync_warehouse_person_properties_activity(inputs: PersonPropertySyncAc# tracking rather than dying silently in an abandoned child workflow.PERSON_PROPERTY_SYNC_TOTAL.labels(team_id=str(inputs.team_id), outcome="failed").inc()log.exception("Person-property sync failed")- capture_exception(e)+ capture_exception(e, inputs.properties_to_log)await record_failed_runs(team_id=inputs.team_id,binding=binding,diff --git a/products/warehouse_sources/backend/temporal/data_imports/person_property_sync_job_test.py b/products/warehouse_sources/backend/temporal/data_imports/person_property_sync_job_test.pynew file mode 100644index 000000000000..859715381e44--- /dev/null+++ b/products/warehouse_sources/backend/temporal/data_imports/person_property_sync_job_test.py@@ -0,0 +1,56 @@+import uuid++import pytest+from unittest.mock import AsyncMock, MagicMock, patch++from temporalio.testing import ActivityEnvironment++from products.warehouse_sources.backend.temporal.data_imports.external_product_hooks import (+ PersonPropertySyncActivityInputs,+)+from products.warehouse_sources.backend.temporal.data_imports.person_property_sync_job import (+ sync_warehouse_person_properties_activity,+)++MODULE = "products.warehouse_sources.backend.temporal.data_imports.person_property_sync_job"+++class TestSyncWarehousePersonPropertiesActivityCapturesFailureContext:+ """A failed run is only attributable to a source/schema in error tracking if the captured+ exception carries that context; a bare capture_exception(e) loses it."""++ @patch(f"{MODULE}.capture_exception")+ @patch(f"{MODULE}.record_failed_runs", new_callable=AsyncMock)+ @patch(f"{MODULE}.record_started_runs", new_callable=AsyncMock)+ @patch(f"{MODULE}.run_person_property_sync", new_callable=AsyncMock)+ @patch(f"{MODULE}.Heartbeater")+ async def test_capture_exception_receives_source_and_schema_context(+ self,+ mock_heartbeater_cls: MagicMock,+ mock_run_sync: AsyncMock,+ _mock_record_started: AsyncMock,+ _mock_record_failed: AsyncMock,+ mock_capture_exception: MagicMock,+ ) -> None:+ mock_heartbeater_cls.return_value.__aenter__ = AsyncMock(return_value=None)+ mock_heartbeater_cls.return_value.__aexit__ = AsyncMock(return_value=None)+ error = ConnectionError("failed to connect to all addresses")+ mock_run_sync.side_effect = error++ inputs = PersonPropertySyncActivityInputs(+ team_id=1,+ schema_id=uuid.uuid4(),+ source_id=uuid.uuid4(),+ job_id="job-1",+ source_type="Stripe",+ schema_name="public.charges",+ last_synced_at=None,+ )++ with pytest.raises(ConnectionError):+ await ActivityEnvironment().run(sync_warehouse_person_properties_activity, inputs)++ mock_capture_exception.assert_called_once_with(error, inputs.properties_to_log)+ captured_properties = mock_capture_exception.call_args[0][1]+ assert captured_properties["source_type"] == "Stripe"+ assert captured_properties["schema_name"] == "public.charges"