Skip to content

: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.

fix(sentry): classify rate-limit errors as retryable (#92675)

Tom Owers6c549463108e
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.py
index 1c42fd2789ac..8b2738346696 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
@@ -134,13 +134,16 @@ class SentrySource(ResumableSource[SentrySourceConfig, SentryResumeConfig]):
}
def get_retryable_errors(self) -> set[str]:
- # `_request_with_retry` (sentry.py) already retries a dropped connection, read timeout, or
- # persistent 429/5xx before re-raising once that budget is exhausted. urllib3 wraps all of
- # those as "... Max retries exceeded with url: ..." regardless of the underlying cause, so
- # match that stable prefix rather than the per-request URL or nested error detail. Temporal
- # then retries the whole activity, so the failure is transient and self-recovering. Mirrors
- # Close's equivalent case.
- return {"Max retries exceeded with url"}
+ # `_request_with_retry` (sentry.py) retries dropped connections and read timeouts at the
+ # urllib3 level; once that budget is exhausted, urllib3 re-raises with the stable "Max
+ # retries exceeded with url" prefix regardless of the underlying cause.
+ #
+ # HTTP 429s are retried by tenacity (respecting X-Sentry-Rate-Limit-Reset); when that
+ # budget is exhausted, `raise_for_status()` raises `HTTPError: 429 Client Error: Too Many
+ # Requests`, which does NOT contain the "Max retries exceeded" phrase. Match the stable
+ # status-line prefix so persistent rate-limiting lets Temporal retry instead of being
+ # reported to error tracking as a bug.
+ return {"Max retries exceeded with url", "429 Client Error"}
def get_required_parent_schemas(self, schema_name: str) -> list[str]:
# issue_tag_values fans out over issues through its custom two-level iterator, so it
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.py
index 2c9d0e05f428..e87551c49de3 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
@@ -436,6 +436,14 @@ class TestSentrySourceValidation:
assert any(pattern in error_msg for pattern in SentrySource().get_retryable_errors())
+ def test_retryable_errors_match_exhausted_rate_limit_retries(self) -> None:
+ # tenacity retries 429s (reading X-Sentry-Rate-Limit-Reset); once exhausted, raise_for_status
+ # raises HTTPError with the status line "429 Client Error: Too Many Requests for url: ...".
+ # This does NOT contain "Max retries exceeded", so it must be matched separately.
+ error_msg = "429 Client Error: Too Many Requests for url: https://sentry.io/api/0/organizations/acme/trace-items/attributes/?dataset=logs"
+
+ assert error_message_matches(error_msg, SentrySource().get_retryable_errors())
+
@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry.rest_api_resource")
def test_sentry_source_builds_response(self, mock_rest_api_resource) -> None:
mock_resource = Mock()