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(oauth): stop capturing expected CIMD fetch failures (#92458)

posthog[bot]7fccb830300d
diff --git a/posthog/api/oauth/cimd.py b/posthog/api/oauth/cimd.py
index 7228a6f0ec6b..1db491dab469 100644
--- a/posthog/api/oauth/cimd.py
+++ b/posthog/api/oauth/cimd.py
@@ -926,12 +926,10 @@ def refresh_cimd_metadata_task(url: str) -> None:
try:
with ph_scoped_capture() as capture_ph_event:
fetch_and_upsert_cimd_application(url, capture_ph_event=capture_ph_event)
- except CIMDValidationError as e:
- # Expected rejection of a non-compliant partner document — log for observability, don't surface as an error.
+ except (CIMDValidationError, CIMDFetchError) as e:
+ # A non-compliant document or an unreachable partner endpoint is expected here — the URL and its
+ # host belong to a third party we do not control. Log for observability, don't surface as an error.
logger.warning("cimd_background_refresh_failed", url=url, error=str(e))
- except CIMDFetchError as e:
- logger.warning("cimd_background_refresh_failed", url=url, error=str(e))
- capture_exception(e)
def get_or_create_cimd_application(url: str) -> OAuthApplication:
diff --git a/posthog/api/oauth/test_cimd.py b/posthog/api/oauth/test_cimd.py
index 7dc590bdaa98..f7081ccbcb3e 100644
--- a/posthog/api/oauth/test_cimd.py
+++ b/posthog/api/oauth/test_cimd.py
@@ -570,21 +570,22 @@ class TestGetOrCreateCimdApplication(APIBaseTest):
app = OAuthApplication.objects.get(client_id=VALID_CIMD_URL)
self.assertEqual(app.name, "Original Name")
+ @parameterized.expand(
+ [
+ ("validation_error", CIMDValidationError("document exceeds the 5120 byte limit")),
+ ("fetch_error", CIMDFetchError("connection reset")),
+ ]
+ )
@patch("posthog.api.oauth.cimd.capture_exception")
@patch("posthog.api.oauth.cimd.fetch_and_upsert_cimd_application")
- def test_refresh_task_does_not_capture_expected_validation_error(self, mock_fetch, mock_capture, _url_mock):
- # Rejecting a non-compliant partner document is expected, so it must not surface as an error-tracking issue.
- mock_fetch.side_effect = CIMDValidationError("document exceeds the 5120 byte limit")
- refresh_cimd_metadata_task(VALID_CIMD_URL)
- mock_capture.assert_not_called()
-
- @patch("posthog.api.oauth.cimd.capture_exception")
- @patch("posthog.api.oauth.cimd.fetch_and_upsert_cimd_application")
- def test_refresh_task_captures_unexpected_fetch_error(self, mock_fetch, mock_capture, _url_mock):
- error = CIMDFetchError("connection reset")
+ def test_refresh_task_does_not_capture_expected_partner_errors(
+ self, _name, error, mock_fetch, mock_capture, _url_mock
+ ):
+ # A rejected partner document or an unreachable partner endpoint is expected, so neither must
+ # surface as an error-tracking issue.
mock_fetch.side_effect = error
refresh_cimd_metadata_task(VALID_CIMD_URL)
- mock_capture.assert_called_once_with(error)
+ mock_capture.assert_not_called()
@patch("posthog.security.url_validation.resolve_host_ips", return_value={ip_address("93.184.216.34")})