From 377840777ee0055b6d369646ff7cbfccc7a4d8cd Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Tue, 20 May 2025 11:35:52 +0200 Subject: [PATCH 1/2] chore: bump @mongodb-js/device-id to 0.2.1 --- package-lock.json | 8 ++++---- package.json | 2 +- src/telemetry/telemetryService.ts | 21 +++++++-------------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9b40b6114..f8152f53e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@mongodb-js/compass-components": "^1.35.2", "@mongodb-js/connection-form": "1.49.0", "@mongodb-js/connection-info": "^0.12.0", - "@mongodb-js/device-id": "^0.2.0", + "@mongodb-js/device-id": "^0.2.1", "@mongodb-js/mongodb-constants": "^0.11.1", "@mongosh/browser-runtime-electron": "^3.10.3", "@mongosh/i18n": "^2.9.1", @@ -7592,9 +7592,9 @@ } }, "node_modules/@mongodb-js/device-id": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@mongodb-js/device-id/-/device-id-0.2.0.tgz", - "integrity": "sha512-auEMkQc6hpSQSQziK5AbeuJeVnI7OQvWmaoMIWcXrMm+RA6pF0ADXZPS6kBtBIrRhWElV6PVYiq+Gfzsss2RYQ==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@mongodb-js/device-id/-/device-id-0.2.1.tgz", + "integrity": "sha512-kC/F1/ryJMNeIt+n7CATAf9AL/X5Nz1Tju8VseyViL2DF640dmF/JQwWmjakpsSTy5X9TVNOkG9ye4Mber8GHQ==", "license": "Apache-2.0" }, "node_modules/@mongodb-js/devtools-connect": { diff --git a/package.json b/package.json index b66a03b44..3f51d6353 100644 --- a/package.json +++ b/package.json @@ -1318,7 +1318,7 @@ "@mongodb-js/compass-components": "^1.35.2", "@mongodb-js/connection-form": "1.49.0", "@mongodb-js/connection-info": "^0.12.0", - "@mongodb-js/device-id": "^0.2.0", + "@mongodb-js/device-id": "^0.2.1", "@mongodb-js/mongodb-constants": "^0.11.1", "@mongosh/browser-runtime-electron": "^3.10.3", "@mongosh/i18n": "^2.9.1", diff --git a/src/telemetry/telemetryService.ts b/src/telemetry/telemetryService.ts index 8336b9ea2..d54f0bc91 100644 --- a/src/telemetry/telemetryService.ts +++ b/src/telemetry/telemetryService.ts @@ -46,8 +46,9 @@ export class TelemetryService { private readonly _context: vscode.ExtensionContext; private readonly _shouldTrackTelemetry: boolean; // When tests run the extension, we don't want to track telemetry. + private readonly _deviceIdAbortController = new AbortController(); + public deviceId: string | undefined; - private resolveDeviceId: ((value: string) => void) | undefined; constructor( storageController: StorageController, @@ -98,7 +99,10 @@ export class TelemetryService { flushInterval: 10000, // 10 seconds is the default libraries' value. }); - this.deviceId = await this.getDeviceId(); + this.deviceId = await getDeviceId({ + getMachineId: (): Promise => nodeMachineId.machineId(true), + abortSignal: this._deviceIdAbortController.signal, + }); const userIdentity = { anonymousId: this.anonymousId, @@ -119,7 +123,7 @@ export class TelemetryService { } deactivate(): void { - this.resolveDeviceId?.('unknown'); + this._deviceIdAbortController.abort(); // Flush on demand to make sure that nothing is left in the queue. void this._segmentAnalytics?.closeAndFlush(); } @@ -189,17 +193,6 @@ export class TelemetryService { this.track(new NewConnectionTelemetryEvent(connectionTelemetryProperties)); } - private async getDeviceId(): Promise { - const { value: deviceId, resolve: resolveDeviceId } = getDeviceId({ - getMachineId: (): Promise => nodeMachineId.machineId(true), - isNodeMachineId: true, - }); - - this.resolveDeviceId = resolveDeviceId; - - return deviceId; - } - trackParticipantError(err: any, command: ParticipantResponseType): void { let errorCode: string | undefined; let errorName: ParticipantErrorTypes; From e537c67f04044ec2cef083319dba3d0af3d950e4 Mon Sep 17 00:00:00 2001 From: Nikola Irinchev Date: Tue, 20 May 2025 12:41:22 +0200 Subject: [PATCH 2/2] Bring back getDeviceId --- src/telemetry/telemetryService.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/telemetry/telemetryService.ts b/src/telemetry/telemetryService.ts index d54f0bc91..5fb5c16bf 100644 --- a/src/telemetry/telemetryService.ts +++ b/src/telemetry/telemetryService.ts @@ -99,10 +99,7 @@ export class TelemetryService { flushInterval: 10000, // 10 seconds is the default libraries' value. }); - this.deviceId = await getDeviceId({ - getMachineId: (): Promise => nodeMachineId.machineId(true), - abortSignal: this._deviceIdAbortController.signal, - }); + this.deviceId = await this.getDeviceId(); const userIdentity = { anonymousId: this.anonymousId, @@ -237,4 +234,11 @@ export class TelemetryService { 5000, { leading: true, trailing: false }, ); + + private getDeviceId(): Promise { + return getDeviceId({ + getMachineId: (): Promise => nodeMachineId.machineId(true), + abortSignal: this._deviceIdAbortController.signal, + }); + } }