@@ -5,33 +5,27 @@ import logger, { LogId } from "../common/logger.js";
55import { ApiClient } from "../common/atlas/apiClient.js" ;
66import { MACHINE_METADATA } from "./constants.js" ;
77import { EventCache } from "./eventCache.js" ;
8- import nodeMachineId from "node-machine-id" ;
9- import { getDeviceId } from "@mongodb-js/device-id" ;
8+ import { getDeviceIdForConnection } from "../helpers/deviceId.js" ;
109import { detectContainerEnv } from "../helpers/container.js" ;
1110
1211type EventResult = {
1312 success : boolean ;
1413 error ?: Error ;
1514} ;
1615
17- export const DEVICE_ID_TIMEOUT = 3000 ;
18-
1916export class Telemetry {
2017 private isBufferingEvents : boolean = true ;
2118 /** Resolves when the setup is complete or a timeout occurs */
2219 public setupPromise : Promise < [ string , boolean ] > | undefined ;
23- private deviceIdAbortController = new AbortController ( ) ;
2420 private eventCache : EventCache ;
25- private getRawMachineId : ( ) => Promise < string > ;
2621
2722 private constructor (
2823 private readonly session : Session ,
2924 private readonly userConfig : UserConfig ,
3025 private readonly commonProperties : CommonProperties ,
31- { eventCache, getRawMachineId } : { eventCache : EventCache ; getRawMachineId : ( ) => Promise < string > }
26+ { eventCache } : { eventCache : EventCache }
3227 ) {
3328 this . eventCache = eventCache ;
34- this . getRawMachineId = getRawMachineId ;
3529 }
3630
3731 static create (
@@ -40,14 +34,12 @@ export class Telemetry {
4034 {
4135 commonProperties = { ...MACHINE_METADATA } ,
4236 eventCache = EventCache . getInstance ( ) ,
43- getRawMachineId = ( ) => nodeMachineId . machineId ( true ) ,
4437 } : {
4538 eventCache ?: EventCache ;
46- getRawMachineId ?: ( ) => Promise < string > ;
4739 commonProperties ?: CommonProperties ;
4840 } = { }
4941 ) : Telemetry {
50- const instance = new Telemetry ( session , userConfig , commonProperties , { eventCache, getRawMachineId } ) ;
42+ const instance = new Telemetry ( session , userConfig , commonProperties , { eventCache } ) ;
5143
5244 void instance . setup ( ) ;
5345 return instance ;
@@ -57,26 +49,7 @@ export class Telemetry {
5749 if ( ! this . isTelemetryEnabled ( ) ) {
5850 return ;
5951 }
60- this . setupPromise = Promise . all ( [
61- getDeviceId ( {
62- getMachineId : ( ) => this . getRawMachineId ( ) ,
63- onError : ( reason , error ) => {
64- switch ( reason ) {
65- case "resolutionError" :
66- logger . debug ( LogId . telemetryDeviceIdFailure , "telemetry" , String ( error ) ) ;
67- break ;
68- case "timeout" :
69- logger . debug ( LogId . telemetryDeviceIdTimeout , "telemetry" , "Device ID retrieval timed out" ) ;
70- break ;
71- case "abort" :
72- // No need to log in the case of aborts
73- break ;
74- }
75- } ,
76- abortSignal : this . deviceIdAbortController . signal ,
77- } ) ,
78- detectContainerEnv ( ) ,
79- ] ) ;
52+ this . setupPromise = Promise . all ( [ getDeviceIdForConnection ( ) , detectContainerEnv ( ) ] ) ;
8053
8154 const [ deviceId , containerEnv ] = await this . setupPromise ;
8255
@@ -87,8 +60,6 @@ export class Telemetry {
8760 }
8861
8962 public async close ( ) : Promise < void > {
90- this . deviceIdAbortController . abort ( ) ;
91- this . isBufferingEvents = false ;
9263 await this . emitEvents ( this . eventCache . getEvents ( ) ) ;
9364 }
9465
0 commit comments