diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 585839bb1baaa..b336dbf5af553 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -1805,6 +1805,7 @@ const CONST = { SPAN_SUBMIT_EXPENSE: 'ManualCreateExpenseSubmit', SPAN_NAVIGATE_AFTER_EXPENSE_CREATE: 'ManualCreateExpenseNavigation', SPAN_EXPENSE_SERVER_RESPONSE: 'ManualCreateExpenseServerResponse', + SPAN_GEOLOCATION_WAIT: 'ManualGeolocationWait', SPAN_SEND_MESSAGE: 'ManualSendMessage', SPAN_NOT_FOUND_PAGE: 'ManualNotFoundPage', SPAN_SKELETON: 'ManualSkeleton', diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e34c62f7fbfb3..3f461ba215404 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -120,6 +120,32 @@ import withWritableReportOrNotFound from './withWritableReportOrNotFound'; type IOURequestStepConfirmationProps = WithWritableReportOrNotFoundProps & WithFullTransactionOrNotFoundProps; +// Ends the submit expense span, starts a geolocation child span, then calls getCurrentPosition. +// The expense callback receives GPS coordinates on success or undefined on error. +// Extracted to avoid duplicating this identical telemetry block across trackExpense and requestMoney paths. +function getCurrentPositionWithGeolocationSpan(onPosition: (gpsCoords?: {lat: number; long: number}) => void) { + const parentSpan = getSpan(CONST.TELEMETRY.SPAN_SUBMIT_EXPENSE); + markSubmitExpenseEnd(); + + startSpan(CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT, { + name: CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT, + op: CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT, + parentSpan, + }); + + getCurrentPosition( + (successData) => { + onPosition({lat: successData.coords.latitude, long: successData.coords.longitude}); + endSpan(CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT); + }, + (errorData) => { + Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData); + onPosition(); + endSpan(CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT); + }, + ); +} + function IOURequestStepConfirmation({ report: reportReal, reportDraft, @@ -1214,21 +1240,7 @@ function IOURequestStepConfirmation({ return; } - getCurrentPosition( - (successData) => { - trackExpense(selectedParticipants, { - lat: successData.coords.latitude, - long: successData.coords.longitude, - }); - markSubmitExpenseEnd(); - }, - (errorData) => { - Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData); - // When there is an error, the money can still be requested, it just won't include the GPS coordinates - trackExpense(selectedParticipants); - markSubmitExpenseEnd(); - }, - ); + getCurrentPositionWithGeolocationSpan((gpsCoords) => trackExpense(selectedParticipants, gpsCoords)); return; } @@ -1266,21 +1278,7 @@ function IOURequestStepConfirmation({ return; } - getCurrentPosition( - (successData) => { - requestMoney(selectedParticipants, { - lat: successData.coords.latitude, - long: successData.coords.longitude, - }); - markSubmitExpenseEnd(); - }, - (errorData) => { - Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData); - // When there is an error, the money can still be requested, it just won't include the GPS coordinates - requestMoney(selectedParticipants); - markSubmitExpenseEnd(); - }, - ); + getCurrentPositionWithGeolocationSpan((gpsCoords) => requestMoney(selectedParticipants, gpsCoords)); return; }