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(vitally): treat 401/403 credential errors as non-retryable (#63712)

Tom Owerseaecbd2232f4
diff --git a/posthog/temporal/data_imports/sources/vitally/source.py b/posthog/temporal/data_imports/sources/vitally/source.py
index 4d2e59557a84..03f86b46efd4 100644
--- a/posthog/temporal/data_imports/sources/vitally/source.py
+++ b/posthog/temporal/data_imports/sources/vitally/source.py
@@ -67,7 +67,12 @@ class VitallySource(SimpleSource[VitallySourceConfig]):
config.secret_token, config.region.selection, config.region.subdomain
)
except Exception as e:
- capture_exception(e)
+ # A 401/403 here is a customer credential problem (invalid/revoked token), not a bug
+ # we can fix — the per-schema sync path already surfaces it and disables the source.
+ # Skip capturing those to avoid spamming error tracking on every discovery run, but
+ # still capture genuinely unexpected discovery failures.
+ if not any(pattern in str(e) for pattern in self.get_non_retryable_errors()):
+ capture_exception(e)
definitions = []
for definition in definitions:
diff --git a/posthog/temporal/data_imports/sources/vitally/tests/test_vitally.py b/posthog/temporal/data_imports/sources/vitally/tests/test_vitally.py
index 4f5be6146da7..181136727c70 100644
--- a/posthog/temporal/data_imports/sources/vitally/tests/test_vitally.py
+++ b/posthog/temporal/data_imports/sources/vitally/tests/test_vitally.py
@@ -283,8 +283,9 @@ class TestVitallySourceGetSchemas:
mock_list.assert_not_called()
assert {s.name for s in schemas} == {"Accounts", "Conversations"}
+ @patch("posthog.temporal.data_imports.sources.vitally.source.capture_exception")
@patch("posthog.temporal.data_imports.sources.vitally.source.list_custom_object_definitions")
- def test_static_schemas_survive_discovery_failure(self, mock_list):
+ def test_static_schemas_survive_discovery_failure(self, mock_list, mock_capture):
mock_list.side_effect = RuntimeError("Vitally API unavailable")
schemas = VitallySource().get_schemas(self._make_config(), team_id=1)
@@ -292,6 +293,29 @@ class TestVitallySourceGetSchemas:
names = {s.name for s in schemas}
assert {"Accounts", "Conversations", "Custom_Objects", "Messages"} <= names
assert not any(s.name.startswith(CUSTOM_OBJECT_SCHEMA_PREFIX) for s in schemas)
+ # Unexpected discovery failures are still captured for triage.
+ mock_capture.assert_called_once()
+
+ @pytest.mark.parametrize(
+ "error_message",
+ [
+ "401 Client Error: Unauthorized for url: https://firstignite.rest.vitally.io/resources/customObjects?limit=100",
+ "403 Client Error: Forbidden for url: https://rest.vitally-eu.io/resources/customObjects?limit=100",
+ ],
+ )
+ @patch("posthog.temporal.data_imports.sources.vitally.source.capture_exception")
+ @patch("posthog.temporal.data_imports.sources.vitally.source.list_custom_object_definitions")
+ def test_credential_errors_do_not_spam_error_tracking(self, mock_list, mock_capture, error_message):
+ # A revoked/invalid token surfaces as a 401/403 during custom object discovery. Static
+ # endpoints must still survive, and we must not capture the credential error to error tracking.
+ mock_list.side_effect = RuntimeError(error_message)
+
+ schemas = VitallySource().get_schemas(self._make_config(), team_id=1)
+
+ names = {s.name for s in schemas}
+ assert {"Accounts", "Conversations", "Custom_Objects", "Messages"} <= names
+ assert not any(s.name.startswith(CUSTOM_OBJECT_SCHEMA_PREFIX) for s in schemas)
+ mock_capture.assert_not_called()
class TestVitallyNonRetryableErrors: