: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 pages with unparseable 2xx bodies (#68684)
Tom Owersc1fa9b1c50da
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 16973b680b90..2db54e48e3dc 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@@ -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 HTTPError, RequestException+from requests.exceptions import HTTPError, JSONDecodeError, RequestExceptionfrom tenacity import RetryCallState, retry, retry_if_exception_type, retry_if_result, stop_after_attemptfrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceResponse@@ -416,7 +416,22 @@ def _iter_issue_tag_values_rows()breakraise- rows = response.json()++ try:+ rows = response.json()+ except JSONDecodeError:+ # Sentry occasionally returns a 2xx with an empty/unparseable+ # body for a single (issue, tag) values page. Skip this tag's+ # remaining values rather than crashing the whole sync — same+ # graceful-skip as the persistent 5xx case above.+ logger.warning(+ "sentry_source.issue_tag_values_invalid_json_skipped",+ organization_slug=organization_slug,+ issue_id=issue_id,+ tag_key=tag_key,+ status_code=response.status_code,+ )+ breakshould_stop = Falsefor row in rows: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 2e0a7b351424..96414b5d3dd7 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@@ -5,7 +5,7 @@ import pytestfrom unittest.mock import Mock, patchfrom parameterized import parameterized-from requests.exceptions import HTTPError+from requests.exceptions import HTTPError, JSONDecodeErrorfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import SentrySourceConfig@@ -558,6 +558,38 @@ class TestSentrySourceValidation: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_skips_tag_on_unparseable_ok_body(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 returns a 200 with an empty/unparseable body for this tag.+ bad = _response([])+ bad.json.side_effect = JSONDecodeError("Expecting value", "", 0)+ return bad+ 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 unparseable 200 on the "bad tag" values endpoint is skipped; the+ # healthy "browser" tag still yields its values instead of crashing.+ 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_client_error(self, mock_request) -> None:def side_effect(url, headers=None, params=None, timeout=None):