@@ -106,38 +106,39 @@ export class Telemetry {
106
106
private async getCommonProperties ( ) : Promise < CommonProperties > {
107
107
if ( ! this . cachedCommonProperties ) {
108
108
let deviceId : string | undefined ;
109
- try {
110
- deviceId = await getDeviceId ( {
111
- getMachineId : ( ) => this . getRawMachineId ( ) ,
112
- onError : ( reason , error ) => {
113
- switch ( reason ) {
114
- case "resolutionError" :
115
- logger . debug ( LogId . telemetryDeviceIdFailure , "telemetry" , String ( error ) ) ;
116
- break ;
117
- case "timeout" :
118
- logger . debug (
119
- LogId . telemetryDeviceIdTimeout ,
120
- "telemetry" ,
121
- "Device ID retrieval timed out"
122
- ) ;
123
- break ;
124
- case "abort" :
125
- // No need to log in the case of aborts
126
- break ;
127
- }
128
- } ,
129
- abortSignal : this .
10000
deviceIdAbortController . signal ,
130
- } ) ;
131
- } catch ( error : unknown ) {
132
- const err = error instanceof Error ? error : new Error ( String ( error ) ) ;
133
- logger . debug ( LogId . telemetryDeviceIdFailure , "telemetry" , err . message ) ;
134
- }
135
109
let containerEnv : boolean | undefined ;
136
110
try {
137
- containerEnv = await this . getContainerEnv ( ) ;
111
+ await Promise . all ( [
112
+ getDeviceId ( {
113
+ getMachineId : ( ) => this . getRawMachineId ( ) ,
114
+ onError : ( reason , error ) => {
115
+ switch ( reason ) {
116
+ case "resolutionError" :
117
+ logger . debug ( LogId . telemetryDeviceIdFailure , "telemetry" , String ( error ) ) ;
118
+ break ;
119
+ case "timeout" :
120
+ logger . debug (
121
+ LogId . telemetryDeviceIdTimeout ,
122
+ "telemetry" ,
123
+ "Device ID retrieval timed out"
124
+ ) ;
125
+ break ;
126
+ case "abort" :
127
+ // No need to log in the case of aborts
128
+ break ;
129
+ }
130
+ } ,
131
+ abortSignal : this . deviceIdAbortController . signal ,
132
+ } ) . then ( ( id ) => {
133
+ deviceId = id ;
134
+ } ) ,
135
+ this . getContainerEnv ( ) . then ( ( env ) => {
136
+ containerEnv = env ;
137
+ } ) ,
138
+ ] ) ;
138
139
} catch ( error : unknown ) {
139
140
const err = error instanceof Error ? error : new Error ( String ( error ) ) ;
140
- logger . debug ( LogId . telemetryContainerEnvFailure , "telemetry" , err . message ) ;
141
+ logger . debug ( LogId . telemetryDeviceIdFailure , "telemetry" , err . message ) ;
141
142
}
142
143
this . cachedCommonProperties = {
143
144
...MACHINE_METADATA ,
@@ -183,6 +184,9 @@ export class Telemetry {
183
184
184
185
if ( this . flushing ) {
185
186
this . eventCache . appendEvents ( events ?? [ ] ) ;
187
+ process . nextTick ( ( ) => { // try again if in the middle of a flush
188
+ this . flush ( ) ;
189
+ } ) ;
186
190
return ;
187
191
}
188
192
@@ -191,6 +195,10 @@ export class Telemetry {
191
195
try {
192
196
const cachedEvents = this . eventCache . getEvents ( ) ;
193
197
const allEvents = [ ...cachedEvents , ...( events ?? [ ] ) ] ;
198
+ if ( allEvents . length <= 0 ) {
199
+ this . flushing = false ;
200
+ return ;
201
+ }
194
202
195
203
logger . debug (
196
204
LogId . telemetryEmitStart ,
@@ -212,6 +220,9 @@ export class Telemetry {
212
220
`Error sending event to client: ${ error instanceof Error ? error . message : String ( error ) } `
213
221
) ;
214
222
this . eventCache . appendEvents ( events ?? [ ] ) ;
223
+ process . nextTick ( ( ) => { // try again
224
+ this . flush ( ) ;
225
+ } ) ;
215
226
}
216
227
217
228
this . flushing = false ;
0 commit comments