: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): request a clamped window for the org stats summary (#79517)
Tom Owerseab41ff57e6e
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 e38b8c7b9a09..6902670b90cd 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@@ -715,12 +715,16 @@ def _iter_organization_stats_summary_rows(organization_slug: str,) -> Iterator[dict[str, Any]]:"""Per-project event volume for the retention window, one row per project per category."""+ # A relative statsPeriod of the full retention length lands on the retention boundary, which+ # Sentry rejects with a 400. Send an explicit clamped window instead, matching the other stats+ # endpoints (see organization_stats).+ window = _retention_window()try:payload = _fetch_json(base_api_url,_endpoint_path("organization_stats_summary", organization_slug=organization_slug),headers,- {"field": "sum(quantity)", "statsPeriod": f"{SENTRY_RETENTION_DAYS}d"},+ {"field": "sum(quantity)", "start": window.start, "end": window.end},)except HTTPError as exc:response = exc.responsediff --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 0ff997cce148..abe85426014e 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@@ -1478,6 +1478,33 @@ class TestSentryCustomIteratorEndpoints:assert rows[0]["period_start"] == "2026-01-01T00:00:00Z"assert rows[0]["period_end"] == "2026-03-01T00:00:00Z"+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")+ def test_stats_summary_requests_a_clamped_window_not_a_boundary_stats_period(self, mock_request) -> None:+ # A relative statsPeriod of the full retention length lands on the retention boundary,+ # which Sentry rejects with a 400 — the request must send an explicit clamped window.+ seen_params: list[dict | None] = []++ def side_effect(url, headers=None, params=None, timeout=None):+ seen_params.append(params)+ return _response({"start": "s", "end": "e", "projects": []})++ mock_request.side_effect = side_effect++ resp = sentry_source(+ auth_token="token",+ organization_slug="acme",+ api_base_url="https://sentry.io",+ endpoint="organization_stats_summary",+ team_id=123,+ job_id="job-id",+ )++ list(cast(Any, resp.items()))++ assert seen_params[0] is not None+ assert "statsPeriod" not in seen_params[0]+ assert seen_params[0]["start"] and seen_params[0]["end"]+@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry._request_with_retry")def test_stats_summary_skips_when_token_has_no_project_access(self, mock_request) -> None:# The requesting token's user can be a member of the org without being a