@@ -5,9 +5,9 @@ import logger, { LogId } from "../logger.js";
55import { ApiClient } from "../common/atlas/apiClient.js" ;
66import { MACHINE_METADATA } from "./constants.js" ;
77import { EventCache } from "./eventCache.js" ;
8- import { createHmac } from "crypto" ;
98import nodeMachineId from "node-machine-id" ;
109import { DeferredPromise } from "../deferred-promise.js" ;
10+ import { getDeviceId as extractDeviceId } from "@mongodb-js/device-id" ;
1111
1212type EventResult = {
1313 success : boolean ;
@@ -80,26 +80,13 @@ export class Telemetry {
8080 * @returns A hashed, unique identifier for the running device or `"unknown"` if not known.
8181 */
8282 private async getDeviceId ( ) : Promise < string > {
83- try {
84- if ( this . commonProperties . device_id ) {
85- return this . commonProperties . device_id ;
86- }
87-
88- const originalId : string = await this . getRawMachineId ( ) ;
89-
90- // Create a hashed format from the all uppercase version of the machine ID
91- // to match it exactly with the denisbrodbeck/machineid library that Atlas CLI uses.
92- const hmac = createHmac ( "sha256" , originalId . toUpperCase ( ) ) ;
93-
94- /** This matches the message used to create the hashes in Atlas CLI */
95- const DEVICE_ID_HASH_MESSAGE = "atlascli" ;
96-
97- hmac . update ( DEVICE_ID_HASH_MESSAGE ) ;
98- return hmac . digest ( "hex" ) ;
99- } catch ( error ) {
100- logger . debug ( LogId . telemetryDeviceIdFailure , "telemetry" , String ( error ) ) ;
101- return "unknown" ;
83+ if ( this . commonProperties . device_id ) {
84+ return this . commonProperties . device_id ;
10285 }
86+ return extractDeviceId ( {
87+ getMachineId : ( ) => this . getRawMachineId ( ) ,
88+ isNodeMachineId : true ,
89+ } ) . value ;
10390 }
10491
10592 /**
0 commit comments