@@ -5,9 +5,9 @@ import logger, { LogId } from "../logger.js";
5
5
import { ApiClient } from "../common/atlas/apiClient.js" ;
6
6
import { MACHINE_METADATA } from "./constants.js" ;
7
7
import { EventCache } from "./eventCache.js" ;
8
- import { createHmac } from "crypto" ;
9
8
import nodeMachineId from "node-machine-id" ;
10
9
import { DeferredPromise } from "../deferred-promise.js" ;
10
+ import { getDeviceId as extractDeviceId } from "@mongodb-js/device-id" ;
11
11
12
12
type EventResult = {
13
13
success : boolean ;
@@ -80,26 +80,13 @@ export class Telemetry {
80
80
* @returns A hashed, unique identifier for the running device or `"unknown"` if not known.
81
81
*/
82
82
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 ;
102
85
}
86
+ return extractDeviceId ( {
87
+ getMachineId : ( ) => this . getRawMachineId ( ) ,
88
+ isNodeMachineId : true ,
89
+ } ) . value ;
103
90
}
104
91
105
92
/**
0 commit comments