Skip to content

Commit 54f1ccc

Browse files
lerouxbaddaleax
andauthored
chore(telemetry): log when getting public cloud info fails (#6672)
* 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]>
1 parent 816aa3c commit 54f1ccc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { getCloudInfo } from 'mongodb-cloud-info';
55
import ConnectionString from 'mongodb-connection-string-url';
66
import resolveMongodbSrv from 'resolve-mongodb-srv';
77
import type { KMSProviders, MongoClientOptions } from 'mongodb';
8+
import { createLogger } from '@mongodb-js/compass-logging';
9+
const { debug, log, mongoLogId } = createLogger('COMPASS-TELEMETRY');
810

911
type HostInformation = {
1012
is_localhost: boolean;
@@ -38,6 +40,14 @@ async function getPublicCloudInfo(host: string): Promise<{
3840
public_cloud_name,
3941
};
4042
} catch (err) {
43+
debug(`getCloudInfo failed for "${host}": ${(err as Error).message}`);
44+
45+
log.warn(
46+
mongoLogId(1_001_000_339),
47+
'getPublicCloudInfo',
48+
'Failed to look up host cloud information for telemetry',
49+
{ host, error: (err as Error).message }
50+
);
4151
return {};
4252
}
4353
}
@@ -148,7 +158,20 @@ async function getHostnameForConnection(
148158
);
149159
if (connectionStringData.isSRV) {
150160
const uri = await resolveMongodbSrv(connectionStringData.toString()).catch(
151-
() => {
161+
(err: unknown) => {
162+
debug(
163+
`resolveMongodbSrv failed for "${connectionStringData.hosts.join(
164+
','
165+
)}": ${(err as Error).message}`
166+
);
167+
168+
log.warn(
169+
mongoLogId(1_001_000_340),
170+
'resolveMongodbSrv',
171+
'Failed to resolve mongodb srv for telemetry',
172+
{ hosts: connectionStringData.hosts, error: (err as Error).message }
173+
);
174+
152175
return null;
153176
}
154177
);

0 commit comments

Comments
 (0)