: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(new_relic): retry nerdgraph gateway timeouts instead of failing the sync (#124535)
Tom Owersb2d254a888ad
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/new_relic.py b/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/new_relic.pyindex db47e8e73213..75d08ea42589 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/new_relic.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/new_relic.py@@ -186,8 +186,9 @@ def _execute_graphql(response = session.post(url, json={"query": query, "variables": variables}, timeout=REQUEST_TIMEOUT_SECONDS)# 25 concurrent NerdGraph requests per user / 3,000 NRQL queries per account per- # minute surface as 429s; both clear on their own, so back off and retry.- if response.status_code == 429 or response.status_code >= 500:+ # minute surface as 429s; both clear on their own, so back off and retry. 408 is+ # NerdGraph's own gateway timing out before the query completed, same story.+ if response.status_code in (408, 429) or response.status_code >= 500:raise NewRelicRetryableError(f"New Relic API error (retryable): status={response.status_code}, url={url}")if not response.ok:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/tests/test_new_relic.py b/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/tests/test_new_relic.pyindex 282a1382884b..306c356af786 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/tests/test_new_relic.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/new_relic/tests/test_new_relic.py@@ -121,7 +121,9 @@ class TestExecuteGraphql:session, "https://api.newrelic.com/graphql", "query", {}, MagicMock())- @parameterized.expand([("rate_limited", 429), ("server_error", 500), ("bad_gateway", 502)])+ @parameterized.expand(+ [("request_timeout", 408), ("rate_limited", 429), ("server_error", 500), ("bad_gateway", 502)]+ )def test_retryable_status_codes_raise_retryable_error(self, _name: str, status_code: int) -> None:with pytest.raises(NewRelicRetryableError):self._execute(self._response(status_code=status_code))