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(stripe): keep exhausted rate-limit retries out of error tracking (#75645)

Tom Owers2dca9007c17b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
index 08e06b42a826..2b46c593ac16 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/source.py
@@ -293,6 +293,12 @@ If automatic creation failed due to a permissions error and you're using a restr
"Your Stripe OAuth connection has expired or been revoked. Please reconnect your Stripe account.": "Your Stripe OAuth connection has expired or been revoked. Please reconnect your Stripe account.",
}
+ def get_retryable_errors(self) -> set[str]:
+ # A 429 is already retried in-process by _RateLimitRetryingRequestsClient's Retry-After-aware
+ # backoff (see stripe.py); if that budget still exhausts, Temporal's activity retry picks it
+ # back up, so this is self-recovering rather than a tracked-exception-worthy failure.
+ return {"Request rate limit exceeded"}
+
def _get_api_key(self, config: StripeSourceConfig, team_id: int) -> str:
if config.auth_method.selection == "api_key":
if not config.auth_method.stripe_secret_key:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
index 5a33391334b6..5c6f03b8a2a3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
@@ -220,12 +220,25 @@ class TestStripeSource:
"HTTPSConnectionPool(host='api.stripe.com', port=443): Read timed out.",
"500 Server Error: Internal Server Error for url: https://api.stripe.com/v1/charges",
"Connection reset by peer",
+ # Rate limits are transient (Retry-After-bounded) — must never disable the source.
+ "Request req_abc123: Request rate limit exceeded. You can learn more about rate limits here https://stripe.com/docs/rate-limits.",
],
)
def test_non_retryable_errors_do_not_match_transient(self, other_error):
non_retryable_errors = self.source.get_non_retryable_errors()
assert not any(key in other_error for key in non_retryable_errors)
+ def test_retryable_errors_match_rate_limit(self):
+ # A RateLimitError that survives _RateLimitRetryingRequestsClient's in-process backoff still
+ # gets retried by Temporal at the activity level; it must be classified as retryable so it's
+ # logged as a warning rather than tracked as an exception.
+ observed_error = (
+ "Request req_abc123: Request rate limit exceeded. You can learn more about rate limits here "
+ "https://stripe.com/docs/rate-limits."
+ )
+ retryable_errors = self.source.get_retryable_errors()
+ assert any(key in observed_error for key in retryable_errors)
+
@pytest.mark.parametrize(
"config,expected_message",
[