diff --git a/packages/telemetry/src/flight-recorder.js b/packages/telemetry/src/flight-recorder.js index afddada5fbab..254acad53139 100644 --- a/packages/telemetry/src/flight-recorder.js +++ b/packages/telemetry/src/flight-recorder.js @@ -272,18 +272,18 @@ export const makeSimpleCircularBuffer = async ({ * @param {Pick>, 'writeCircBuf'>} circBuf */ export const makeSlogSenderFromBuffer = ({ writeCircBuf }) => { - let writes = []; + let toWrite = Promise.resolve(); const writeJSON = (obj, serialized = serializeSlogObj(obj)) => { // Prepend a newline so that the file can be more easily manipulated. const data = new TextEncoder().encode(`\n${serialized}`); // console.log('have obj', obj, data); - writes.push(writeCircBuf(data)); + toWrite = toWrite.then(() => writeCircBuf(data)); }; return Object.assign(writeJSON, { forceFlush: async () => { - const flushing = [...writes]; - writes = []; - return Promise.all(flushing).then(() => {}); + const writing = toWrite; + toWrite = Promise.resolve(); + await writing; }, usesJsonObject: true, });