Skip to content

Commit a844d6b

Browse files
authored
Merge pull request #84415 from callstack-internal/perf/isolate-gps-wait-from-submit-span
[No QA] perf: Isolate GPS wait from ManualCreateExpenseSubmit telemetry span
2 parents 656be5e + 5cfd39f commit a844d6b

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,7 @@ const CONST = {
18391839
SPAN_NAVIGATE_AFTER_EXPENSE_CREATE: 'ManualCreateExpenseNavigation',
18401840
SPAN_SUBMIT_TO_DESTINATION_VISIBLE: 'ManualSubmitToDestinationVisible',
18411841
SPAN_EXPENSE_SERVER_RESPONSE: 'ManualCreateExpenseServerResponse',
1842+
SPAN_GEOLOCATION_WAIT: 'ManualGeolocationWait',
18421843
SPAN_SEND_MESSAGE: 'ManualSendMessage',
18431844
SPAN_NOT_FOUND_PAGE: 'ManualNotFoundPage',
18441845
SPAN_SKELETON: 'ManualSkeleton',

src/pages/iou/request/step/IOURequestStepConfirmation.tsx

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,32 @@ import withWritableReportOrNotFound from './withWritableReportOrNotFound';
122122
type IOURequestStepConfirmationProps = WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION> &
123123
WithFullTransactionOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION>;
124124

125+
// Ends the submit expense span, starts a geolocation child span, then calls getCurrentPosition.
126+
// The expense callback receives GPS coordinates on success or undefined on error.
127+
// Extracted to avoid duplicating this identical telemetry block across trackExpense and requestMoney paths.
128+
function getCurrentPositionWithGeolocationSpan(onPosition: (gpsCoords?: {lat: number; long: number}) => void) {
129+
const parentSpan = getSpan(CONST.TELEMETRY.SPAN_SUBMIT_EXPENSE);
130+
markSubmitExpenseEnd();
131+
132+
startSpan(CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT, {
133+
name: CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT,
134+
op: CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT,
135+
parentSpan,
136+
});
137+
138+
getCurrentPosition(
139+
(successData) => {
140+
onPosition({lat: successData.coords.latitude, long: successData.coords.longitude});
141+
endSpan(CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT);
142+
},
143+
(errorData) => {
144+
Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData);
145+
onPosition();
146+
endSpan(CONST.TELEMETRY.SPAN_GEOLOCATION_WAIT);
147+
},
148+
);
149+
}
150+
125151
function IOURequestStepConfirmation({
126152
report: reportReal,
127153
reportDraft,
@@ -1238,21 +1264,7 @@ function IOURequestStepConfirmation({
12381264
return;
12391265
}
12401266

1241-
getCurrentPosition(
1242-
(successData) => {
1243-
trackExpense(selectedParticipants, {
1244-
lat: successData.coords.latitude,
1245-
long: successData.coords.longitude,
1246-
});
1247-
markSubmitExpenseEnd();
1248-
},
1249-
(errorData) => {
1250-
Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData);
1251-
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
1252-
trackExpense(selectedParticipants);
1253-
markSubmitExpenseEnd();
1254-
},
1255-
);
1267+
getCurrentPositionWithGeolocationSpan((gpsCoords) => trackExpense(selectedParticipants, gpsCoords));
12561268
return;
12571269
}
12581270

@@ -1290,21 +1302,7 @@ function IOURequestStepConfirmation({
12901302
return;
12911303
}
12921304

1293-
getCurrentPosition(
1294-
(successData) => {
1295-
requestMoney(selectedParticipants, {
1296-
lat: successData.coords.latitude,
1297-
long: successData.coords.longitude,
1298-
});
1299-
markSubmitExpenseEnd();
1300-
},
1301-
(errorData) => {
1302-
Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData);
1303-
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
1304-
requestMoney(selectedParticipants);
1305-
markSubmitExpenseEnd();
1306-
},
1307-
);
1305+
getCurrentPositionWithGeolocationSpan((gpsCoords) => requestMoney(selectedParticipants, gpsCoords));
13081306
return;
13091307
}
13101308

0 commit comments

Comments
 (0)