: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 org-gated tag values 403 instead of failing sync (#70425)
Tom Owers12d08eef0a96
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 2db54e48e3dc..180cb2669f93 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@@ -404,8 +404,7 @@ def _iter_issue_tag_values_rows(# (issue, tag) values endpoint — seen on tags with unusual# keys/values. Retries are already exhausted by# _request_with_retry, so skip this tag's remaining values- # rather than failing the whole sync. Non-server errors- # (auth, etc.) still propagate to the job-level handler.+ # rather than failing the whole sync.if response.status_code >= 500:logger.warning("sentry_source.issue_tag_values_server_error_skipped",@@ -415,6 +414,21 @@ def _iter_issue_tag_values_rows(status_code=response.status_code,)break+ # Sentry gates individual tag values endpoints at the org level+ # (data-scrubbing/privacy settings, restricted tags), returning+ # 403 even for tokens that just listed the issue's tags. Skip the+ # tag rather than failing the sync — a genuine scope problem would+ # already have surfaced on the issues/tags listing above.+ if response.status_code == 403:+ logger.warning(+ "sentry_source.issue_tag_values_forbidden_skipped",+ organization_slug=organization_slug,+ issue_id=issue_id,+ tag_key=tag_key,+ status_code=response.status_code,+ )+ break+ # Other client errors (401, etc.) still propagate to the job-level handler.raisetry: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 96414b5d3dd7..e429154a3b66 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@@ -591,15 +591,45 @@ class TestSentrySourceValidation:assert rows == [{"value": "Chrome", "issue_id": "100", "tag_key": "browser"}]@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")- def test_issue_tag_values_propagates_client_error(self, mock_request) -> None:+ def test_issue_tag_values_skips_tag_on_forbidden(self, mock_request) -> None:+ def side_effect(url, headers=None, params=None, timeout=None):+ if url.endswith("/organizations/acme/issues/"):+ return _response([{"id": "100"}])+ if url.endswith("/organizations/acme/issues/100/tags/"):+ return _response([{"key": "dart.name"}, {"key": "browser"}])+ if url.endswith("/organizations/acme/issues/100/tags/dart.name/values/"):+ # Sentry gates this tag's values at the org level (data scrubbing).+ return _response(None, status_code=403)+ if url.endswith("/organizations/acme/issues/100/tags/browser/values/"):+ return _response([{"value": "Chrome"}])+ return _response([])++ mock_request.side_effect = side_effect++ resp = sentry_source(+ auth_token="token",+ organization_slug="acme",+ api_base_url="https://sentry.io",+ endpoint="issue_tag_values",+ team_id=123,+ job_id="job-id",+ )++ # The 403 on the gated tag is skipped; the healthy "browser" tag still+ # yields its values instead of the whole sync failing.+ rows = list(cast(Any, resp.items()))+ assert rows == [{"value": "Chrome", "issue_id": "100", "tag_key": "browser"}]++ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")+ def test_issue_tag_values_propagates_non_forbidden_client_error(self, mock_request) -> None:def side_effect(url, headers=None, params=None, timeout=None):if url.endswith("/organizations/acme/issues/"):return _response([{"id": "100"}])if url.endswith("/organizations/acme/issues/100/tags/"):return _response([{"key": "browser"}])if url.endswith("/organizations/acme/issues/100/tags/browser/values/"):- # A 4xx is not a transient upstream blip — it must still propagate.- return _response(None, status_code=403)+ # A revoked token (401) is a genuine failure — it must still propagate.+ return _response(None, status_code=401)return _response([])mock_request.side_effect = side_effect