: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): stop burning jobs on a rejected stats-summary request (#80099)
Tom Owers196e5d81c8d1
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 6902670b90cd..6c21a3921f5b 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@@ -580,6 +580,22 @@ _MISSING_PROJECT_RESOURCE_STATUSES = (403, 404)# project membership in the org, even though the token itself is otherwise valid._NO_PROJECTS_AVAILABLE_DETAIL = "No projects available"+# Any other 400 from the stats-summary endpoint is a deterministic rejection of the request we+# build (most often the requested window falling outside the org's plan retention), so retrying+# replays it identically. Surface a credential-safe message the source classifies as non-retryable+# (see `SentrySource.get_non_retryable_errors`) instead of burning retries on the raw HTTPError,+# whose URL embeds the org slug. The wording never interpolates the org, URL, or response body.+STATS_SUMMARY_REJECTED_MESSAGE = (+ "Sentry rejected PostHog's request for your per-project usage stats (the "+ "organization_stats_summary table) with an HTTP 400. This usually means the requested date "+ "range is outside your Sentry plan's data retention. Remove that table from this source's "+ "selected tables, then re-enable the sync."+)+++class SentryStatsSummaryRejectedError(Exception):+ """The stats-summary endpoint rejected our request with a non-recoverable 400."""+def _iter_rows_tolerating_unavailable(rows: Iterator[dict[str, Any]],@@ -742,6 +758,7 @@ def _iter_organization_stats_summary_rows(organization_slug=organization_slug,)return+ raise SentryStatsSummaryRejectedError(STATS_SUMMARY_REJECTED_MESSAGE) from excraiseperiod_start = payload.get("start")diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/source.pyindex 45574aef671f..efdff99ed413 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/source.py@@ -21,6 +21,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.schfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputs, SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.sentry import SentrySourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry import (+ STATS_SUMMARY_REJECTED_MESSAGE,SentryResumeConfig,_normalize_organization_slug,sentry_source,@@ -122,6 +123,10 @@ class SentrySource(ResumableSource[SentrySourceConfig, SentryResumeConfig]):+ ", ".join(REQUIRED_SENTRY_SCOPES)+ ".","404 Client Error": "Sentry organization not found. Verify your organization slug.",+ # Raised as `SentryStatsSummaryRejectedError` for any stats-summary 400 other than the+ # skipped no-projects case (see sentry.py). Deterministic for the request we build, so+ # stop retrying; the message is defined at the raise site so it stays credential-safe.+ STATS_SUMMARY_REJECTED_MESSAGE: None,}def get_schemas(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 abe85426014e..f7c89ca8842d 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@@ -7,11 +7,13 @@ from unittest.mock import Mock, patchfrom parameterized import parameterizedfrom requests.exceptions import HTTPError, JSONDecodeError+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matchesfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.sentry import SentrySourceConfigfrom products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry import (SentryPaginator,SentryResumeConfig,+ SentryStatsSummaryRejectedError,_custom_endpoint_rows,_normalize_api_base_url,_normalize_organization_slug,@@ -1524,7 +1526,10 @@ class TestSentryCustomIteratorEndpoints:assert list(cast(Any, resp.items())) == []@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")- def test_stats_summary_propagates_other_400_errors(self, mock_request) -> None:+ def test_stats_summary_other_400_is_classified_non_retryable(self, mock_request) -> None:+ # Any stats-summary 400 that isn't the skipped no-projects case is deterministic, so it must+ # fail fast with a credential-safe message the source classifies non-retryable — not burn+ # retries on the raw HTTPError (whose URL embeds the org slug).mock_request.return_value = _response({"detail": 'Invalid field: "bogus"'}, status_code=400)resp = sentry_source(@@ -1536,9 +1541,13 @@ class TestSentryCustomIteratorEndpoints:job_id="job-id",)- with pytest.raises(HTTPError):+ with pytest.raises(SentryStatsSummaryRejectedError) as exc_info:list(cast(Any, resp.items()))+ message = str(exc_info.value)+ assert "acme" not in message and "sentry.io" not in message+ assert error_message_matches(message, SentrySource().get_non_retryable_errors())+@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")def test_trace_item_attributes_stamps_dataset_and_skips_unavailable_ones(self, mock_request) -> None:def side_effect(url, headers=None, params=None, timeout=None):