From 0d7df8517e5e9b55245953acb74a3c80e2081051 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 31 Jan 2025 10:49:53 +0000 Subject: [PATCH 1/5] log when getting public cloud info fails --- packages/compass/src/app/utils/telemetry.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index 380ccb0f998..06f528afad4 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -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 { log, mongoLogId } = createLogger('COMPASS-TELEMETRY'); type HostInformation = { is_localhost: boolean; @@ -38,6 +40,12 @@ async function getPublicCloudInfo(host: string): Promise<{ public_cloud_name, }; } catch (err) { + log.error( + mongoLogId(1_001_000_339), + 'getPublicCloudInfo', + 'Error fetching cloud info', + (err as Error).message + ); return {}; } } From 88c0b17838c417b2f45ff8b80a15b08449648502 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 31 Jan 2025 11:44:02 +0000 Subject: [PATCH 2/5] add debug too --- packages/compass/src/app/utils/telemetry.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index 06f528afad4..eef5aa33f4c 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -6,7 +6,7 @@ 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 { log, mongoLogId } = createLogger('COMPASS-TELEMETRY'); +const { debug, log, mongoLogId } = createLogger('COMPASS-TELEMETRY'); type HostInformation = { is_localhost: boolean; @@ -40,6 +40,8 @@ async function getPublicCloudInfo(host: string): Promise<{ public_cloud_name, }; } catch (err) { + debug(`getCloudInfo failed: ${(err as Error).message}`); + log.error( mongoLogId(1_001_000_339), 'getPublicCloudInfo', From 884daa9b3f0d8e4e6621986673e16300449c47c0 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 31 Jan 2025 14:16:46 +0000 Subject: [PATCH 3/5] also add the host to the error logging --- packages/compass/src/app/utils/telemetry.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index eef5aa33f4c..122d2114d0e 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -40,13 +40,13 @@ async function getPublicCloudInfo(host: string): Promise<{ public_cloud_name, }; } catch (err) { - debug(`getCloudInfo failed: ${(err as Error).message}`); + debug(`getCloudInfo failed for "${host}": ${(err as Error).message}`); log.error( mongoLogId(1_001_000_339), 'getPublicCloudInfo', - 'Error fetching cloud info', - (err as Error).message + (err as Error).message, + { host } ); return {}; } From db5a02d85bc8571a53fa02cf07c4af97630d5468 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Fri, 31 Jan 2025 16:47:07 +0000 Subject: [PATCH 4/5] Update packages/compass/src/app/utils/telemetry.ts Co-authored-by: Anna Henningsen --- packages/compass/src/app/utils/telemetry.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index 122d2114d0e..a341011cbe9 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -42,11 +42,11 @@ async function getPublicCloudInfo(host: string): Promise<{ } catch (err) { debug(`getCloudInfo failed for "${host}": ${(err as Error).message}`); - log.error( + log.warn( mongoLogId(1_001_000_339), 'getPublicCloudInfo', - (err as Error).message, - { host } + 'Failed to look up host cloud information for telemetry', + { host, error: (err as Error).message } ); return {}; } From 004fce946d462fac6b86e766b45821b2ff1c78fd Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Tue, 4 Feb 2025 08:00:01 +0000 Subject: [PATCH 5/5] also log when resolveMongodbSrv fails --- packages/compass/src/app/utils/telemetry.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/compass/src/app/utils/telemetry.ts b/packages/compass/src/app/utils/telemetry.ts index a341011cbe9..57e19adcbf3 100644 --- a/packages/compass/src/app/utils/telemetry.ts +++ b/packages/compass/src/app/utils/telemetry.ts @@ -158,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; } );