@@ -39,8 +39,8 @@ async function isContainerized(): Promise<boolean> {
3939}
4040
4141export class Telemetry {
42- private deviceIdPromise : Promise < string > | undefined ;
43- private containerEnvPromise : Promise < boolean > | undefined ;
42+ private deviceId : string | undefined ;
43+ private containerEnv : boolean | undefined ;
4444 private deviceIdAbortController = new AbortController ( ) ;
4545 private eventCache : EventCache ;
4646 private getRawMachineId : ( ) => Promise < string > ;
@@ -64,7 +64,7 @@ export class Telemetry {
6464 this . getContainerEnv = getContainerEnv ;
6565 }
6666
67- static create (
67+ static async create (
6868 session : Session ,
6969 userConfig : UserConfig ,
7070 {
@@ -76,23 +76,23 @@ export class Telemetry {
7676 getRawMachineId ?: ( ) => Promise < string > ;
7777 getContainerEnv ?: ( ) => Promise < boolean > ;
7878 } = { }
79- ) : Telemetry {
79+ ) : Promise < Telemetry > {
8080 const instance = new Telemetry ( session , userConfig , {
8181 eventCache,
8282 getRawMachineId,
8383 getContainerEnv,
8484 } ) ;
8585
86- instance . start ( ) ;
86+ await instance . start ( ) ;
8787 return instance ;
8888 }
8989
90- private start ( ) : void {
90+ private async start ( ) : Promise < void > {
9191 if ( ! this . isTelemetryEnabled ( ) ) {
9292 return ;
9393 }
9494
95- this . deviceIdPromise = getDeviceId ( {
95+ const deviceIdPromise = getDeviceId ( {
9696 getMachineId : ( ) => this . getRawMachineId ( ) ,
9797 onError : ( reason , error ) => {
9898 switch ( reason ) {
@@ -109,7 +109,9 @@ export class Telemetry {
109109 } ,
110110 abortSignal : this . deviceIdAbortController . signal ,
111111 } ) ;
112- this . containerEnvPromise = this . getContainerEnv ( ) ;
112+ const containerEnvPromise = this . getContainerEnv ( ) ;
113+
114+ [ this . deviceId , this . containerEnv ] = await Promise . all ( [ deviceIdPromise , containerEnvPromise ] ) ;
113115 }
114116
115117 public async close ( ) : Promise < void > {
@@ -138,16 +140,16 @@ export class Telemetry {
138140 * Gets the common properties for events
139141 * @returns Object containing common properties for all events
140142 */
141- private async getCommonProperties ( ) : Promise < CommonProperties > {
143+ private getCommonProperties ( ) : CommonProperties {
142144 return {
143145 ...MACHINE_METADATA ,
144146 mcp_client_version : this . session . agentRunner ?. version ,
145147 mcp_client_name : this . session . agentRunner ?. name ,
146148 session_id : this . session . sessionId ,
147149 config_atlas_auth : this . session . apiClient . hasCredentials ( ) ? "true" : "false" ,
148150 config_connection_string : this . userConfig . connectionString ? "true" : "false" ,
149- is_container_env : ( await this . containerEnvPromise ) ? "true" : "false" ,
150- device_id : await this . deviceIdPromise ,
151+ is_container_env : this . containerEnv ? "true" : "false" ,
152+ device_id : this . deviceId ,
151153 } ;
152154 }
153155
@@ -204,11 +206,10 @@ export class Telemetry {
204206 * Attempts to send events through the provided API client
205207 */
206208 private async sendEvents ( client : ApiClient , events : BaseEvent [ ] ) : Promise < void > {
207- const commonProperties = await this . getCommonProperties ( ) ;
208209 await client . sendEvents (
209210 events . map ( ( event ) => ( {
210211 ...event ,
211- properties : { ...commonProperties , ...event . properties } ,
212+ properties : { ...this . getCommonProperties ( ) , ...event . properties } ,
212213 } ) )
213214 ) ;
214215 }
0 commit comments