Skip to content

Commit e749645

Browse files
committed
Add OnyxUpdates.applyHTTPSOnyxUpdates Sentry span for perf comparison
Wraps applyHTTPSOnyxUpdates in a Sentry span via the existing @libs/telemetry/activeSpans helper so we can measure local Onyx-update processing time per API response, isolated from network latency. Cold-cache mergeCollection batches dominate this duration during OpenApp / ReconnectApp / Search, so this span is a clean A/B-test signal for mergeCollectionWithPatches changes (cache-first ordering and multiGet pre-warm). Span attributes: command, onyx_data_count, success_data_count, failure_data_count. Local console output via the helper: [Sentry][OnyxUpdates.applyHTTPSOnyxUpdates:OpenApp:<id>] Ending span (Xms) Not for merge -- perf-test instrumentation only.
1 parent c0821dd commit e749645

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ const CONST = {
20612061
EMOJI_TRIE_BUILD: 'LocaleEmojiTrieBuild',
20622062
},
20632063
SPAN_ONYX_DERIVED_COMPUTE: 'OnyxDerivedCompute',
2064+
SPAN_ONYX_UPDATES_APPLY_HTTPS: 'OnyxUpdates.applyHTTPSOnyxUpdates',
20642065
SPAN_NAVIGATION: {
20652066
ROOT: 'BootsplashVisibleNavigation',
20662067
PUSHER_INIT: 'NavigationPusherInit',

src/libs/actions/OnyxUpdates.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {Merge} from 'type-fest';
44
import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
55
import Log from '@libs/Log';
66
import PusherUtils from '@libs/PusherUtils';
7+
import {endSpan, startSpan} from '@libs/telemetry/activeSpans';
78
import {trackExpenseApiError} from '@libs/telemetry/trackExpenseCreationError';
89
import CONST from '@src/CONST';
910
import ONYXKEYS from '@src/ONYXKEYS';
@@ -30,6 +31,23 @@ let airshipEventsPromise = Promise.resolve();
3031

3132
function applyHTTPSOnyxUpdates<TKey extends OnyxKey>(request: Request<TKey>, response: Response<TKey>, lastUpdateID: number) {
3233
Log.info('[OnyxUpdateManager] Applying https update', false, {lastUpdateID});
34+
35+
// Perf-test instrumentation: measure local Onyx-update processing time per API response
36+
// (excludes network time). Cold-cache mergeCollection batches dominate this duration during
37+
// OpenApp / ReconnectApp / Search; comparing this span across branches isolates the impact
38+
// of mergeCollectionWithPatches changes (cache-first ordering, multiGet pre-warm).
39+
const spanId = `${CONST.TELEMETRY.SPAN_ONYX_UPDATES_APPLY_HTTPS}:${request?.command ?? 'unknown'}:${lastUpdateID}`;
40+
startSpan(spanId, {
41+
name: CONST.TELEMETRY.SPAN_ONYX_UPDATES_APPLY_HTTPS,
42+
op: 'onyx.updates.apply.https',
43+
attributes: {
44+
command: String(request?.command ?? 'unknown'),
45+
onyx_data_count: Array.isArray(response.onyxData) ? response.onyxData.length : 0,
46+
success_data_count: Array.isArray(request?.successData) ? request.successData.length : 0,
47+
failure_data_count: Array.isArray(request?.failureData) ? request.failureData.length : 0,
48+
},
49+
});
50+
3351
// For most requests we can immediately update Onyx. For write requests we queue the updates and apply them after the sequential queue has flushed to prevent a replay effect in
3452
// the UI. See https://github.com/Expensify/App/issues/12775 for more info.
3553
const updateHandler: (updates: Array<OnyxUpdate<TKey>>) => Promise<unknown> = request?.data?.apiRequestType === CONST.API_REQUEST_TYPE.WRITE ? queueOnyxUpdates : Onyx.update;
@@ -75,6 +93,9 @@ function applyHTTPSOnyxUpdates<TKey extends OnyxKey>(request: Request<TKey>, res
7593
.then(() => {
7694
Log.info('[OnyxUpdateManager] Done applying HTTPS update', false, {lastUpdateID});
7795
return Promise.resolve(response);
96+
})
97+
.finally(() => {
98+
endSpan(spanId);
7899
});
79100
}
80101

0 commit comments

Comments
 (0)