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(mongodb): stop reporting unescaped-credential errors to error tracking (#66691)

Tom Owers4dd2082400d7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
index 1658317bb7f8..bd594272267f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/source.py
@@ -229,13 +229,14 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin
return False, _MONGO_HOST_UNRESOLVED_MESSAGE
return False, _MONGO_UNREACHABLE_MESSAGE
except Exception as e:
- capture_exception(e)
# pymongo raises InvalidURI with the RFC-3986 hint before any network call when the
- # credentials contain unescaped reserved characters; surface the actionable message
- # rather than the raw driver string. Any other exception falls back to a generic message
- # so internal exception text never reaches the user.
+ # credentials contain unescaped reserved characters. This is a malformed connection
+ # string the user must fix — already surfaced with an actionable message — so don't
+ # report it to error tracking as a bug. Any other exception is unexpected: capture it
+ # and fall back to a generic message so internal exception text never reaches the user.
if "must be escaped according to RFC 3986" in str(e):
return False, _MONGO_UNESCAPED_CREDENTIALS_MESSAGE
+ capture_exception(e)
return False, _MONGO_CONNECT_FAILED_MESSAGE
return True, None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_database_name.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_database_name.py
index f041abb9f284..13e9ee8213c6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_database_name.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mongodb/test_database_name.py
@@ -147,3 +147,33 @@ class TestMongoValidateCredentialsOperationFailure:
assert err == expected_message
for leaked in forbidden:
assert leaked not in (err or "")
+
+
+class TestMongoValidateCredentialsErrorTrackingNoise:
+ # Unescaped credentials are a user mistake we already surface an actionable message for, so
+ # they must not be reported to error tracking; genuinely unexpected errors still must be.
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.mongodb.source.capture_exception")
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.mongodb.source.get_collection_names")
+ def test_unescaped_credentials_not_reported(self, mock_get_collections, mock_capture):
+ mock_get_collections.side_effect = InvalidURI(
+ "Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus"
+ )
+ config = MongoDBSourceConfig.from_dict({"connection_string": _SRV_WITH_DB})
+
+ ok, err = MongoDBSource().validate_credentials(config, team_id=1)
+
+ assert ok is False
+ assert err == _MONGO_UNESCAPED_CREDENTIALS_MESSAGE
+ mock_capture.assert_not_called()
+
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.mongodb.source.capture_exception")
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.mongodb.source.get_collection_names")
+ def test_unexpected_error_is_reported(self, mock_get_collections, mock_capture):
+ mock_get_collections.side_effect = Exception("some-internal-driver-detail")
+ config = MongoDBSourceConfig.from_dict({"connection_string": _SRV_WITH_DB})
+
+ ok, err = MongoDBSource().validate_credentials(config, team_id=1)
+
+ assert ok is False
+ assert err == _MONGO_CONNECT_FAILED_MESSAGE
+ mock_capture.assert_called_once()