: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(sentry): skip a trace-item dataset on a persistent 5xx instead of failing the whole sync (#109227)
Tom Owersf9fb5a3147bd
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 c6b28630ae22..d6bbf240a0be 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@@ -795,6 +795,19 @@ def _iter_issue_tag_values_rows(# Sentry answers a request for a product surface the organization doesn't have with a# 400, so an unavailable trace item dataset is indistinguishable from a rejected param._UNAVAILABLE_DATASET_STATUSES = (400, 403, 404)+# trace_item_attributes/trace_item_stats hit the trace-items API once per dataset/item type.+# 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 project_stats (see+# _PROJECT_STATS_UNAVAILABLE_STATUSES) — so treat it as that slice being unavailable rather+# than failing the whole schema.+_TRACE_ITEM_UNAVAILABLE_STATUSES = (+ *_UNAVAILABLE_DATASET_STATUSES,+ 500,+ 502,+ 503,+ 504,+ *CLOUDFLARE_TRANSIENT_STATUSES,+)# 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@@ -1061,7 +1074,7 @@ def _iter_trace_item_attributes_rows(max_pages=_MAX_PAGES_PER_PARENT,)for row in _iter_rows_tolerating_unavailable(- rows, "trace_item_attributes", _UNAVAILABLE_DATASET_STATUSES, dataset=dataset+ rows, "trace_item_attributes", _TRACE_ITEM_UNAVAILABLE_STATUSES, dataset=dataset):row["dataset"] = datasetyield row@@ -1094,7 +1107,7 @@ def _iter_trace_item_stats_rows(for item_type in TRACE_ITEM_STATS_TYPES:yield from _iter_rows_tolerating_unavailable(- _distributions(item_type), "trace_item_stats", _UNAVAILABLE_DATASET_STATUSES, item_type=item_type+ _distributions(item_type), "trace_item_stats", _TRACE_ITEM_UNAVAILABLE_STATUSES, item_type=item_type)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 188ce0005d16..11f1439189f3 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@@ -1944,6 +1944,32 @@ class TestSentryCustomIteratorEndpoints:rows = list(cast(Any, resp.items()))assert rows == [{"key": "browser.name", "attributeType": "string", "dataset": "spans"}]+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")+ def test_trace_item_attributes_skips_dataset_on_persistent_server_error(self, mock_request) -> None:+ # A persistent 5xx for one dataset (retries already exhausted by _request_with_retry)+ # must not fail the whole endpoint — skip that dataset, like the other slices do.+ def side_effect(url, headers=None, params=None, timeout=None):+ dataset = (params or {}).get("dataset")+ if dataset == "spans":+ return _response([{"key": "browser.name", "attributeType": "string"}])+ if dataset == "logs":+ return _response(None, status_code=502)+ return _response([])++ mock_request.side_effect = side_effect++ resp = sentry_source(+ auth_token="token",+ organization_slug="acme",+ api_base_url="https://sentry.io",+ endpoint="trace_item_attributes",+ team_id=123,+ job_id="job-id",+ )++ rows = list(cast(Any, resp.items()))+ assert rows == [{"key": "browser.name", "attributeType": "string", "dataset": "spans"}]+@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")def test_trace_item_stats_flattens_attribute_distributions(self, mock_request) -> None:def side_effect(url, headers=None, params=None, timeout=None):@@ -1983,6 +2009,35 @@ class TestSentryCustomIteratorEndpoints:{"item_type": "spans", "attribute": "sentry.device", "label": "desktop", "value": 1},]+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")+ def test_trace_item_stats_skips_item_type_on_persistent_server_error(self, mock_request) -> None:+ # Same persistent-5xx graceful skip as trace_item_attributes, for the other trace-item+ # fan-out (item type instead of dataset).+ def side_effect(url, headers=None, params=None, timeout=None):+ if (params or {}).get("itemType") == "spans":+ return _response(+ {+ "data": [+ {"attributeDistributions": {"data": {"sentry.device": [{"label": "mobile", "value": 3}]}}}+ ]+ }+ )+ return _response(None, status_code=502)++ mock_request.side_effect = side_effect++ resp = sentry_source(+ auth_token="token",+ organization_slug="acme",+ api_base_url="https://sentry.io",+ endpoint="trace_item_stats",+ team_id=123,+ job_id="job-id",+ )++ rows = list(cast(Any, resp.items()))+ assert rows == [{"item_type": "spans", "attribute": "sentry.device", "label": "mobile", "value": 3}]+@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")def test_project_ownership_yields_one_row_per_project_and_skips_missing_config(self, mock_request) -> None:def side_effect(url, headers=None, params=None, timeout=None):