@@ -39,8 +39,8 @@ async function isContainerized(): Promise<boolean> {
39
39
}
40
40
41
41
export class Telemetry {
42
- private deviceIdPromise : Promise < string > | undefined ;
43
- private containerEnvPromise : Promise < boolean > | undefined ;
42
+ private deviceId : string | undefined ;
43
+ private containerEnv : boolean | undefined ;
44
44
private deviceIdAbortController = new AbortController ( ) ;
45
45
private eventCache : EventCache ;
46
46
private getRawMachineId : ( ) => Promise < string > ;
@@ -64,7 +64,7 @@ export class Telemetry {
64
64
this . getContainerEnv = getContainerEnv ;
65
65
}
66
66
67
- static create (
67
+ static async create (
68
68
session : Session ,
69
69
userConfig : UserConfig ,
70
70
{
@@ -76,23 +76,23 @@ export class Telemetry {
76
76
getRawMachineId ?: ( ) => Promise < string > ;
77
77
getContainerEnv ?: ( ) => Promise < boolean > ;
78
78
} = { }
79
- ) : Telemetry {
79
+ ) : Promise < Telemetry > {
80
80
const instance = new Telemetry ( session , userConfig , {
81
81
eventCache,
82
82
getRawMachineId,
83
83
getContainerEnv,
84
84
} ) ;
85
85
86
- instance . start ( ) ;
86
+ await instance . start ( ) ;
87
87
return instance ;
88
88
}
89
89
90
- private start ( ) : void {
90
+ private async start ( ) : Promise < void > {
91
91
if ( ! this . isTelemetryEnabled ( ) ) {
92
92
return ;
93
93
}
94
94
95
- this . deviceIdPromise = getDeviceId ( {
95
+ const deviceIdPromise = getDeviceId ( {
96
96
getMachineId : ( ) => this . getRawMachineId ( ) ,
97
97
onError : ( reason , error ) => {
98
98
switch ( reason ) {
@@ -109,7 +109,9 @@ export class Telemetry {
109
109
} ,
110
110
abortSignal : this . deviceIdAbortController . signal ,
111
111
} ) ;
112
- this . containerEnvPromise = this . getContainerEnv ( ) ;
112
+ const containerEnvPromise = this . getContainerEnv ( ) ;
113
+
114
+ [ this . deviceId , this . containerEnv ] = await Promise . all ( [ deviceIdPromise , containerEnvPromise ] ) ;
113
115
}
114
116
115
117
public async close ( ) : Promise < void > {
@@ -138,16 +140,16 @@ export class Telemetry {
138
140
* Gets the common properties for events
139
141
* @returns Object containing common properties for all events
140
142
*/
141
- private async getCommonProperties ( ) : Promise < CommonProperties > {
143
+ private getCommonProperties ( ) : CommonProperties {
142
144
return {
143
145
...MACHINE_METADATA ,
144
146
mcp_client_version : this . session . agentRunner ?. version ,
145
147
mcp_client_name : this . session . agentRunner ?. name ,
146
148
session_id : this . session . sessionId ,
147
149
config_atlas_auth : this . session . apiClient . hasCredentials ( ) ? "true" : "false" ,
148
150
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 ,
151
153
} ;
152
154
}
153
155
@@ -204,11 +206,10 @@ export class Telemetry {
204
206
* Attempts to send events through the provided API client
205
207
*/
206
208
private async sendEvents ( client : ApiClient , events : BaseEvent [ ] ) : Promise < void > {
207
- const commonProperties = await this . getCommonProperties ( ) ;
208
209
await client . sendEvents (
209
210
events . map ( ( event ) => ( {
210
211
...event ,
211
- properties : { ...commonProperties , ...event . properties } ,
212
+ properties : { ...this . getCommonProperties ( ) , ...event . properties } ,
212
213
} ) )
213
214
) ;
214
215
}
0 commit comments