@@ -5,33 +5,27 @@ import { 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 = ( ) : Promise < string > => 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,35 +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- this . session . logger . debug ( {
67- id : LogId . telemetryDeviceIdFailure ,
68- context : "telemetry" ,
69- message : String ( error ) ,
70- } ) ;
71- break ;
72- case "timeout" :
73- this . session . logger . debug ( {
74- id : LogId . telemetryDeviceIdTimeout ,
75- context : "telemetry" ,
76- message : "Device ID retrieval timed out" ,
77- noRedaction : true ,
78- } ) ;
79- break ;
80- case "abort" :
81- // No need to log in the case of aborts
82- break ;
83- }
84- } ,
85- abortSignal : this . deviceIdAbortController . signal ,
86- } ) ,
87- detectContainerEnv ( ) ,
88- ] ) ;
52+ this . setupPromise = Promise . all ( [ getDeviceIdForConnection ( ) , detectContainerEnv ( ) ] ) ;
8953
9054 const [ deviceId , containerEnv ] = await this . setupPromise ;
9155
@@ -96,8 +60,6 @@ export class Telemetry {
9660 }
9761
9862 public async close ( ) : Promise < void > {
99- this . deviceIdAbortController . abort ( ) ;
100- this . isBufferingEvents = false ;
10163 await this . emitEvents ( this . eventCache . getEvents ( ) ) ;
10264 }
10365
0 commit comments