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(similarweb): stop retrying a 400 the account can't resolve (#129879)

Tom Owersa56bba6c0419
diff --git a/products/warehouse_sources/sources/similarweb/source.py b/products/warehouse_sources/sources/similarweb/source.py
index 9ef994194538..6dbaab4c81ff 100644
--- a/products/warehouse_sources/sources/similarweb/source.py
+++ b/products/warehouse_sources/sources/similarweb/source.py
@@ -66,6 +66,14 @@ class SimilarwebSource(ResumableSource[SimilarwebSourceConfig, SimilarwebResumeC
"Similarweb rejected the API key, or the account is out of data credits. "
"Check both on the API management page in your Similarweb account."
),
+ # Similarweb's documented cause for 400 is a request parameter outside what the
+ # account can answer — most commonly a start month earlier than the account's plan
+ # has history for. Retrying sends the exact same invalid window every time, so stop.
+ "Similarweb API returned status 400": (
+ "Similarweb rejected the request. This usually means the configured start month "
+ "is earlier than your plan's available history. Check the start month in the "
+ "source settings, then re-run the sync."
+ ),
NO_DOMAINS_ERROR: "Add one or more domains in the source settings, then re-run the sync.",
}
diff --git a/products/warehouse_sources/sources/similarweb/tests/test_similarweb_source.py b/products/warehouse_sources/sources/similarweb/tests/test_similarweb_source.py
index a5a995a373f4..360dc5448e53 100644
--- a/products/warehouse_sources/sources/similarweb/tests/test_similarweb_source.py
+++ b/products/warehouse_sources/sources/similarweb/tests/test_similarweb_source.py
@@ -92,3 +92,14 @@ class TestSimilarwebSource:
else:
assert result.paths != [V5_ENGAGEMENT_PATH]
assert result.params("api_key") == ["key-123"]
+
+ @parameterized.expand(
+ [
+ "Similarweb API returned status 400 for https://api.similarweb.com/v1/website/example.com/global-rank/global-rank",
+ "Similarweb API returned status 400 for https://api.similarweb.com/v5/website-analysis/websites/traffic-and-engagement",
+ "Similarweb API returned status 403 for https://api.similarweb.com/v1/website/example.com/total-traffic-and-engagement/visits",
+ ]
+ )
+ def test_non_retryable_errors_match_client_errors(self, observed_error: str) -> None:
+ non_retryable = self.source.get_non_retryable_errors()
+ assert any(key in observed_error for key in non_retryable)