: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 tag values fetch on persistent server error (#63997)
Tom Owersa2c86cc1234e
diff --git a/posthog/temporal/data_imports/sources/sentry/sentry.py b/posthog/temporal/data_imports/sources/sentry/sentry.pyindex 9f453bc58caa..7474b66ff230 100644--- a/posthog/temporal/data_imports/sources/sentry/sentry.py+++ b/posthog/temporal/data_imports/sources/sentry/sentry.py@@ -8,7 +8,7 @@ from urllib.parse import quote, urljoinimport structlogfrom dateutil import parser as dateutil_parserfrom requests import Request, Response-from requests.exceptions import RequestException+from requests.exceptions import HTTPError, RequestExceptionfrom tenacity import RetryCallState, retry, retry_if_exception_type, retry_if_result, stop_after_attemptfrom posthog.temporal.data_imports.pipelines.pipeline.typings import SourceResponse@@ -400,7 +400,25 @@ def _iter_issue_tag_values_rows(breakresponse = _request_with_retry(url=values_url, headers=headers, params=values_params)- response.raise_for_status()+ try:+ response.raise_for_status()+ except HTTPError:+ # Sentry intermittently returns a persistent 5xx for a single+ # (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.+ if response.status_code >= 500:+ logger.warning(+ "sentry_source.issue_tag_values_server_error_skipped",+ organization_slug=organization_slug,+ issue_id=issue_id,+ tag_key=tag_key,+ status_code=response.status_code,+ )+ break+ raiserows = response.json()should_stop = Falsediff --git a/posthog/temporal/data_imports/sources/sentry/tests/test_sentry.py b/posthog/temporal/data_imports/sources/sentry/tests/test_sentry.pyindex 41d20b1264e6..bba1650b617f 100644--- a/posthog/temporal/data_imports/sources/sentry/tests/test_sentry.py+++ b/posthog/temporal/data_imports/sources/sentry/tests/test_sentry.py@@ -5,6 +5,7 @@ import pytestfrom unittest.mock import Mock, patchfrom parameterized import parameterized+from requests.exceptions import HTTPErrorfrom posthog.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom posthog.temporal.data_imports.sources.generated_configs import SentrySourceConfig@@ -31,7 +32,7 @@ def _response(payload, status_code: int = 200, link_header: str = "") -> Mock:def _raise_for_status() -> None:if status_code >= 400:- raise Exception(f"{status_code} client error")+ raise HTTPError(f"{status_code} Server Error", response=response)response.raise_for_status = _raise_for_statusreturn response@@ -442,6 +443,64 @@ class TestSentrySourceValidation:{"value": "Chrome", "lastSeen": "2026-03-05T12:00:00Z", "issue_id": "100", "tag_key": "browser"}]+ # Patch _request_with_retry directly so the test exercises the iterator's+ # skip logic without incurring the real (post-exhaustion) retry sleeps.+ @patch("posthog.temporal.data_imports.sources.sentry.sentry._request_with_retry")+ def test_issue_tag_values_skips_tag_on_persistent_server_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": "bad tag"}, {"key": "browser"}])+ if "tags/bad%20tag/values/" in url:+ # Sentry persistently 500s for this tag's values endpoint.+ return _response(None, status_code=500)+ 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 500 on the "bad tag" values endpoint is skipped; the healthy+ # "browser" tag still yields its values instead of the whole sync crashing.+ rows = list(cast(Any, resp.items()))+ assert rows == [{"value": "Chrome", "issue_id": "100", "tag_key": "browser"}]++ @patch("posthog.temporal.data_imports.sources.sentry.sentry._request_with_retry")+ def test_issue_tag_values_propagates_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)+ 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",+ )++ with pytest.raises(HTTPError):+ list(cast(Any, resp.items()))+class TestSentrySourceResumable:"""Resume behaviour for flat endpoints (rest_api_resource path)."""