diff --git a/packages/compass/src/app/utils/telemetry.spec.ts b/packages/compass/src/app/utils/telemetry.spec.ts index 3d46135a6b8..0b43bf256db 100644 --- a/packages/compass/src/app/utils/telemetry.spec.ts +++ b/packages/compass/src/app/utils/telemetry.spec.ts @@ -157,6 +157,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -200,6 +201,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -226,12 +228,12 @@ describe('connection tracking', function () { { url: 'mongodb://compass-data-sets-shard-00-00.e06dc.mongodb.net', is_srv: false, - title: 'is atlas, no srv', + title: 'no srv', }, { url: 'mongodb+srv://compass-data-sets.e06dc.mongodb.net', is_srv: true, - title: 'is atlas, is srv', + title: 'is srv', }, ]) { it(`tracks a new connection event - ${title}`, async function () { @@ -255,6 +257,7 @@ describe('connection tracking', function () { is_srv: is_srv, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -329,6 +332,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: true, is_dataLake: false, is_enterprise: false, @@ -373,6 +377,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -416,6 +421,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -458,6 +464,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -500,6 +507,7 @@ describe('connection tracking', function () { is_srv: true, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, @@ -632,13 +640,16 @@ describe('connection tracking', function () { const connection: ConnectionInfo = { ...connectionInfo, connectionOptions: { - connectionString: 'mongodb://127.0.0.1', + connectionString: 'mongodb://test-data-sets-a011bb.mongodb.net', }, }; trackNewConnectionEvent(connection, mockDataService, logger, track); const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(true); + expect(properties.atlas_hostname).to.equal( + 'test-data-sets-a011bb.mongodb.net' + ); expect(properties.is_local_atlas).to.equal(false); expect(properties.is_dataLake).to.equal(true); expect(properties.is_enterprise).to.equal(true); @@ -690,6 +701,7 @@ describe('connection tracking', function () { const [{ properties }] = await trackEvent; expect(properties.is_atlas).to.equal(false); + expect(properties.atlas_hostname).to.equal(null); expect(properties.is_local_atlas).to.equal(false); expect(properties.is_dataLake).to.equal(false); expect(properties.is_enterprise).to.equal(false); @@ -772,6 +784,7 @@ describe('connection tracking', function () { is_srv: false, topology_type: 'Unknown', is_atlas: false, + atlas_hostname: null, is_local_atlas: false, is_dataLake: false, is_enterprise: false, diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index c6d1630747d..62c9aa66b23 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -101,8 +101,14 @@ function getCsfleInformation( } async function getHostnameForConnection( - connectionStringData: ConnectionString + connectionInfo: ConnectionInfo ): Promise { + let connectionStringData = new ConnectionString( + connectionInfo.connectionOptions.connectionString, + { + looseValidation: true, + } + ); if (connectionStringData.isSRV) { const uri = await resolveMongodbSrv(connectionStringData.toString()).catch( () => { @@ -120,11 +126,12 @@ async function getHostnameForConnection( return connectionStringData.hosts[0]; } -async function getConnectionData({ - connectionOptions: { connectionString, sshTunnel, fleOptions }, -}: Pick): Promise< - Record -> { +async function getConnectionData( + { + connectionOptions: { connectionString, sshTunnel, fleOptions }, + }: Pick, + resolvedHostname: string | null +): Promise> { const connectionStringData = new ConnectionString(connectionString, { looseValidation: true, }); @@ -139,8 +146,6 @@ async function getConnectionData({ : 'NONE'; const proxyHost = searchParams.get('proxyHost'); - const resolvedHostname = await getHostnameForConnection(connectionStringData); - return { ...(await getHostInformation(resolvedHostname)), auth_type: authType.toUpperCase(), @@ -179,10 +184,15 @@ export function trackNewConnectionEvent( const callback = async () => { const { dataLake, genuineMongoDB, host, build, isAtlas, isLocalAtlas } = await dataService.instance(); - const connectionData = await getConnectionData(connectionInfo); + const resolvedHostname = await getHostnameForConnection(connectionInfo); + const connectionData = await getConnectionData( + connectionInfo, + resolvedHostname + ); const trackEvent = { ...connectionData, is_atlas: isAtlas, + atlas_hostname: isAtlas ? resolvedHostname : null, is_local_atlas: isLocalAtlas, is_dataLake: dataLake.isDataLake, is_enterprise: build.isEnterprise, @@ -209,8 +219,14 @@ export function trackConnectionFailedEvent( ): void { try { const callback = async () => { - const connectionData = - connectionInfo !== null ? await getConnectionData(connectionInfo) : {}; + let connectionData: Record = {}; + if (connectionInfo !== null) { + const resolvedHostname = await getHostnameForConnection(connectionInfo); + connectionData = await getConnectionData( + connectionInfo, + resolvedHostname + ); + } const trackEvent = { ...connectionData, error_code: connectionError.code,