Skip to content

Commit

Permalink
chore(telemetry): log when getting public cloud info fails (#6672)
Browse files Browse the repository at this point in the history
* log when getting public cloud info fails

* add debug too

* also add the host to the error logging

* Update packages/compass/src/app/utils/telemetry.ts

Co-authored-by: Anna Henningsen <[email protected]>

* also log when resolveMongodbSrv fails

---------

Co-authored-by: Anna Henningsen <[email protected]>
  • Loading branch information
lerouxb and addaleax authored Feb 4, 2025
1 parent 816aa3c commit 54f1ccc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/compass/src/app/utils/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { getCloudInfo } from 'mongodb-cloud-info';
import ConnectionString from 'mongodb-connection-string-url';
import resolveMongodbSrv from 'resolve-mongodb-srv';
import type { KMSProviders, MongoClientOptions } from 'mongodb';
import { createLogger } from '@mongodb-js/compass-logging';
const { debug, log, mongoLogId } = createLogger('COMPASS-TELEMETRY');

type HostInformation = {
is_localhost: boolean;
Expand Down Expand Up @@ -38,6 +40,14 @@ async function getPublicCloudInfo(host: string): Promise<{
public_cloud_name,
};
} catch (err) {
debug(`getCloudInfo failed for "${host}": ${(err as Error).message}`);

log.warn(
mongoLogId(1_001_000_339),
'getPublicCloudInfo',
'Failed to look up host cloud information for telemetry',
{ host, error: (err as Error).message }
);
return {};
}
}
Expand Down Expand Up @@ -148,7 +158,20 @@ async function getHostnameForConnection(
);
if (connectionStringData.isSRV) {
const uri = await resolveMongodbSrv(connectionStringData.toString()).catch(
() => {
(err: unknown) => {
debug(
`resolveMongodbSrv failed for "${connectionStringData.hosts.join(
','
)}": ${(err as Error).message}`
);

log.warn(
mongoLogId(1_001_000_340),
'resolveMongodbSrv',
'Failed to resolve mongodb srv for telemetry',
{ hosts: connectionStringData.hosts, error: (err as Error).message }
);

return null;
}
);
Expand Down

0 comments on commit 54f1ccc

Please sign in to comment.