Skip to content

: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.

fix(google_search_console): classify sitemaps/sites 5xx as retryable (#114730)

Tom Owersc16b852b2004
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py
index 0e360e05133f..fe6b7adf9628 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/google_search_console.py
@@ -110,6 +110,17 @@ class GoogleSearchConsoleQuotaExceededError(Exception):
"""
+class GoogleSearchConsoleServerError(Exception):
+ """Raised when listing sites/sitemaps hits a transient Google-side 5xx.
+
+ Unlike `_query_search_analytics`, `list_sites`/`list_sitemaps` have no inline retry
+ budget, so a 5xx otherwise reaches `get_non_retryable_errors`/error tracking as a bare
+ HTTPError. Its messages carry a `(retryable)` marker that `get_retryable_errors`
+ matches, so Temporal retries the activity and the self-recovering failure is logged as
+ a warning instead of tracked as noise.
+ """
+
+
@dataclasses.dataclass
class GoogleSearchConsoleResumeConfig:
current_date: str # ISO date currently being fetched
@@ -649,6 +660,13 @@ def _property_rows(
raise GoogleSearchConsoleQuotaExceededError(
f"Search Console quota exhausted while listing {resource_name}; the next sync picks it up (retryable)"
) from e
+ # A transient Google-side 5xx, same class `_query_search_analytics` retries inline — these
+ # two calls have no inline retry budget of their own, so mark it the same way rather than
+ # letting a bare HTTPError fall through and get logged as an exception.
+ if e.response is not None and _is_server_error(e.response):
+ raise GoogleSearchConsoleServerError(
+ f"Google Search Console server error while listing {resource_name}; retrying (retryable)"
+ ) from e
raise
if rows:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py
index dcbf8ea43ff3..1da4f9113ebf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_search_console/tests/test_google_search_console.py
@@ -19,6 +19,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.google_sea
QUOTA_MAX_RETRIES,
GoogleSearchConsoleQuotaExceededError,
GoogleSearchConsoleResumeConfig,
+ GoogleSearchConsoleServerError,
_credentials,
_get_integration,
_initial_start_date,
@@ -778,3 +779,27 @@ def test_property_listing_separates_quota_from_permission_denial(
with pytest.raises(expected_error, match=expected_match):
list(response.items()) # type: ignore[arg-type]
+
+
[email protected]("resource_name", ["sites", "sitemaps"])
+def test_property_listing_marks_server_error_retryable(monkeypatch, resource_name):
+ # `list_sites`/`list_sitemaps` have no inline retry budget, so a bare Google-side 5xx used to
+ # reach `get_non_retryable_errors` as an unmarked HTTPError and get reported as an exception
+ # even though Temporal retries it anyway.
+ config = GoogleSearchConsoleSourceConfig(
+ site_url="https://example.com/",
+ google_search_console_integration_id=1,
+ )
+ session = mock.MagicMock()
+ session.get.return_value = _fake_response(500)
+ monkeypatch.setattr(gsc, "google_search_console_session", lambda *a, **kw: session)
+
+ response = google_search_console_source(
+ config=config,
+ resource_name=resource_name,
+ team_id=1,
+ resumable_source_manager=mock.MagicMock(),
+ )
+
+ with pytest.raises(GoogleSearchConsoleServerError, match=r"\(retryable\)"):
+ list(response.items()) # type: ignore[arg-type]