: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(google_analytics): stop paging error tracking for transient GA4 metadata probe statuses (#113628)
Tom Owers1fd38ea681bf
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.pyindex e4ad6760c613..56667e20e788 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/source.py@@ -1,6 +1,7 @@from typing import Optional, castimport requests+import structlogfrom google.auth.exceptions import RefreshErrorfrom posthog.exceptions_capture import capture_exception@@ -40,6 +41,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.google_ana)from products.warehouse_sources.backend.types import ExternalDataSourceType+logger = structlog.get_logger(__name__)+# Fallback messages for unexpected failures during credential validation. The raw exception can# embed OAuth tokens, ids, or an HTML error body, so we capture it for debugging and show generic# guidance instead of surfacing `str(e)` to the user.@@ -251,6 +254,12 @@ class GoogleAnalyticsSource(ResumableSource[GoogleAnalyticsSourceConfig, GoogleAf"GA4 property '{property_id}' was not found. Verify the numeric property ID in ""Google Analytics admin settings.",)+ if status == 429 or (status is not None and 500 <= status < 600):+ # Google is rate-limiting this metadata probe or briefly unavailable — both clear on+ # their own and the status means nothing actionable for us, so log it rather than+ # paging error tracking (same call as app_store_connect's credential probe).+ logger.warning("ga4_property_metadata_probe_transient_status", status=status)+ return False, _PROPERTY_METADATA_ERRORcapture_exception(e)return False, _PROPERTY_METADATA_ERRORexcept RefreshError:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.pyindex 3df1207daf08..a4d972adf434 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_analytics/tests/test_google_analytics_source.py@@ -134,10 +134,13 @@ def _http_error(status_code: int, body: str = "") -> requests.HTTPError:"allow Google Analytics access",),(404, "", "was not found"),+ (429, "", "couldn't reach Google Analytics"),(500, "", "couldn't reach Google Analytics"),],)def test_validate_credentials_maps_http_errors(status_code, body, expected_substring):+ # None of these are bugs worth paging error tracking for: the mapped ones are user/upstream+ # errors with their own message, and 429/5xx are transient and self-resolving.with (mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.google_analytics.source.google_analytics_session"@@ -146,11 +149,15 @@ def test_validate_credentials_maps_http_errors(status_code, body, expected_subst"products.warehouse_sources.backend.temporal.data_imports.sources.google_analytics.source.get_property_metadata",side_effect=_http_error(status_code, body),),+ mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.google_analytics.source.capture_exception"+ ) as mock_capture,):ok, message = GoogleAnalyticsSource().validate_credentials(_config(), team_id=1)assert ok is Falseassert expected_substring in (message or "")+ mock_capture.assert_not_called()def test_validate_credentials_maps_token_refresh_error():