Skip to content

Commit 2c8f60d

Browse files
elirangoshenclaude
andcommitted
Add Sentry spans to measure sequential queue command execution time
Track performance per command name in the sequential queue using Sentry spans. PusherPing is excluded to avoid heartbeat noise in telemetry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d3c00a5 commit 2c8f60d

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/CONST/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ const CONST = {
17991799
SPAN_OPEN_SEARCH_ROUTER: 'ManualOpenSearchRouter',
18001800
SPAN_OPEN_CREATE_EXPENSE: 'ManualOpenCreateExpense',
18011801
SPAN_SEND_MESSAGE: 'ManualSendMessage',
1802+
SPAN_SEQUENTIAL_QUEUE_COMMAND: 'SequentialQueueCommand',
18021803
SPAN_NOT_FOUND_PAGE: 'ManualNotFoundPage',
18031804
SPAN_SKELETON: 'ManualSkeleton',
18041805
SPAN_NAVIGATION_ROOT_READY: 'NavigationRootReady',
@@ -1835,6 +1836,7 @@ const CONST = {
18351836
ATTRIBUTE_CANCELED: 'canceled',
18361837
ATTRIBUTE_ROUTE_FROM: 'route_from',
18371838
ATTRIBUTE_ROUTE_TO: 'route_to',
1839+
ATTRIBUTE_COMMAND_NAME: 'command_name',
18381840
ATTRIBUTE_MIN_DURATION: 'min_duration',
18391841
ATTRIBUTE_FINISHED_MANUALLY: 'finished_manually',
18401842
ATTRIBUTE_SKELETON_PREFIX: 'skeleton.',

src/libs/Network/SequentialQueue.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {OnyxKey, OnyxUpdate} from 'react-native-onyx';
22
import Onyx from 'react-native-onyx';
33
import {setIsOpenAppFailureModalOpen} from '@libs/actions/isOpenAppFailureModalOpen';
4+
import {endSpan, startSpan} from '@libs/telemetry/activeSpans';
45
import {
56
deleteRequestsByIndices as deletePersistedRequestsByIndices,
67
endRequestAndRemoveFromQueue as endPersistedRequestAndRemoveFromQueue,
@@ -157,6 +158,19 @@ function process(): Promise<void> {
157158
persistWhenOngoing: requestToProcess.persistWhenOngoing ?? false,
158159
});
159160

161+
const commandSpanId = `${CONST.TELEMETRY.SPAN_SEQUENTIAL_QUEUE_COMMAND}_${requestToProcess.command}`;
162+
// Skip tracking PusherPing — it fires every 30s as a heartbeat and would spam telemetry
163+
const shouldTrackSpan = requestToProcess.command !== WRITE_COMMANDS.PUSHER_PING;
164+
if (shouldTrackSpan) {
165+
startSpan(commandSpanId, {
166+
name: CONST.TELEMETRY.SPAN_SEQUENTIAL_QUEUE_COMMAND,
167+
op: CONST.TELEMETRY.SPAN_SEQUENTIAL_QUEUE_COMMAND,
168+
attributes: {
169+
[CONST.TELEMETRY.ATTRIBUTE_COMMAND_NAME]: requestToProcess.command,
170+
},
171+
});
172+
}
173+
160174
// Set the current request to a promise awaiting its processing so that getCurrentRequest can be used to take some action after the current request has processed.
161175
currentRequestPromise = processWithMiddleware(requestToProcess, true)
162176
.then((response) => {
@@ -177,6 +191,7 @@ function process(): Promise<void> {
177191
command: requestToProcess.command,
178192
remainingRequests: getAllPersistedRequests().length,
179193
});
194+
endSpan(commandSpanId);
180195
endPersistedRequestAndRemoveFromQueue(requestToProcess);
181196

182197
if (requestToProcess.queueFlushedData) {
@@ -216,6 +231,7 @@ function process(): Promise<void> {
216231
errorName: error.name,
217232
errorMessage: error.message,
218233
});
234+
endSpan(commandSpanId);
219235
endPersistedRequestAndRemoveFromQueue(requestToProcess);
220236
sequentialQueueRequestThrottle.clear();
221237
return process();
@@ -226,6 +242,7 @@ function process(): Promise<void> {
226242
command: requestToProcess.command,
227243
});
228244
Onyx.update(requestToProcess.failureData ?? []);
245+
endSpan(commandSpanId);
229246
endPersistedRequestAndRemoveFromQueue(requestToProcess);
230247
sequentialQueueRequestThrottle.clear();
231248
return process();
@@ -236,6 +253,7 @@ function process(): Promise<void> {
236253
errorMessage: error.message,
237254
});
238255

256+
endSpan(commandSpanId);
239257
rollbackOngoingPersistedRequest();
240258
return sequentialQueueRequestThrottle
241259
.sleep(error, requestToProcess.command)

0 commit comments

Comments
 (0)