@atlaskit/react-ufo 2.4.7 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/additional-payload/utils/lighthouse-metrics/utils/buffer/index.js +2 -4
- package/dist/cjs/common/constants.js +2 -1
- package/dist/cjs/config/index.js +18 -40
- package/dist/cjs/create-payload/common/utils/index.js +1 -85
- package/dist/cjs/create-payload/index.js +77 -37
- package/dist/cjs/interaction-metrics/common/constants.js +1 -7
- package/dist/cjs/interaction-metrics/index.js +205 -140
- package/dist/cjs/interaction-metrics/post-interaction-log.js +1 -2
- package/dist/cjs/interaction-metrics-init/index.js +9 -27
- package/dist/cjs/load-hold/UFOLoadHold.js +4 -3
- package/dist/cjs/segment/segment.js +9 -7
- package/dist/cjs/trace-pageload/index.js +1 -2
- package/dist/cjs/vc/vc-observer/index.js +50 -38
- package/dist/cjs/vc/vc-observer/observers/editor-lnv/index.js +1 -2
- package/dist/cjs/vc/vc-observer/observers/editor-lnv/test-utils.js +1 -2
- package/dist/cjs/vc/vc-observer/observers/index.js +1 -2
- package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +1 -2
- package/dist/es2019/common/constants.js +3 -1
- package/dist/es2019/config/index.js +0 -22
- package/dist/es2019/create-payload/common/utils/index.js +1 -86
- package/dist/es2019/create-payload/index.js +74 -28
- package/dist/es2019/interaction-metrics/common/constants.js +0 -6
- package/dist/es2019/interaction-metrics/index.js +130 -93
- package/dist/es2019/interaction-metrics-init/index.js +8 -21
- package/dist/es2019/load-hold/UFOLoadHold.js +4 -3
- package/dist/es2019/segment/segment.js +12 -6
- package/dist/es2019/trace-pageload/index.js +1 -1
- package/dist/es2019/vc/vc-observer/index.js +17 -5
- package/dist/esm/additional-payload/utils/lighthouse-metrics/utils/buffer/index.js +2 -4
- package/dist/esm/common/constants.js +3 -1
- package/dist/esm/config/index.js +18 -39
- package/dist/esm/create-payload/common/utils/index.js +1 -80
- package/dist/esm/create-payload/index.js +75 -33
- package/dist/esm/interaction-metrics/common/constants.js +0 -6
- package/dist/esm/interaction-metrics/index.js +157 -88
- package/dist/esm/interaction-metrics/post-interaction-log.js +1 -2
- package/dist/esm/interaction-metrics-init/index.js +10 -24
- package/dist/esm/load-hold/UFOLoadHold.js +4 -3
- package/dist/esm/segment/segment.js +9 -7
- package/dist/esm/trace-pageload/index.js +1 -1
- package/dist/esm/vc/vc-observer/index.js +50 -38
- package/dist/esm/vc/vc-observer/observers/editor-lnv/index.js +1 -2
- package/dist/esm/vc/vc-observer/observers/editor-lnv/test-utils.js +1 -2
- package/dist/esm/vc/vc-observer/observers/index.js +1 -2
- package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +1 -2
- package/dist/types/common/common/types.d.ts +4 -6
- package/dist/types/config/index.d.ts +0 -6
- package/dist/types/create-payload/common/utils/index.d.ts +0 -12
- package/dist/types/create-payload/index.d.ts +5660 -13
- package/dist/types/interaction-metrics/common/constants.d.ts +1 -31
- package/dist/types/interaction-metrics/index.d.ts +15 -4
- package/dist/types/load-hold/UFOLoadHold.d.ts +2 -1
- package/dist/types/trace-pageload/index.d.ts +0 -1
- package/dist/types/vc/vc-observer/index.d.ts +1 -1
- package/dist/types-ts4.5/common/common/types.d.ts +4 -6
- package/dist/types-ts4.5/config/index.d.ts +0 -6
- package/dist/types-ts4.5/create-payload/common/utils/index.d.ts +0 -12
- package/dist/types-ts4.5/create-payload/index.d.ts +5660 -13
- package/dist/types-ts4.5/interaction-metrics/common/constants.d.ts +1 -31
- package/dist/types-ts4.5/interaction-metrics/index.d.ts +15 -4
- package/dist/types-ts4.5/load-hold/UFOLoadHold.d.ts +2 -1
- package/dist/types-ts4.5/trace-pageload/index.d.ts +0 -1
- package/dist/types-ts4.5/vc/vc-observer/index.d.ts +1 -1
- package/package.json +6 -5
- package/create-experimental-interaction-metrics-payload/package.json +0 -15
- package/dist/cjs/create-experimental-interaction-metrics-payload/index.js +0 -89
- package/dist/cjs/interaction-metrics/common/index.js +0 -151
- package/dist/es2019/create-experimental-interaction-metrics-payload/index.js +0 -67
- package/dist/es2019/interaction-metrics/common/index.js +0 -103
- package/dist/esm/create-experimental-interaction-metrics-payload/index.js +0 -81
- package/dist/esm/interaction-metrics/common/index.js +0 -132
- package/dist/types/create-experimental-interaction-metrics-payload/index.d.ts +0 -31
- package/dist/types/interaction-metrics/common/index.d.ts +0 -16
- package/dist/types-ts4.5/create-experimental-interaction-metrics-payload/index.d.ts +0 -31
- package/dist/types-ts4.5/interaction-metrics/common/index.d.ts +0 -16
|
@@ -8,12 +8,13 @@ import { getBm3Timings } from '../custom-timings';
|
|
|
8
8
|
import { getGlobalErrorCount } from '../global-error-handler';
|
|
9
9
|
import { getPageVisibilityState } from '../hidden-timing';
|
|
10
10
|
import * as initialPageLoadExtraTiming from '../initial-page-load-extra-timing';
|
|
11
|
-
import { interactionSpans as atlaskitInteractionSpans } from '../interaction-metrics';
|
|
11
|
+
import { interactionSpans as atlaskitInteractionSpans, postInteractionLog } from '../interaction-metrics';
|
|
12
12
|
import * as resourceTiming from '../resource-timing';
|
|
13
13
|
import { roundEpsilon } from '../round-number';
|
|
14
14
|
import * as ssr from '../ssr';
|
|
15
|
-
import {
|
|
16
|
-
|
|
15
|
+
import { getVCObserver } from '../vc';
|
|
16
|
+
import { buildSegmentTree, labelStackStartWith, optimizeLabelStack, sanitizeUfoName, stringifyLabelStackFully } from './common/utils';
|
|
17
|
+
function getUfoNameOverride(interaction) {
|
|
17
18
|
const {
|
|
18
19
|
ufoName,
|
|
19
20
|
apdex
|
|
@@ -27,6 +28,7 @@ export function getUfoNameOverride(interaction) {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
return ufoName;
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
32
|
} catch (e) {
|
|
31
33
|
return ufoName;
|
|
32
34
|
}
|
|
@@ -61,6 +63,13 @@ const getPageVisibilityUpToTTI = interaction => {
|
|
|
61
63
|
const bm3EndTimeOrInteractionEndTime = getBm3EndTimeOrFallbackValue(interaction);
|
|
62
64
|
return getPageVisibilityState(start, bm3EndTimeOrInteractionEndTime);
|
|
63
65
|
};
|
|
66
|
+
const getPageVisibilityUpToTTAI = interaction => {
|
|
67
|
+
const {
|
|
68
|
+
start,
|
|
69
|
+
end
|
|
70
|
+
} = interaction;
|
|
71
|
+
return getPageVisibilityState(start, end);
|
|
72
|
+
};
|
|
64
73
|
const getVisibilityStateFromPerformance = stop => {
|
|
65
74
|
try {
|
|
66
75
|
const results = performance.getEntriesByType('visibility-state');
|
|
@@ -115,6 +124,15 @@ const getMoreAccuratePageVisibilityUpToTTAI = interaction => {
|
|
|
115
124
|
}
|
|
116
125
|
return old;
|
|
117
126
|
};
|
|
127
|
+
const getInteractionStatus = interaction => {
|
|
128
|
+
const originalInteractionStatus = interaction.abortReason ? 'ABORTED' : 'SUCCEEDED';
|
|
129
|
+
const hasBm3TTI = interaction.apdex.length > 0;
|
|
130
|
+
const overrideStatus = hasBm3TTI ? 'SUCCEEDED' : originalInteractionStatus;
|
|
131
|
+
return {
|
|
132
|
+
originalInteractionStatus,
|
|
133
|
+
overrideStatus
|
|
134
|
+
};
|
|
135
|
+
};
|
|
118
136
|
const getResourceTimings = (start, end) => {
|
|
119
137
|
var _resourceTiming$getRe;
|
|
120
138
|
return (_resourceTiming$getRe = resourceTiming.getResourceTimings(start, end)) !== null && _resourceTiming$getRe !== void 0 ? _resourceTiming$getRe : undefined;
|
|
@@ -137,6 +155,44 @@ const getPaintMetrics = type => {
|
|
|
137
155
|
});
|
|
138
156
|
return metrics;
|
|
139
157
|
};
|
|
158
|
+
const getVCMetrics = interaction => {
|
|
159
|
+
var _config$vc, _interaction$apdex, _interaction$apdex$;
|
|
160
|
+
const config = getConfig();
|
|
161
|
+
if (!(config !== null && config !== void 0 && (_config$vc = config.vc) !== null && _config$vc !== void 0 && _config$vc.enabled)) {
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
164
|
+
if (interaction.type !== 'page_load' && interaction.type !== 'transition') {
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
const ssr = interaction.type === 'page_load' && config !== null && config !== void 0 && config.ssr ? {
|
|
168
|
+
ssr: getSSRDoneTimeValue(config)
|
|
169
|
+
} : null;
|
|
170
|
+
postInteractionLog.setVCObserverSSRConfig(ssr);
|
|
171
|
+
const tti = (_interaction$apdex = interaction.apdex) === null || _interaction$apdex === void 0 ? void 0 : (_interaction$apdex$ = _interaction$apdex[0]) === null || _interaction$apdex$ === void 0 ? void 0 : _interaction$apdex$.stopTime;
|
|
172
|
+
const prefix = 'ufo';
|
|
173
|
+
const result = getVCObserver().getVCResult({
|
|
174
|
+
start: interaction.start,
|
|
175
|
+
stop: interaction.end,
|
|
176
|
+
tti,
|
|
177
|
+
prefix,
|
|
178
|
+
vc: interaction.vc,
|
|
179
|
+
...ssr
|
|
180
|
+
});
|
|
181
|
+
postInteractionLog.setLastInteractionFinishVCResult(result);
|
|
182
|
+
const VC = result === null || result === void 0 ? void 0 : result['metrics:vc'];
|
|
183
|
+
if (!VC || !(result !== null && result !== void 0 && result[`${prefix}:vc:clean`])) {
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
const interactionStatus = getInteractionStatus(interaction);
|
|
187
|
+
const pageVisibilityUpToTTAI = getPageVisibilityUpToTTAI(interaction);
|
|
188
|
+
if (interactionStatus.originalInteractionStatus !== 'SUCCEEDED' || pageVisibilityUpToTTAI !== 'visible') {
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
...result,
|
|
193
|
+
'metric:vc90': VC['90']
|
|
194
|
+
};
|
|
195
|
+
};
|
|
140
196
|
const getNavigationMetrics = type => {
|
|
141
197
|
if (type !== 'page_load') {
|
|
142
198
|
return {};
|
|
@@ -184,7 +240,7 @@ const getNavigationMetrics = type => {
|
|
|
184
240
|
};
|
|
185
241
|
};
|
|
186
242
|
const getPPSMetrics = interaction => {
|
|
187
|
-
var _interaction$
|
|
243
|
+
var _interaction$apdex2, _interaction$apdex2$;
|
|
188
244
|
const {
|
|
189
245
|
start,
|
|
190
246
|
end
|
|
@@ -192,7 +248,7 @@ const getPPSMetrics = interaction => {
|
|
|
192
248
|
const config = getConfig();
|
|
193
249
|
const interactionStatus = getInteractionStatus(interaction);
|
|
194
250
|
const pageVisibilityUpToTTAI = getPageVisibilityUpToTTAI(interaction);
|
|
195
|
-
const tti = (_interaction$
|
|
251
|
+
const tti = (_interaction$apdex2 = interaction.apdex) === null || _interaction$apdex2 === void 0 ? void 0 : (_interaction$apdex2$ = _interaction$apdex2[0]) === null || _interaction$apdex2$ === void 0 ? void 0 : _interaction$apdex2$.stopTime;
|
|
196
252
|
const ttai = interactionStatus.originalInteractionStatus === 'SUCCEEDED' && pageVisibilityUpToTTAI === 'visible' ? Math.round(end - start) : undefined;
|
|
197
253
|
const PPSMetricsAtTTI = tti !== undefined ? getLighthouseMetrics({
|
|
198
254
|
start,
|
|
@@ -538,6 +594,10 @@ function getBm3TrackerTimings(interaction) {
|
|
|
538
594
|
legacyMetrics
|
|
539
595
|
};
|
|
540
596
|
}
|
|
597
|
+
function getSSRDoneTimeValue(config) {
|
|
598
|
+
var _config$ssr, _config$ssr2;
|
|
599
|
+
return config !== null && config !== void 0 && (_config$ssr = config.ssr) !== null && _config$ssr !== void 0 && _config$ssr.getSSRDoneTime ? config === null || config === void 0 ? void 0 : (_config$ssr2 = config.ssr) === null || _config$ssr2 === void 0 ? void 0 : _config$ssr2.getSSRDoneTime() : ssr.getSSRDoneTime();
|
|
600
|
+
}
|
|
541
601
|
function getPayloadSize(payload) {
|
|
542
602
|
return Math.round(new TextEncoder().encode(JSON.stringify(payload)).length / 1024);
|
|
543
603
|
}
|
|
@@ -580,15 +640,13 @@ function getStylesheetMetrics() {
|
|
|
580
640
|
return {};
|
|
581
641
|
}
|
|
582
642
|
}
|
|
583
|
-
let regularTTAI;
|
|
584
|
-
let expTTAI;
|
|
585
643
|
function getErrorCounts(interaction) {
|
|
586
644
|
return {
|
|
587
645
|
'ufo:errors:globalCount': getGlobalErrorCount(),
|
|
588
646
|
'ufo:errors:count': interaction.errors.length
|
|
589
647
|
};
|
|
590
648
|
}
|
|
591
|
-
|
|
649
|
+
function createInteractionMetricsPayload(interaction, interactionId) {
|
|
592
650
|
var _window$location, _config$additionalPay;
|
|
593
651
|
const interactionPayloadStart = performance.now();
|
|
594
652
|
const config = getConfig();
|
|
@@ -623,7 +681,7 @@ export function createInteractionMetricsPayload(interaction, interactionId, expe
|
|
|
623
681
|
} : {};
|
|
624
682
|
// Page Load
|
|
625
683
|
const getPageLoadInteractionMetrics = () => {
|
|
626
|
-
var _config$
|
|
684
|
+
var _config$ssr3;
|
|
627
685
|
if (!isPageLoad) {
|
|
628
686
|
return {};
|
|
629
687
|
}
|
|
@@ -635,12 +693,12 @@ export function createInteractionMetricsPayload(interaction, interactionId, expe
|
|
|
635
693
|
return {
|
|
636
694
|
...SSRDoneTime,
|
|
637
695
|
isBM3ConfigSSRDoneAsFmp: interaction.metaData.__legacy__bm3ConfigSSRDoneAsFmp,
|
|
638
|
-
isUFOConfigSSRDoneAsFmp: interaction.metaData.__legacy__bm3ConfigSSRDoneAsFmp || !!(config !== null && config !== void 0 && (_config$
|
|
696
|
+
isUFOConfigSSRDoneAsFmp: interaction.metaData.__legacy__bm3ConfigSSRDoneAsFmp || !!(config !== null && config !== void 0 && (_config$ssr3 = config.ssr) !== null && _config$ssr3 !== void 0 && _config$ssr3.getSSRDoneTime)
|
|
639
697
|
};
|
|
640
698
|
};
|
|
641
699
|
// Detailed payload. Page visibility = visible
|
|
642
700
|
const getDetailedInteractionMetrics = () => {
|
|
643
|
-
if (
|
|
701
|
+
if (window.__UFO_COMPACT_PAYLOAD__ || !isDetailedPayload) {
|
|
644
702
|
return {};
|
|
645
703
|
}
|
|
646
704
|
const spans = [...interaction.spans, ...atlaskitInteractionSpans];
|
|
@@ -655,7 +713,7 @@ export function createInteractionMetricsPayload(interaction, interactionId, expe
|
|
|
655
713
|
})),
|
|
656
714
|
holdActive: [...interaction.holdActive.values()],
|
|
657
715
|
redirects: optimizeRedirects(interaction.redirects, start),
|
|
658
|
-
holdInfo: optimizeHoldInfo(
|
|
716
|
+
holdInfo: optimizeHoldInfo(interaction.holdInfo, start),
|
|
659
717
|
spans: optimizeSpans(spans, start),
|
|
660
718
|
requestInfo: optimizeRequestInfo(interaction.requestInfo, start),
|
|
661
719
|
customTimings: optimizeCustomTimings(interaction.customTimings, start),
|
|
@@ -665,21 +723,16 @@ export function createInteractionMetricsPayload(interaction, interactionId, expe
|
|
|
665
723
|
};
|
|
666
724
|
// Page load & detailed payload
|
|
667
725
|
const getPageLoadDetailedInteractionMetrics = () => {
|
|
668
|
-
var _config$
|
|
726
|
+
var _config$ssr4;
|
|
669
727
|
if (!isPageLoad || !isDetailedPayload) {
|
|
670
728
|
return {};
|
|
671
729
|
}
|
|
672
730
|
const config = getConfig();
|
|
673
731
|
return {
|
|
674
732
|
initialPageLoadExtraTimings: objectToArray(initialPageLoadExtraTiming.getTimings()),
|
|
675
|
-
SSRTimings: config !== null && config !== void 0 && (_config$
|
|
733
|
+
SSRTimings: config !== null && config !== void 0 && (_config$ssr4 = config.ssr) !== null && _config$ssr4 !== void 0 && _config$ssr4.getSSRTimings ? config.ssr.getSSRTimings() : objectToArray(ssr.getSSRTimings())
|
|
676
734
|
};
|
|
677
735
|
};
|
|
678
|
-
if (experimental) {
|
|
679
|
-
expTTAI = getTTAI(interaction);
|
|
680
|
-
} else {
|
|
681
|
-
regularTTAI = getTTAI(interaction);
|
|
682
|
-
}
|
|
683
736
|
const newUFOName = sanitizeUfoName(ufoName);
|
|
684
737
|
const payload = {
|
|
685
738
|
actionSubject: 'experience',
|
|
@@ -700,7 +753,7 @@ export function createInteractionMetricsPayload(interaction, interactionId, expe
|
|
|
700
753
|
payloadSource: 'platform'
|
|
701
754
|
},
|
|
702
755
|
'event:region': config.region || 'unknown',
|
|
703
|
-
'experience:key':
|
|
756
|
+
'experience:key': 'custom.interaction-metrics',
|
|
704
757
|
'experience:name': newUFOName,
|
|
705
758
|
// root
|
|
706
759
|
...getBrowserMetadata(),
|
|
@@ -709,7 +762,6 @@ export function createInteractionMetricsPayload(interaction, interactionId, expe
|
|
|
709
762
|
...getPaintMetrics(type),
|
|
710
763
|
...getNavigationMetrics(type),
|
|
711
764
|
...getVCMetrics(interaction),
|
|
712
|
-
...(experimental ? getExperimentalVCMetrics(interaction) : undefined),
|
|
713
765
|
...((_config$additionalPay = config.additionalPayloadData) === null || _config$additionalPay === void 0 ? void 0 : _config$additionalPay.call(config, interaction)),
|
|
714
766
|
...getTracingContextData(interaction),
|
|
715
767
|
...getStylesheetMetrics(),
|
|
@@ -749,18 +801,12 @@ export function createInteractionMetricsPayload(interaction, interactionId, expe
|
|
|
749
801
|
...getPageLoadInteractionMetrics(),
|
|
750
802
|
...getDetailedInteractionMetrics(),
|
|
751
803
|
...getPageLoadDetailedInteractionMetrics(),
|
|
752
|
-
...getBm3TrackerTimings(interaction)
|
|
753
|
-
'metric:ttai': experimental ? regularTTAI || expTTAI : undefined,
|
|
754
|
-
'metric:experimental:ttai': experimental ? expTTAI : undefined
|
|
804
|
+
...getBm3TrackerTimings(interaction)
|
|
755
805
|
},
|
|
756
806
|
'ufo:payloadTime': roundEpsilon(performance.now() - interactionPayloadStart)
|
|
757
807
|
}
|
|
758
808
|
}
|
|
759
809
|
};
|
|
760
|
-
if (experimental) {
|
|
761
|
-
regularTTAI = undefined;
|
|
762
|
-
expTTAI = undefined;
|
|
763
|
-
}
|
|
764
810
|
payload.attributes.properties['event:sizeInKb'] = getPayloadSize(payload.attributes.properties);
|
|
765
811
|
return payload;
|
|
766
812
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
const interactions = new Map();
|
|
2
|
-
export const CLEANUP_TIMEOUT = 60 * 1000;
|
|
3
|
-
export const CLEANUP_TIMEOUT_AFTER_APDEX = 15 * 1000;
|
|
4
|
-
export const interactionQueue = [];
|
|
5
|
-
export const segmentCache = new Map();
|
|
6
|
-
export const segmentObservers = [];
|
|
7
|
-
export const moduleLoadingRequests = {};
|
|
8
2
|
export default interactions;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { v4 as createUUID } from 'uuid';
|
|
2
2
|
import coinflip from '../coinflip';
|
|
3
3
|
import { getAwaitBM3TTIList, getCapabilityRate, getConfig } from '../config';
|
|
4
|
-
import { ExperimentalInteractionMetrics } from '../create-experimental-interaction-metrics-payload';
|
|
5
|
-
import { getExperimentalVCMetrics, getTTAI } from '../create-payload/common/utils';
|
|
6
4
|
import { clearActiveTrace } from '../experience-trace-id-context';
|
|
7
5
|
import { allFeatureFlagsAccessed, currentFeatureFlagsAccessed } from '../feature-flags-accessed';
|
|
8
6
|
import { getInteractionId } from '../interaction-id-context';
|
|
9
7
|
import { getVCObserver } from '../vc';
|
|
10
|
-
import
|
|
11
|
-
import interactions, { CLEANUP_TIMEOUT, CLEANUP_TIMEOUT_AFTER_APDEX, interactionQueue, moduleLoadingRequests, segmentCache, segmentObservers } from './common/constants';
|
|
8
|
+
import interactions from './common/constants';
|
|
12
9
|
import PostInteractionLog from './post-interaction-log';
|
|
13
10
|
const PreviousInteractionLog = {
|
|
14
11
|
name: undefined,
|
|
15
12
|
isAborted: undefined
|
|
16
13
|
};
|
|
17
14
|
export const postInteractionLog = new PostInteractionLog();
|
|
18
|
-
|
|
15
|
+
const interactionQueue = [];
|
|
16
|
+
const segmentCache = new Map();
|
|
17
|
+
const CLEANUP_TIMEOUT = 60 * 1000;
|
|
18
|
+
const CLEANUP_TIMEOUT_AFTER_APDEX = 15 * 1000;
|
|
19
|
+
const segmentObservers = [];
|
|
19
20
|
export function getActiveInteraction() {
|
|
20
21
|
const interactionId = getInteractionId();
|
|
21
22
|
if (!interactionId.current) {
|
|
@@ -23,6 +24,36 @@ export function getActiveInteraction() {
|
|
|
23
24
|
}
|
|
24
25
|
return interactions.get(interactionId.current);
|
|
25
26
|
}
|
|
27
|
+
function isPerformanceTracingEnabled() {
|
|
28
|
+
var _getConfig;
|
|
29
|
+
return ((_getConfig = getConfig()) === null || _getConfig === void 0 ? void 0 : _getConfig.enableAdditionalPerformanceMarks) || window.__REACT_UFO_ENABLE_PERF_TRACING || process.env.NODE_ENV !== 'production';
|
|
30
|
+
}
|
|
31
|
+
function labelStackToString(labelStack, name) {
|
|
32
|
+
var _stack$map;
|
|
33
|
+
const stack = [...(labelStack !== null && labelStack !== void 0 ? labelStack : [])];
|
|
34
|
+
if (name) {
|
|
35
|
+
stack.push({
|
|
36
|
+
name
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return (_stack$map = stack.map(l => l.name)) === null || _stack$map === void 0 ? void 0 : _stack$map.join('/');
|
|
40
|
+
}
|
|
41
|
+
function labelStackToIdString(labelStack) {
|
|
42
|
+
var _labelStack$map;
|
|
43
|
+
return labelStack === null || labelStack === void 0 ? void 0 : (_labelStack$map = labelStack.map(l => 'segmentId' in l ? `${l.name}:${l.segmentId}` : `${l.name}`)) === null || _labelStack$map === void 0 ? void 0 : _labelStack$map.join('/');
|
|
44
|
+
}
|
|
45
|
+
function addSegmentObserver(observer) {
|
|
46
|
+
segmentObservers.push(observer);
|
|
47
|
+
for (const segmentInfo of segmentCache.values()) {
|
|
48
|
+
observer.onAdd(segmentInfo);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function removeSegmentObserver(observer) {
|
|
52
|
+
const index = segmentObservers.findIndex(obs => obs === observer);
|
|
53
|
+
if (index !== -1) {
|
|
54
|
+
segmentObservers.splice(index, 1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
26
57
|
export function remove(interactionId) {
|
|
27
58
|
interactions.delete(interactionId);
|
|
28
59
|
}
|
|
@@ -165,6 +196,7 @@ export function addPreload(moduleId, timestamp) {
|
|
|
165
196
|
export function addLoad(identifier, start, end) {
|
|
166
197
|
addSpanToAll('bundle_load', identifier, null, start, end - start);
|
|
167
198
|
}
|
|
199
|
+
const moduleLoadingRequests = {};
|
|
168
200
|
export function extractModuleName(input) {
|
|
169
201
|
let result = input !== null && input !== void 0 ? input : '';
|
|
170
202
|
result = result.replace(/^\.\/src\/packages\//, '');
|
|
@@ -172,29 +204,30 @@ export function extractModuleName(input) {
|
|
|
172
204
|
result = result.replace(/(\/src)?\/(index|main)\.(tsx|ts|js|jsx)$/, '');
|
|
173
205
|
return result;
|
|
174
206
|
}
|
|
175
|
-
|
|
207
|
+
function addHoldCriterion(id, labelStack, name, startTime) {
|
|
208
|
+
var _window$__CRITERION__;
|
|
209
|
+
if (!((_window$__CRITERION__ = window.__CRITERION__) !== null && _window$__CRITERION__ !== void 0 && _window$__CRITERION__.addUFOHold)) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
window.__CRITERION__.addUFOHold(id, labelStackToString(labelStack), name, startTime);
|
|
213
|
+
}
|
|
214
|
+
function removeHoldCriterion(id) {
|
|
215
|
+
var _window$__CRITERION__2;
|
|
216
|
+
if (!((_window$__CRITERION__2 = window.__CRITERION__) !== null && _window$__CRITERION__2 !== void 0 && _window$__CRITERION__2.removeUFOHold)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
window.__CRITERION__.removeUFOHold(id);
|
|
220
|
+
}
|
|
221
|
+
export function addHold(interactionId, labelStack, name) {
|
|
176
222
|
const interaction = interactions.get(interactionId);
|
|
177
223
|
const id = createUUID();
|
|
178
224
|
if (interaction != null) {
|
|
179
|
-
|
|
180
|
-
|
|
225
|
+
const start = performance.now();
|
|
226
|
+
interaction.holdActive.set(id, {
|
|
181
227
|
labelStack,
|
|
182
228
|
name,
|
|
183
|
-
start
|
|
184
|
-
};
|
|
185
|
-
const start = performance.now();
|
|
186
|
-
if ((_getConfig = getConfig()) !== null && _getConfig !== void 0 && (_getConfig$experiment = _getConfig.experimentalInteractionMetrics) !== null && _getConfig$experiment !== void 0 && _getConfig$experiment.enabled && experimental) {
|
|
187
|
-
interaction.holdExpActive.set(id, {
|
|
188
|
-
...holdActive,
|
|
189
|
-
start
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
if (!experimental) {
|
|
193
|
-
interaction.holdActive.set(id, {
|
|
194
|
-
...holdActive,
|
|
195
|
-
start
|
|
196
|
-
});
|
|
197
|
-
}
|
|
229
|
+
start
|
|
230
|
+
});
|
|
198
231
|
addHoldCriterion(id, labelStack, name, start);
|
|
199
232
|
return () => {
|
|
200
233
|
const end = performance.now();
|
|
@@ -212,22 +245,12 @@ export function addHold(interactionId, labelStack, name, experimental) {
|
|
|
212
245
|
removeHoldCriterion(id);
|
|
213
246
|
const currentInteraction = interactions.get(interactionId);
|
|
214
247
|
const currentHold = interaction.holdActive.get(id);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
interaction.holdActive.delete(id);
|
|
223
|
-
}
|
|
224
|
-
if (expHold != null) {
|
|
225
|
-
currentInteraction.holdExpInfo.push({
|
|
226
|
-
...expHold,
|
|
227
|
-
end
|
|
228
|
-
});
|
|
229
|
-
interaction.holdExpActive.delete(id);
|
|
230
|
-
}
|
|
248
|
+
if (currentInteraction != null && currentHold != null) {
|
|
249
|
+
currentInteraction.holdInfo.push({
|
|
250
|
+
...currentHold,
|
|
251
|
+
end
|
|
252
|
+
});
|
|
253
|
+
interaction.holdActive.delete(id);
|
|
231
254
|
}
|
|
232
255
|
};
|
|
233
256
|
}
|
|
@@ -356,9 +379,21 @@ export const addProfilerTimings = (interactionId, labelStack, type, actualDurati
|
|
|
356
379
|
postInteractionLog.addProfilerTimings(labelStack, type, actualDuration, baseDuration, startTime, commitTime);
|
|
357
380
|
}
|
|
358
381
|
};
|
|
382
|
+
const pushToQueue = (id, data) => {
|
|
383
|
+
interactionQueue.push({
|
|
384
|
+
id,
|
|
385
|
+
data
|
|
386
|
+
});
|
|
387
|
+
};
|
|
359
388
|
let handleInteraction = pushToQueue;
|
|
389
|
+
function callCleanUpCallbacks(interaction) {
|
|
390
|
+
interaction.cleanupCallbacks.reverse().forEach(cleanUpCallback => {
|
|
391
|
+
cleanUpCallback();
|
|
392
|
+
});
|
|
393
|
+
}
|
|
360
394
|
const finishInteraction = (id, data, endTime = performance.now()) => {
|
|
361
395
|
var _getConfig3, _getConfig3$vc;
|
|
396
|
+
// eslint-disable-next-line no-param-reassign
|
|
362
397
|
data.end = endTime;
|
|
363
398
|
try {
|
|
364
399
|
// for Firefox 102 and older
|
|
@@ -370,20 +405,49 @@ const finishInteraction = (id, data, endTime = performance.now()) => {
|
|
|
370
405
|
// do nothing
|
|
371
406
|
}
|
|
372
407
|
if (data.featureFlags) {
|
|
408
|
+
// eslint-disable-next-line no-param-reassign
|
|
373
409
|
data.featureFlags.during = Object.fromEntries(currentFeatureFlagsAccessed);
|
|
374
410
|
}
|
|
375
411
|
clearActiveTrace();
|
|
376
412
|
callCleanUpCallbacks(data);
|
|
377
413
|
if ((_getConfig3 = getConfig()) !== null && _getConfig3 !== void 0 && (_getConfig3$vc = _getConfig3.vc) !== null && _getConfig3$vc !== void 0 && _getConfig3$vc.stopVCAtInteractionFinish) {
|
|
378
|
-
data.vc = getVCObserver().getVCRawData();
|
|
414
|
+
data.vc = getVCObserver().getVCRawData(data.end);
|
|
379
415
|
}
|
|
416
|
+
remove(id);
|
|
380
417
|
PreviousInteractionLog.name = data.ufoName || 'unknown';
|
|
381
418
|
PreviousInteractionLog.isAborted = data.abortReason != null;
|
|
382
419
|
if (data.ufoName) {
|
|
383
420
|
handleInteraction(id, data);
|
|
384
421
|
}
|
|
385
422
|
if (isPerformanceTracingEnabled()) {
|
|
386
|
-
|
|
423
|
+
const profilerTimingMap = new Map();
|
|
424
|
+
data.reactProfilerTimings.forEach(profilerTiming => {
|
|
425
|
+
const labelStackId = labelStackToIdString(profilerTiming.labelStack);
|
|
426
|
+
if (labelStackId) {
|
|
427
|
+
var _profilerTimingMap$ge, _timing$start, _timing$end;
|
|
428
|
+
const timing = (_profilerTimingMap$ge = profilerTimingMap.get(labelStackId)) !== null && _profilerTimingMap$ge !== void 0 ? _profilerTimingMap$ge : {
|
|
429
|
+
labelStack: profilerTiming.labelStack
|
|
430
|
+
};
|
|
431
|
+
timing.start = profilerTiming.startTime < ((_timing$start = timing.start) !== null && _timing$start !== void 0 ? _timing$start : Number.MAX_SAFE_INTEGER) ? profilerTiming.startTime : timing.start;
|
|
432
|
+
timing.end = profilerTiming.commitTime > ((_timing$end = timing.end) !== null && _timing$end !== void 0 ? _timing$end : Number.MIN_SAFE_INTEGER) ? profilerTiming.commitTime : timing.end;
|
|
433
|
+
profilerTimingMap.set(labelStackId, timing);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
try {
|
|
437
|
+
// for Firefox 102 and older
|
|
438
|
+
for (const [, {
|
|
439
|
+
labelStack,
|
|
440
|
+
start,
|
|
441
|
+
end
|
|
442
|
+
}] of profilerTimingMap.entries()) {
|
|
443
|
+
performance.measure(`🛸 ${labelStackToString(labelStack)} [segment_ttai]`, {
|
|
444
|
+
start,
|
|
445
|
+
end
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
} catch (e) {
|
|
449
|
+
// do nothing
|
|
450
|
+
}
|
|
387
451
|
}
|
|
388
452
|
try {
|
|
389
453
|
// dispatch a global window event to notify the measure is completed
|
|
@@ -403,93 +467,57 @@ export const sinkInteractionHandler = sinkFn => {
|
|
|
403
467
|
interactionQueue.length = 0;
|
|
404
468
|
}
|
|
405
469
|
};
|
|
406
|
-
export const sinkExperimentalHandler = sinkFn => {
|
|
407
|
-
experimentalInteractionLog.sinkHandler(sinkFn);
|
|
408
|
-
};
|
|
409
470
|
export const sinkPostInteractionLogHandler = sinkFn => {
|
|
410
471
|
postInteractionLog.sinkHandler(sinkFn);
|
|
411
472
|
};
|
|
412
|
-
|
|
413
|
-
// a flag to prevent mutliple submittions
|
|
414
|
-
let activeSubmitted = false;
|
|
415
473
|
export function tryComplete(interactionId, endTime) {
|
|
416
474
|
const interaction = interactions.get(interactionId);
|
|
417
475
|
if (interaction != null) {
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
const postInteraction = () => {
|
|
476
|
+
const noMoreHolds = interaction.holdActive.size === 0;
|
|
477
|
+
if (noMoreHolds) {
|
|
421
478
|
var _getConfig4, _getConfig4$postInter;
|
|
479
|
+
finishInteraction(interactionId, interaction, endTime);
|
|
422
480
|
if ((_getConfig4 = getConfig()) !== null && _getConfig4 !== void 0 && (_getConfig4$postInter = _getConfig4.postInteractionLog) !== null && _getConfig4$postInter !== void 0 && _getConfig4$postInter.enabled) {
|
|
423
|
-
|
|
424
|
-
const experimentalVC90 = (_getExperimentalVCMet = getExperimentalVCMetrics(interaction)) === null || _getExperimentalVCMet === void 0 ? void 0 : _getExperimentalVCMet['metric:experimental:vc90'];
|
|
425
|
-
const experimentalTTAI = getTTAI(interaction);
|
|
426
|
-
postInteractionLog.onInteractionComplete({
|
|
427
|
-
...interaction,
|
|
428
|
-
experimentalTTAI,
|
|
429
|
-
experimentalVC90
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
remove(interactionId);
|
|
433
|
-
activeSubmitted = false;
|
|
434
|
-
};
|
|
435
|
-
if (noMoreActiveHolds) {
|
|
436
|
-
if (!activeSubmitted) {
|
|
437
|
-
finishInteraction(interactionId, interaction, endTime);
|
|
438
|
-
activeSubmitted = true;
|
|
439
|
-
}
|
|
440
|
-
if (noMoreExpHolds) {
|
|
441
|
-
var _getConfig5, _getConfig5$experimen;
|
|
442
|
-
if ((_getConfig5 = getConfig()) !== null && _getConfig5 !== void 0 && (_getConfig5$experimen = _getConfig5.experimentalInteractionMetrics) !== null && _getConfig5$experimen !== void 0 && _getConfig5$experimen.enabled) {
|
|
443
|
-
experimentalInteractionLog.onInteractionComplete(interactionId, interaction, endTime);
|
|
444
|
-
}
|
|
445
|
-
postInteraction();
|
|
481
|
+
postInteractionLog.onInteractionComplete(interaction);
|
|
446
482
|
}
|
|
447
483
|
}
|
|
448
484
|
}
|
|
449
485
|
}
|
|
486
|
+
function callCancelCallbacks(interaction) {
|
|
487
|
+
interaction.cancelCallbacks.reverse().forEach(cancelCallback => {
|
|
488
|
+
cancelCallback();
|
|
489
|
+
});
|
|
490
|
+
}
|
|
450
491
|
export function abort(interactionId, abortReason) {
|
|
451
492
|
const interaction = interactions.get(interactionId);
|
|
452
493
|
if (interaction != null) {
|
|
453
|
-
var _getConfig6, _getConfig6$experimen;
|
|
454
494
|
callCancelCallbacks(interaction);
|
|
455
495
|
interaction.abortReason = abortReason;
|
|
456
496
|
finishInteraction(interactionId, interaction);
|
|
457
|
-
if ((_getConfig6 = getConfig()) !== null && _getConfig6 !== void 0 && (_getConfig6$experimen = _getConfig6.experimentalInteractionMetrics) !== null && _getConfig6$experimen !== void 0 && _getConfig6$experimen.enabled) {
|
|
458
|
-
experimentalInteractionLog.onInteractionComplete(interactionId, interaction);
|
|
459
|
-
}
|
|
460
|
-
remove(interactionId);
|
|
461
497
|
}
|
|
462
498
|
}
|
|
463
499
|
export function abortByNewInteraction(interactionId, interactionName) {
|
|
464
500
|
const interaction = interactions.get(interactionId);
|
|
465
501
|
if (interaction != null) {
|
|
466
|
-
var _getConfig7, _getConfig7$experimen;
|
|
467
502
|
callCancelCallbacks(interaction);
|
|
468
503
|
interaction.abortReason = 'new_interaction';
|
|
469
504
|
interaction.abortedByInteractionName = interactionName;
|
|
470
505
|
finishInteraction(interactionId, interaction);
|
|
471
|
-
if ((_getConfig7 = getConfig()) !== null && _getConfig7 !== void 0 && (_getConfig7$experimen = _getConfig7.experimentalInteractionMetrics) !== null && _getConfig7$experimen !== void 0 && _getConfig7$experimen.enabled) {
|
|
472
|
-
experimentalInteractionLog.onInteractionComplete(interactionId, interaction);
|
|
473
|
-
}
|
|
474
|
-
remove(interactionId);
|
|
475
506
|
}
|
|
476
507
|
}
|
|
477
508
|
export function abortAll(abortReason, abortedByInteractionName) {
|
|
478
509
|
interactions.forEach((interaction, interactionId) => {
|
|
479
|
-
var _getConfig8, _getConfig8$experimen;
|
|
480
510
|
const noMoreHolds = interaction.holdActive.size === 0;
|
|
481
511
|
if (!noMoreHolds) {
|
|
482
512
|
callCancelCallbacks(interaction);
|
|
513
|
+
// eslint-disable-next-line no-param-reassign
|
|
483
514
|
interaction.abortReason = abortReason;
|
|
484
515
|
if (abortedByInteractionName != null) {
|
|
516
|
+
// eslint-disable-next-line no-param-reassign
|
|
485
517
|
interaction.abortedByInteractionName = abortedByInteractionName;
|
|
486
518
|
}
|
|
487
519
|
}
|
|
488
520
|
finishInteraction(interactionId, interaction);
|
|
489
|
-
if ((_getConfig8 = getConfig()) !== null && _getConfig8 !== void 0 && (_getConfig8$experimen = _getConfig8.experimentalInteractionMetrics) !== null && _getConfig8$experimen !== void 0 && _getConfig8$experimen.enabled) {
|
|
490
|
-
experimentalInteractionLog.onInteractionComplete(interactionId, interaction);
|
|
491
|
-
}
|
|
492
|
-
remove(interactionId);
|
|
493
521
|
});
|
|
494
522
|
}
|
|
495
523
|
export function addOnCancelCallback(id, cancelCallback) {
|
|
@@ -497,8 +525,8 @@ export function addOnCancelCallback(id, cancelCallback) {
|
|
|
497
525
|
interaction === null || interaction === void 0 ? void 0 : interaction.cancelCallbacks.push(cancelCallback);
|
|
498
526
|
}
|
|
499
527
|
export function addNewInteraction(interactionId, ufoName, type, startTime, rate, labelStack, routeName, trace = null) {
|
|
500
|
-
var
|
|
501
|
-
if ((
|
|
528
|
+
var _getConfig5, _getConfig5$postInter;
|
|
529
|
+
if ((_getConfig5 = getConfig()) !== null && _getConfig5 !== void 0 && (_getConfig5$postInter = _getConfig5.postInteractionLog) !== null && _getConfig5$postInter !== void 0 && _getConfig5$postInter.enabled) {
|
|
502
530
|
postInteractionLog.reset();
|
|
503
531
|
}
|
|
504
532
|
let previousTime = startTime;
|
|
@@ -538,11 +566,9 @@ export function addNewInteraction(interactionId, ufoName, type, startTime, rate,
|
|
|
538
566
|
requestInfo: [],
|
|
539
567
|
reactProfilerTimings: [],
|
|
540
568
|
holdInfo: [],
|
|
541
|
-
holdExpInfo: [],
|
|
542
569
|
holdActive: new Map(),
|
|
543
|
-
holdExpActive: new Map(),
|
|
544
570
|
// measure when we execute this code
|
|
545
|
-
// from this
|
|
571
|
+
// from this we can measure the input delay -
|
|
546
572
|
// how long the browser took to hand execution back to JS)
|
|
547
573
|
measureStart: performance.now(),
|
|
548
574
|
rate,
|
|
@@ -654,6 +680,17 @@ export function addRequestInfo(interactionId, labelStack, requestInfo) {
|
|
|
654
680
|
});
|
|
655
681
|
}
|
|
656
682
|
}
|
|
683
|
+
function isSegmentLabel(obj) {
|
|
684
|
+
return obj && typeof obj.name === 'string' && typeof obj.segmentId === 'string';
|
|
685
|
+
}
|
|
686
|
+
function getSegmentCacheKey(labelStack) {
|
|
687
|
+
return labelStack.map(l => {
|
|
688
|
+
if (isSegmentLabel(l)) {
|
|
689
|
+
return `${l.name}_${l.segmentId}`;
|
|
690
|
+
}
|
|
691
|
+
return l.name;
|
|
692
|
+
}).join('|');
|
|
693
|
+
}
|
|
657
694
|
export function addSegment(labelStack) {
|
|
658
695
|
const key = getSegmentCacheKey(labelStack);
|
|
659
696
|
const existingSegment = segmentCache.get(key);
|