: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(meta-ads): name the failure when a temporary Meta error outlives retries (#103645)
Tom Owers35f8d5721b16
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.pyindex 33ddf777a68d..4302bc996472 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py@@ -196,6 +196,21 @@ class MetaAdsSource(ResumableSource[MetaAdsSourceConfig, MetaAdsResumeConfig], OMETA_RATE_LIMIT_ERROR_MESSAGE,}+ def get_retry_exhausted_errors(self) -> dict[str, str]:+ # Both markers above are raised with Meta's raw response appended for debugging+ # (`_raise_meta_api_error`), so a failure that also outlives Temporal's retries stores that+ # JSON blob, HTTP status and trace id included, as the error the customer reads.+ return {+ "Meta API request failed (retryable)": (+ "Meta kept returning temporary errors, so this sync run did not finish. This usually "+ "clears on its own and the next sync runs on schedule."+ ),+ META_RATE_LIMIT_ERROR_MESSAGE: (+ "Meta is rate limiting requests for this connection, so this sync run did not finish. "+ "The next sync runs on schedule."+ ),+ }+def get_schemas(self,config: MetaAdsSourceConfig,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.pyindex 7e84c1f5c3ec..a19e63af6416 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py@@ -32,6 +32,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.meta_ads.mMETA_ADS_MAX_HISTORY_DAYS,META_AUTH_ERROR_MESSAGE,META_INVALID_CURSOR_ERROR_MESSAGE,+ META_RATE_LIMIT_ERROR_MESSAGE,META_TRANSIENT_ERROR_MAX_ATTEMPTS,PAGE_LIMIT_FALLBACK_SIZES,SHRINK_EXHAUSTED_ERROR_MESSAGE,@@ -1499,6 +1500,35 @@ class TestRetryableErrors:_raise_meta_api_error(response)assert any(pattern in str(exc_info.value) for pattern in patterns)+ @pytest.mark.parametrize(+ "error_message,expected_fragment",+ [+ (+ 'Meta API request failed (retryable): 500 - {"error":{"message":"An unexpected error has '+ 'occurred. Please retry your request later.","type":"OAuthException","is_transient":true,'+ '"code":2,"fbtrace_id":"AaBbCcDdEeFf00112233"}}',+ "temporary errors",+ ),+ (+ f"{META_RATE_LIMIT_ERROR_MESSAGE} (Meta API response: 400 - "+ '{"error":{"message":"User request limit reached","type":"OAuthException","code":17,'+ '"fbtrace_id":"AaBbCcDdEeFf00112233"}})',+ "rate limiting",+ ),+ ],+ )+ def test_retry_exhausted_message_replaces_the_raw_meta_response(+ self, error_message: str, expected_fragment: str+ ) -> None:+ # Without this the job stores Meta's raw response body as what the customer reads.+ messages = [+ message for key, message in MetaAdsSource().get_retry_exhausted_errors().items() if key in error_message+ ]+ assert messages, f"An exhausted Meta Ads retry should store a customer-facing message: {error_message}"+ assert expected_fragment in messages[0]+ assert "fbtrace_id" not in messages[0]+ assert "next sync runs on schedule" in messages[0]+def test_too_much_data_timeout_does_not_match_retryable_pattern(self) -> None:# The too-much-data timeout keeps its own non-retryable classification (adaptive chunking# already exhausted) — plain retries never resolve it, so it must not also be tagged