diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 978d6c3be5491..16b0b1e13c49a 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -17,7 +17,7 @@ import Performance from '@libs/Performance'; import {isPublicRoom, isValidReport} from '@libs/ReportUtils'; import {isLoggingInAsNewUser as isLoggingInAsNewUserSessionUtils} from '@libs/SessionUtils'; import {clearSoundAssetsCache} from '@libs/Sound'; -import {endSpan, getSpan, startSpan} from '@libs/telemetry/activeSpans'; +import {cancelAllSpans, endSpan, getSpan, startSpan} from '@libs/telemetry/activeSpans'; import CONST from '@src/CONST'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -238,6 +238,7 @@ AppState.addEventListener('change', (nextAppState) => { if (nextAppState.match(/inactive|background/) && appState === 'active') { Log.info('Flushing logs as app is going inactive', true, {}, true); saveCurrentPathBeforeBackground(); + cancelAllSpans(); } appState = nextAppState; }); diff --git a/src/libs/telemetry/activeSpans.ts b/src/libs/telemetry/activeSpans.ts index 8ccf608165707..6d807b94e4e30 100644 --- a/src/libs/telemetry/activeSpans.ts +++ b/src/libs/telemetry/activeSpans.ts @@ -46,8 +46,14 @@ function cancelSpan(spanId: string) { endSpan(spanId); } +function cancelAllSpans() { + for (const [spanId] of activeSpans.entries()) { + cancelSpan(spanId); + } +} + function getSpan(spanId: string) { return activeSpans.get(spanId); } -export {startSpan, endSpan, getSpan, cancelSpan}; +export {startSpan, endSpan, getSpan, cancelSpan, cancelAllSpans};