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): treat exhausted 5xx retries as transient (#115590)

Tom Owers1d0f1d033e9d
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 394869a0f358..94b0268ccfc4 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
@@ -154,7 +154,13 @@ class SentrySource(ResumableSource[SentrySourceConfig, SentryResumeConfig]):
# of error tracking; every other path still reaches `raise_for_status()`, which raises
# `HTTPError: 429 Client Error: Too Many Requests`. Match both so persistent rate-limiting
# lets Temporal retry instead of being reported to error tracking as a bug.
- return {"Max retries exceeded with url", SENTRY_RATE_LIMITED_MESSAGE, "429 Client Error"}
+ #
+ # A persistent 5xx is retried the same way and, for endpoints with no per-request skip
+ # handler (e.g. the projects listing `_iter_projects` feeds project_ownership and
+ # project_stats from), reaches the same `raise_for_status()` once that budget is
+ # exhausted. `raise_for_status()` derives the "<code> Server Error" prefix from the status
+ # code alone, so it's stable to match on (see mailchimp/impact for the same pattern).
+ return {"Max retries exceeded with url", SENTRY_RATE_LIMITED_MESSAGE, "429 Client Error", "Server 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 b11566a618e7..5beb71af94a1 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
@@ -1184,6 +1184,20 @@ class TestHelpers:
assert _raise_on_failed_retry(state) is response
+ def test_exhausted_5xx_raise_for_status_is_classified_retryable(self) -> None:
+ # Endpoints with no per-request skip handler (e.g. the projects listing _iter_projects
+ # feeds project_ownership/project_stats from) let the response above reach
+ # raise_for_status() uncaught. That HTTPError must still be classified retryable, the
+ # same as the exhausted-429 case above, rather than reported to error tracking as a bug.
+ response = Mock(status_code=502, headers={})
+ error = HTTPError(
+ "502 Server Error: Bad Gateway for url: https://de.sentry.io/api/0/organizations/acme/projects/",
+ response=response,
+ )
+
+ assert error_message_matches(str(error), SentrySource().get_retryable_errors())
+ assert not error_message_matches(str(error), SentrySource().get_non_retryable_errors())
+
class TestSentryRetentionWindow:
@parameterized.expand(