: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(warehouse-sources): skip a persistent 5xx on one sentry project_stats series (#108968)
Tom Owers74a128254b13
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.pyindex a2e4f74a66b4..c6b28630ae22 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py@@ -797,6 +797,19 @@ def _iter_issue_tag_values_rows(_UNAVAILABLE_DATASET_STATUSES = (400, 403, 404)# Per-project surfaces only ever go missing through permissions or an absent config._MISSING_PROJECT_RESOURCE_STATUSES = (403, 404)+# project_stats hits Sentry's per-project stats endpoint once per (project, stat) pair. Sentry+# occasionally returns a persistent 5xx for a single one of those after _request_with_retry's+# budget is exhausted — the same failure mode as the issue tags/tag-values endpoints (see+# _skip_issue_on_tags_server_error) — so treat it as that slice being unavailable rather than+# failing the whole schema.+_PROJECT_STATS_UNAVAILABLE_STATUSES = (+ *_MISSING_PROJECT_RESOURCE_STATUSES,+ 500,+ 502,+ 503,+ 504,+ *CLOUDFLARE_TRANSIENT_STATUSES,+)# Sentry's stats-summary endpoint 400s with this detail when the token's user has no# project membership in the org, even though the token itself is otherwise valid._NO_PROJECTS_AVAILABLE_DETAIL = "No projects available"@@ -1178,7 +1191,7 @@ def _iter_project_stats_rows(for row in _iter_rows_tolerating_unavailable(_points(project_slug, stat),"project_stats",- _MISSING_PROJECT_RESOURCE_STATUSES,+ _PROJECT_STATS_UNAVAILABLE_STATUSES,project_slug=project_slug,stat=stat,):diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.pyindex 2cabd7f073c4..188ce0005d16 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py@@ -2032,6 +2032,36 @@ class TestSentryCustomIteratorEndpoints:{"stat": "received", "timestamp": 1772496000, "value": 8, "project_id": "1", "project_slug": "web"},]+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")+ def test_project_stats_skips_stat_on_persistent_server_error(self, mock_request) -> None:+ def side_effect(url, headers=None, params=None, timeout=None):+ if url.endswith("/organizations/acme/projects/"):+ return _response([{"id": "1", "slug": "web"}])+ if (params or {}).get("stat") == "received":+ # Sentry persistently 500s for this project's "received" stat.+ return _response(None, status_code=500)+ if (params or {}).get("stat") == "generated":+ return _response([[1772409600, 12]])+ return _response([])++ mock_request.side_effect = side_effect++ resp = sentry_source(+ auth_token="token",+ organization_slug="acme",+ api_base_url="https://sentry.io",+ endpoint="project_stats",+ team_id=123,+ job_id="job-id",+ )++ # The 500 on the "received" stat (first in PROJECT_STAT_NAMES) is skipped; the+ # sync still reaches the later "generated" stat instead of stopping at the skip.+ rows = list(cast(Any, resp.items()))+ assert rows == [+ {"stat": "generated", "timestamp": 1772409600, "value": 12, "project_id": "1", "project_slug": "web"}+ ]+@parameterized.expand([("pre_retention_watermark", 946684800, True),