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(linkedin_ads): classify exhausted retryable errors as retryable noise (#73632)

Tom Owers6d2188e93f1a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
index 692f0c4406eb..aa4edb80904a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/source.py
@@ -115,6 +115,18 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResu
"Integration matching query does not exist": "Your LinkedIn Ads connection is no longer available — it may have been disconnected. Please re-authorize the LinkedIn Ads integration.",
}
+ def get_retryable_errors(self) -> set[str]:
+ # `client.py`'s `_call_finder` already retries these in-process via tenacity (5 attempts,
+ # exponential backoff honoring Retry-After) before re-raising `LinkedinAdsRetryableError`. A
+ # 429/5xx/malformed-body that survives all 5 attempts is a transient LinkedIn/edge blip, not
+ # a bug — Temporal's activity retry recovers once the upstream issue clears, so keep it out
+ # of error tracking as noise. Match the stable message prefix LinkedIn's own status/body are
+ # appended to, not the volatile status code or body.
+ return {
+ "LinkedIn API error (retryable, ",
+ "LinkedIn API returned a malformed (non-JSON) response",
+ }
+
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
index 269da76bcbec..b13a977f942d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
@@ -50,6 +50,31 @@ class TestLinkedInAdsSource:
non_retryable_errors = self.source.get_non_retryable_errors()
assert not any(key in other_error for key in non_retryable_errors)
+ @pytest.mark.parametrize(
+ "observed_error",
+ [
+ 'LinkedIn API error (retryable, 500): {"message":"Internal Server Error","status":500}',
+ 'LinkedIn API error (retryable, 429): {"message":"Too many requests"}',
+ 'LinkedIn API error (retryable, 503): {"message":"Service Unavailable"}',
+ "LinkedIn API returned a malformed (non-JSON) response: Expecting value: line 1 column 1 (char 0)",
+ ],
+ )
+ def test_retryable_errors_match_exhausted_transient_failures(self, observed_error):
+ retryable_errors = self.source.get_retryable_errors()
+ assert any(pattern in observed_error for pattern in retryable_errors)
+
+ @pytest.mark.parametrize(
+ "other_error",
+ [
+ 'LinkedIn API error (404): {"status":404,"code":"RESOURCE_NOT_FOUND"}',
+ 'LinkedIn daily rate limit reached (429): {"message":"throttled"}',
+ "Connection reset by peer",
+ ],
+ )
+ def test_retryable_errors_does_not_match_unrelated(self, other_error):
+ retryable_errors = self.source.get_retryable_errors()
+ assert not any(pattern in other_error for pattern in retryable_errors)
+
def test_defaults_new_sources_to_202606(self):
assert self.source.default_version == LINKEDIN_ADS_VERSION_202606
assert set(self.source.supported_versions) == {"v1", LINKEDIN_ADS_VERSION_202606}