: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mongodb): stop reporting SRV DNS lookup failures as bugs (#84274)
Tom Owersed095660a297
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.pyindex a5786f6f40d6..740d97cccefd 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@@ -85,6 +85,12 @@ _DNS_RESOLUTION_FAILURE_MARKERS = ("Temporary failure in name resolution",)+# For a `mongodb+srv://` URI, pymongo resolves the SRV record via dnspython inside the+# MongoClient constructor and wraps any dnspython exception as ConfigurationError. dnspython's+# NXDOMAIN carries this fixed prefix when the SRV record's DNS name doesn't exist at all —+# a deleted, renamed, or mistyped cluster hostname — distinct from a timed-out lookup.+_SRV_DNS_NAME_NOT_FOUND_MARKER = "The DNS query name does not exist"+@SourceRegistry.registerclass MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixin):@@ -217,7 +223,7 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixinschema_name: Optional[str] = None,api_version: str | None = None,) -> tuple[bool, str | None]:- from pymongo.errors import OperationFailure, ServerSelectionTimeoutError+ from pymongo.errors import ConfigurationError, OperationFailure, ServerSelectionTimeoutErrortry:connection_params = _parse_connection_string(config.connection_string, config.database_name)@@ -270,16 +276,26 @@ class MongoDBSource(SimpleSource[MongoDBSourceConfig], ValidateDatabaseHostMixinif any(marker in message for marker in _DNS_RESOLUTION_FAILURE_MARKERS):return False, _MONGO_HOST_UNRESOLVED_MESSAGEreturn False, _MONGO_UNREACHABLE_MESSAGE- except Exception as e:- # pymongo raises InvalidURI with the RFC-3986 hint before any network call when the- # 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):+ except ConfigurationError as e:+ # InvalidURI (raised with the RFC-3986 hint before any network call when+ # credentials contain unescaped reserved characters) is itself a ConfigurationError+ # subclass, so it lands here too. An SRV DNS name that doesn't exist is the same+ # user-side problem as the non-SRV host-not-found case above. Both are malformed-+ # input problems the user must fix — already surfaced with an actionable message —+ # so don't report them to error tracking as noise. Any other ConfigurationError is+ # unexpected, so capture it and fall back to a generic message.+ message = str(e)+ if _SRV_DNS_NAME_NOT_FOUND_MARKER in message:+ return False, _MONGO_HOST_UNRESOLVED_MESSAGE+ if "must be escaped according to RFC 3986" in message:return False, _MONGO_UNESCAPED_CREDENTIALS_MESSAGEcapture_exception(e)return False, _MONGO_CONNECT_FAILED_MESSAGE+ except Exception as e:+ # Any other exception is unexpected: capture it and fall back to a generic message+ # so internal exception text never reaches the user.+ capture_exception(e)+ return False, _MONGO_CONNECT_FAILED_MESSAGEreturn True, Nonediff --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.pyindex ce8d7249b607..7b642a652f03 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@@ -1,7 +1,7 @@import pytestfrom unittest.mock import patch-from pymongo.errors import InvalidURI, OperationFailure, ServerSelectionTimeoutError+from pymongo.errors import ConfigurationError, InvalidURI, OperationFailure, ServerSelectionTimeoutErrorfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.mongodb import (MongoDBSourceConfig,@@ -180,6 +180,20 @@ class TestMongoValidateCredentialsErrorTrackingNoise:_MONGO_UNREACHABLE_MESSAGE,False,),+ (+ # dnspython's NXDOMAIN, wrapped by pymongo as ConfigurationError, when a+ # mongodb+srv:// URI's SRV DNS record doesn't exist at all.+ ConfigurationError("The DNS query name does not exist: _mongodb._tcp.cluster.abc.mongodb.net."),+ _MONGO_HOST_UNRESOLVED_MESSAGE,+ False,+ ),+ (+ # An unrecognized ConfigurationError still falls back to capturing, same as any+ # other unexpected exception.+ ConfigurationError("some-unrecognized-configuration-problem"),+ _MONGO_CONNECT_FAILED_MESSAGE,+ True,+ ),(Exception("some-internal-driver-detail"), _MONGO_CONNECT_FAILED_MESSAGE, True),],)