: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
feat(data-warehouse): add 2 missing tables to the Mixpanel source (#118785)
Tom Owersf65db4f579d7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.mdindex bbdf3ea668e2..25b508fef39b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md@@ -8043,11 +8043,11 @@ Diffed against: <https://developer.mixpanel.com/reference/query-api>- [x] `funnels query (GET /api/query/funnels — reference/funnels-query)` — funnel conversion is Mixpanel's headline metric and is entirely absent (high) — added as `funnel_steps`, fanned out over every saved funnel- [x] `saved funnels list (reference/funnels-list-saved)` — lookup table of saved funnel definitions and their IDs, required to drive the funnels query (high) — added as `funnels`- [x] `retention query (reference/retention-query)` — cohort retention, a core Mixpanel report with no equivalent today (high) — added as `retention` (compounded retention across all events, because birth retention needs a user-chosen `born_event`)-- [ ] `segmentation query (reference/segmentation-query, plus numeric/sum/average variants)` — event counts broken down by property — the main breakdown dimension API (high)+- [ ] `segmentation query (reference/segmentation-query, plus numeric/sum/average variants)` — event counts broken down by property — the main breakdown dimension API (high). Not added: each call needs one user-chosen `event` (and an `on` property for the breakdown and the numeric variants), and one query per event does not fit the Query API limit of 60 queries per hour.- [ ] `insights query (reference/insights-query)` — returns the data behind saved Insights reports (high). Not added: each call needs a report `bookmark_id`, no Query API endpoint lists saved reports, and the `series` shape varies per report.-- [ ] `Lexicon schemas (reference/list-all-schemas-for-project, list-schemas-for-entity)` — lookup table of event and property definitions that names and types everything in the export table (high)-- [ ] `lookup tables (reference/list-lookup-tables)` — literally the project's lookup tables, used to resolve IDs on synced events and profiles (high)-- [ ] `activity stream (reference/activity-stream-query)` — per-user chronological event feed joining engage profiles to their activity (medium)+- [x] `Lexicon schemas (reference/list-all-schemas-for-project, list-schemas-for-entity)` — lookup table of event and property definitions that names and types everything in the export table (high) — added as `lexicon_schemas` from the project-wide list, which already covers every entity type+- [x] `lookup tables (reference/list-lookup-tables)` — literally the project's lookup tables, used to resolve IDs on synced events and profiles (high) — added as `lookup_tables` (id and name only: the API has no endpoint that reads lookup table rows)+- [ ] `activity stream (reference/activity-stream-query)` — per-user chronological event feed joining engage profiles to their activity (medium). Not added: Mixpanel marks `stream/query` as in maintenance mode, each call needs a list of `distinct_ids` (a fan-out over every profile under the 60 queries per hour limit), and the same events are in the `export` table.- [ ] `event taxonomy queries (reference/query-top-events, query-events-top-properties, query-events-top-property-values, query-event-properties)` — dimension/cardinality tables for event and property discovery (medium)- [ ] `retention frequency query (reference/retention-frequency-query)` — addiction/frequency view complementing retention (medium)- [ ] `experiments (reference/list-experiments, get-experiment)` — experiment definitions and state, needed to attribute events to variants (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/canonical_descriptions.pyindex 5bd1ddc6c0a0..c671590a3cec 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/canonical_descriptions.py@@ -103,4 +103,21 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"first": "Number of users in the cohort.",},},+ "lexicon_schemas": {+ "description": "Lexicon data dictionary: the schema Mixpanel holds for each event and profile, with its property definitions.",+ "docs_url": "https://developer.mixpanel.com/reference/list-all-schemas-for-project",+ "columns": {+ "entityType": "Kind of entity the schema describes: event or profile.",+ "name": "Name of the entity, for example the event name.",+ "schemaJson": "Schema of the entity: its description and the type and description of each property.",+ },+ },+ "lookup_tables": {+ "description": "Lookup tables defined in the Mixpanel project, by id and name.",+ "docs_url": "https://developer.mixpanel.com/reference/list-lookup-tables",+ "columns": {+ "id": "Unique identifier (UUID) of the lookup table.",+ "name": "The lookup table's name.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.pyindex 1ef842f2571e..cee8bac2f3d4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/mixpanel.py@@ -115,6 +115,10 @@ def _export_base(region: str) -> str:return _hosts(region).export_base+def _ingestion_base(region: str) -> str:+ return _hosts(region).ingestion_base++def _export_url(region: str, api_version: str) -> str:# A pin is honored verbatim, so an unknown/future label can reach here; fall back to# Mixpanel's only raw-export path (`2.0`) rather than raising on the lookup.@@ -451,6 +455,28 @@ def _fetch_annotations(yield rows+def _fetch_lexicon_schemas(+ region: str, username: str, secret: str, project_id: str, logger: FilteringBoundLogger+) -> Iterator[list[dict[str, Any]]]:+ url = f"{_query_base(region)}/api/app/projects/{project_id}/schemas"+ response = _request("GET", url, username=username, secret=secret, logger=logger)+ data = response.json()+ rows = data.get("results", []) if isinstance(data, dict) else []+ if rows:+ yield rows+++def _fetch_lookup_tables(+ region: str, username: str, secret: str, project_id: str, logger: FilteringBoundLogger+) -> Iterator[list[dict[str, Any]]]:+ url = f"{_ingestion_base(region)}/lookup-tables"+ response = _request("GET", url, username=username, secret=secret, logger=logger, params={"project_id": project_id})+ data = response.json()+ rows = data.get("results", []) if isinstance(data, dict) else []+ if rows:+ yield rows++def _fetch_funnel_list(region: str, username: str, secret: str, project_id: str, logger: FilteringBoundLogger) -> list[dict[str, Any]]:@@ -631,6 +657,10 @@ def get_rows(yield from _fetch_cohorts(region, username, secret, project_id, logger)elif endpoint == "annotations":yield from _fetch_annotations(region, username, secret, project_id, logger)+ elif endpoint == "lexicon_schemas":+ yield from _fetch_lexicon_schemas(region, username, secret, project_id, logger)+ elif endpoint == "lookup_tables":+ yield from _fetch_lookup_tables(region, username, secret, project_id, logger)elif endpoint == "funnels":yield from _fetch_funnels(region, username, secret, project_id, logger)elif endpoint in ("funnel_steps", "retention"):diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/settings.pyindex 1d118319fb77..10f78d91e08b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/settings.py@@ -36,14 +36,27 @@ class MixpanelRegion(StrEnum):class RegionHosts:query_base: str # query/app API baseexport_base: str # raw export API base+ ingestion_base: str # ingestion API base, which also serves lookup tables# Mixpanel splits the heavy raw export traffic onto a separate `data*` host per# data-residency region.REGION_HOSTS: dict[str, RegionHosts] = {- MixpanelRegion.US: RegionHosts(query_base="https://mixpanel.com", export_base="https://data.mixpanel.com"),- MixpanelRegion.EU: RegionHosts(query_base="https://eu.mixpanel.com", export_base="https://data-eu.mixpanel.com"),- MixpanelRegion.IN: RegionHosts(query_base="https://in.mixpanel.com", export_base="https://data-in.mixpanel.com"),+ MixpanelRegion.US: RegionHosts(+ query_base="https://mixpanel.com",+ export_base="https://data.mixpanel.com",+ ingestion_base="https://api.mixpanel.com",+ ),+ MixpanelRegion.EU: RegionHosts(+ query_base="https://eu.mixpanel.com",+ export_base="https://data-eu.mixpanel.com",+ ingestion_base="https://api-eu.mixpanel.com",+ ),+ MixpanelRegion.IN: RegionHosts(+ query_base="https://in.mixpanel.com",+ export_base="https://data-in.mixpanel.com",+ ingestion_base="https://api-in.mixpanel.com",+ ),}# First sync of the raw export endpoint only pulls this far back to avoid replaying@@ -127,6 +140,17 @@ MIXPANEL_ENDPOINTS: dict[str, MixpanelEndpointConfig] = {primary_keys=["date", "interval_index"],partition_key="date",),+ # App API: Lexicon data dictionary, one row per event or profile schema. Full refresh.+ "lexicon_schemas": MixpanelEndpointConfig(+ name="lexicon_schemas",+ primary_keys=["entityType", "name"],+ ),+ # Ingestion API: lookup table ids and names. Mixpanel has no endpoint that reads the rows of a+ # lookup table, so only the list is synced. Full refresh.+ "lookup_tables": MixpanelEndpointConfig(+ name="lookup_tables",+ primary_keys=["id"],+ ),}ENDPOINTS = tuple(MIXPANEL_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.pyindex a3815426a807..58a02a0d6d5f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mixpanel/test_mixpanel.py@@ -1,5 +1,5 @@from datetime import UTC, date, datetime-from typing import Any, Optional+from typing import Any, Literal, Optionalimport pytestimport time_machine@@ -25,6 +25,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.mixpanel.mMixpanelRetryableError,_check_response,_export_base,+ _ingestion_base,_parse_retry_after,_query_base,_retry_wait,@@ -40,10 +41,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.mixpanel.sLOGGER = structlog.get_logger()-def _driver() -> SourceDriver:+def _driver(region: Literal["us", "eu", "in"] = "us") -> SourceDriver:return SourceDriver(MixpanelSource(),- MixpanelSourceConfig(project_id="123", service_account_username="u", service_account_secret="s", region="us"),+ MixpanelSourceConfig(project_id="123", service_account_username="u", service_account_secret="s", region=region),)@@ -137,15 +138,18 @@ class TestToDate:class TestRegionHosts:@parameterized.expand([- ("us", "https://mixpanel.com", "https://data.mixpanel.com"),- ("eu", "https://eu.mixpanel.com", "https://data-eu.mixpanel.com"),- ("in", "https://in.mixpanel.com", "https://data-in.mixpanel.com"),- ("unknown", "https://mixpanel.com", "https://data.mixpanel.com"),+ ("us", "https://mixpanel.com", "https://data.mixpanel.com", "https://api.mixpanel.com"),+ ("eu", "https://eu.mixpanel.com", "https://data-eu.mixpanel.com", "https://api-eu.mixpanel.com"),+ ("in", "https://in.mixpanel.com", "https://data-in.mixpanel.com", "https://api-in.mixpanel.com"),+ ("unknown", "https://mixpanel.com", "https://data.mixpanel.com", "https://api.mixpanel.com"),])- def test_region_resolution(self, region: str, expected_query: str, expected_export: str) -> None:+ def test_region_resolution(+ self, region: str, expected_query: str, expected_export: str, expected_ingestion: str+ ) -> None:assert _query_base(region) == expected_queryassert _export_base(region) == expected_export+ assert _ingestion_base(region) == expected_ingestionclass TestCheckResponse:@@ -450,6 +454,69 @@ class TestSingleRequestEndpoints:assert result.raised is Noneassert result.items == [[{"id": 5}]]+ @parameterized.expand(+ [+ (+ "lexicon_schemas_us",+ "lexicon_schemas",+ "us",+ "https://mixpanel.com/api/app/projects/123/schemas",+ None,+ [+ {+ "entityType": "event",+ "name": "Song Played",+ "schemaJson": {"properties": {"genre": {"type": "string"}}},+ }+ ],+ ),+ (+ "lexicon_schemas_eu",+ "lexicon_schemas",+ "eu",+ "https://eu.mixpanel.com/api/app/projects/123/schemas",+ None,+ [{"entityType": "profile", "name": "$user", "schemaJson": {"properties": {}}}],+ ),+ (+ "lookup_tables_us",+ "lookup_tables",+ "us",+ "https://api.mixpanel.com/lookup-tables",+ "123",+ [{"id": "00000000-0000-4000-8000-000000000001", "name": "Plans"}],+ ),+ (+ "lookup_tables_in",+ "lookup_tables",+ "in",+ "https://api-in.mixpanel.com/lookup-tables",+ "123",+ [{"id": "00000000-0000-4000-8000-000000000002", "name": "Stores"}],+ ),+ ]+ )+ def test_list_endpoints_read_results_from_the_region_host(+ self,+ _name: str,+ endpoint: str,+ region: Literal["us", "eu", "in"],+ expected_url: str,+ expected_project_param: Optional[str],+ rows: list[dict[str, Any]],+ ) -> None:+ result = _driver(region).run(endpoint, [ScriptedResponse(json={"status": "ok", "results": rows})])+ assert result.raised is None+ assert result.urls[0].split("?", 1)[0] == expected_url+ assert result.params("project_id") == [expected_project_param]+ assert result.items == [rows]++ @parameterized.expand([("lexicon_schemas",), ("lookup_tables",)])+ def test_list_endpoints_yield_nothing_for_empty_results(self, endpoint: str) -> None:+ result = _driver().run(endpoint, [ScriptedResponse(json={"status": "ok", "results": []})])+ assert result.raised is None+ assert result.items == []+class TestReportEndpoints:@pytest.fixture(autouse=True)