@atlaskit/react-ufo 4.1.10 → 4.1.12

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.
@@ -3,6 +3,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
3
3
  import coinflip from '../coinflip';
4
4
  import { getAwaitBM3TTIList, getCapabilityRate, getConfig, getExperimentalInteractionRate, getInteractionTimeout, getPostInteractionRate } from '../config';
5
5
  import { experimentalVC, getExperimentalVCMetrics, onExperimentalInteractionComplete } from '../create-experimental-interaction-metrics-payload';
6
+ import { sanitizeUfoName } from '../create-payload/common/utils';
6
7
  import { clearActiveTrace } from '../experience-trace-id-context';
7
8
  import { allFeatureFlagsAccessed, currentFeatureFlagsAccessed } from '../feature-flags-accessed';
8
9
  import { getInteractionId } from '../interaction-id-context';
@@ -155,10 +156,23 @@ export function addCustomTiming(interactionId, labelStack, data) {
155
156
  } = timingData;
156
157
  try {
157
158
  // for Firefox 102 and older
158
- performance.measure(`🛸 ${labelStackToString(labelStack, key)} [custom_timing]`, {
159
- start: startTime,
160
- end: endTime
161
- });
159
+ if (fg('ufo_chrome_devtools_uplift')) {
160
+ performance.measure(`🛸 ${labelStackToString(labelStack, key)} [custom_timing]`, {
161
+ start: startTime,
162
+ end: endTime,
163
+ detail: {
164
+ devtools: {
165
+ track: '🛸 reactUFO detailed timings',
166
+ color: 'tertiary-light'
167
+ }
168
+ }
169
+ });
170
+ } else {
171
+ performance.measure(`🛸 ${labelStackToString(labelStack, key)} [custom_timing]`, {
172
+ start: startTime,
173
+ end: endTime
174
+ });
175
+ }
162
176
  } catch (e) {
163
177
  // do nothing
164
178
  }
@@ -211,10 +225,23 @@ export function addSpan(interactionId, type, name, labelStack, start, end = perf
211
225
  if (isPerformanceTracingEnabled()) {
212
226
  try {
213
227
  // for Firefox 102 and older
214
- performance.measure(`🛸 ${labelStackToString(labelStack, name)} [${type}]`, {
215
- start,
216
- end
217
- });
228
+ if (fg('ufo_chrome_devtools_uplift')) {
229
+ performance.measure(`🛸 ${labelStackToString(labelStack, name)} [${type}]`, {
230
+ start,
231
+ end,
232
+ detail: {
233
+ devtools: {
234
+ track: '🛸 reactUFO detailed timings',
235
+ color: 'secondary'
236
+ }
237
+ }
238
+ });
239
+ } else {
240
+ performance.measure(`🛸 ${labelStackToString(labelStack, name)} [${type}]`, {
241
+ start,
242
+ end
243
+ });
244
+ }
218
245
  } catch (e) {
219
246
  // do nothing
220
247
  }
@@ -235,10 +262,23 @@ export function addSpanToAll(type, name, labelStack, start, end = performance.no
235
262
  if (isPerformanceTracingEnabled()) {
236
263
  try {
237
264
  // for Firefox 102 and older
238
- performance.measure(`🛸 ${labelStackToString(labelStack, name)} [${type}]`, {
239
- start,
240
- end
241
- });
265
+ if (fg('ufo_chrome_devtools_uplift')) {
266
+ performance.measure(`🛸 ${labelStackToString(labelStack, name)} [${type}]`, {
267
+ start,
268
+ end,
269
+ detail: {
270
+ devtools: {
271
+ track: '🛸 reactUFO detailed timings',
272
+ color: 'secondary'
273
+ }
274
+ }
275
+ });
276
+ } else {
277
+ performance.measure(`🛸 ${labelStackToString(labelStack, name)} [${type}]`, {
278
+ start,
279
+ end
280
+ });
281
+ }
242
282
  } catch (e) {
243
283
  // do nothing
244
284
  }
@@ -301,10 +341,23 @@ export function addHold(interactionId, labelStack, name, experimental) {
301
341
  if (isPerformanceTracingEnabled()) {
302
342
  try {
303
343
  // for Firefox 102 and older
304
- performance.measure(`🛸 ${labelStackToString(labelStack, name)} [hold]`, {
305
- start,
306
- end
307
- });
344
+ if (fg('ufo_chrome_devtools_uplift')) {
345
+ performance.measure(`🛸 ${labelStackToString(labelStack, name)} [hold]`, {
346
+ start,
347
+ end,
348
+ detail: {
349
+ devtools: {
350
+ track: '🛸 reactUFO detailed timings',
351
+ color: 'secondary-light'
352
+ }
353
+ }
354
+ });
355
+ } else {
356
+ performance.measure(`🛸 ${labelStackToString(labelStack, name)} [hold]`, {
357
+ start,
358
+ end
359
+ });
360
+ }
308
361
  } catch (e) {
309
362
  // do nothing
310
363
  }
@@ -434,10 +487,23 @@ export function addProfilerTimings(interactionId, labelStack, type, actualDurati
434
487
  if (isPerformanceTracingEnabled()) {
435
488
  try {
436
489
  // for Firefox 102 and older
437
- performance.measure(`🛸 ${labelStackToString(labelStack)} [react-profiler] ${type}`, {
438
- start: startTime,
439
- duration: actualDuration
440
- });
490
+ if (fg('ufo_chrome_devtools_uplift')) {
491
+ performance.measure(`🛸 ${labelStackToString(labelStack)} [react-profiler] ${type}`, {
492
+ start: startTime,
493
+ duration: actualDuration,
494
+ detail: {
495
+ devtools: {
496
+ track: '🛸 reactUFO detailed timings',
497
+ color: 'secondary-dark'
498
+ }
499
+ }
500
+ });
501
+ } else {
502
+ performance.measure(`🛸 ${labelStackToString(labelStack)} [react-profiler] ${type}`, {
503
+ start: startTime,
504
+ duration: actualDuration
505
+ });
506
+ }
441
507
  } catch (e) {
442
508
  // do nothing
443
509
  }
@@ -473,10 +539,24 @@ function finishInteraction(id, data, endTime = performance.now()) {
473
539
  data.end = endTime;
474
540
  try {
475
541
  // for Firefox 102 and older
476
- performance.measure(`🛸 [${data.type}] ${data.ufoName} [ttai]`, {
477
- start: data.start,
478
- end: data.end
479
- });
542
+ if (fg('ufo_chrome_devtools_uplift')) {
543
+ performance.measure(`🛸 [${data.type}] ${data.ufoName} [ttai]`, {
544
+ start: data.start,
545
+ end: data.end,
546
+ detail: {
547
+ devtools: {
548
+ track: 'main metrics',
549
+ trackGroup: '🛸 reactUFO metrics',
550
+ color: 'tertiary'
551
+ }
552
+ }
553
+ });
554
+ } else {
555
+ performance.measure(`🛸 [${data.type}] ${data.ufoName} [ttai]`, {
556
+ start: data.start,
557
+ end: data.end
558
+ });
559
+ }
480
560
  } catch (e) {
481
561
  // do nothing
482
562
  }
@@ -492,6 +572,18 @@ function finishInteraction(id, data, endTime = performance.now()) {
492
572
  data.vc = observer.getVCRawData();
493
573
  }
494
574
  }
575
+
576
+ // By this time, stop the post interaction log observer if coinflip rate is 0
577
+ if (fg('platform_ufo_post_interaction_check_name')) {
578
+ const sanitisedUfoName = sanitizeUfoName(data.ufoName);
579
+ if (!coinflip(getPostInteractionRate(sanitisedUfoName, data.type))) {
580
+ postInteractionLog.stopVCObserver();
581
+ }
582
+ } else {
583
+ if (!coinflip(getPostInteractionRate(data.routeName || data.ufoName, data.type))) {
584
+ postInteractionLog.stopVCObserver();
585
+ }
586
+ }
495
587
  if (!((_getConfig5 = getConfig()) !== null && _getConfig5 !== void 0 && (_getConfig5$experimen = _getConfig5.experimentalInteractionMetrics) !== null && _getConfig5$experimen !== void 0 && _getConfig5$experimen.enabled)) {
496
588
  remove(id);
497
589
  }
@@ -521,10 +613,23 @@ function finishInteraction(id, data, endTime = performance.now()) {
521
613
  start,
522
614
  end
523
615
  }] of profilerTimingMap.entries()) {
524
- performance.measure(`🛸 ${labelStackToString(labelStack)} [segment_ttai]`, {
525
- start,
526
- end
527
- });
616
+ if (fg('ufo_chrome_devtools_uplift')) {
617
+ performance.measure(`🛸 ${labelStackToString(labelStack)} [segment_ttai]`, {
618
+ start,
619
+ end,
620
+ detail: {
621
+ devtools: {
622
+ track: '🛸 reactUFO detailed timings',
623
+ color: 'secondary-dark'
624
+ }
625
+ }
626
+ });
627
+ } else {
628
+ performance.measure(`🛸 ${labelStackToString(labelStack)} [segment_ttai]`, {
629
+ start,
630
+ end
631
+ });
632
+ }
528
633
  }
529
634
  } catch (e) {
530
635
  // do nothing
@@ -658,8 +763,12 @@ export function addOnCancelCallback(id, cancelCallback) {
658
763
  interaction === null || interaction === void 0 ? void 0 : interaction.cancelCallbacks.push(cancelCallback);
659
764
  }
660
765
  export function addNewInteraction(interactionId, ufoName, type, startTime, rate, labelStack, routeName, trace = null) {
661
- if (coinflip(getPostInteractionRate(routeName || ufoName, type))) {
766
+ if (fg('platform_ufo_post_interaction_check_name')) {
662
767
  postInteractionLog.reset();
768
+ } else {
769
+ if (coinflip(getPostInteractionRate(routeName || ufoName, type))) {
770
+ postInteractionLog.reset();
771
+ }
663
772
  }
664
773
  let vcObserver;
665
774
  let previousTime = startTime;
@@ -778,10 +887,21 @@ export function addNewInteraction(interactionId, ufoName, type, startTime, rate,
778
887
  experienceKey: ufoName
779
888
  });
780
889
  }
781
- if (coinflip(getPostInteractionRate(routeName || ufoName, type))) {
782
- postInteractionLog.startVCObserver({
783
- startTime
784
- });
890
+ if (fg('platform_ufo_post_interaction_check_name')) {
891
+ var _getConfig0, _getConfig0$postInter;
892
+ // Start post interaction observer for all if config is enabled
893
+ // in case ufoName is updated at later time
894
+ if ((_getConfig0 = getConfig()) !== null && _getConfig0 !== void 0 && (_getConfig0$postInter = _getConfig0.postInteractionLog) !== null && _getConfig0$postInter !== void 0 && _getConfig0$postInter.enabled) {
895
+ postInteractionLog.startVCObserver({
896
+ startTime
897
+ });
898
+ }
899
+ } else {
900
+ if (coinflip(getPostInteractionRate(routeName || ufoName, type))) {
901
+ postInteractionLog.startVCObserver({
902
+ startTime
903
+ });
904
+ }
785
905
  }
786
906
  if (coinflip(getExperimentalInteractionRate(ufoName, type))) {
787
907
  experimentalVC.start({
@@ -815,12 +935,27 @@ export function addApdexToAll(apdex) {
815
935
  interactions.forEach((interaction, key) => {
816
936
  interaction.apdex.push(apdex);
817
937
  try {
818
- var _apdex$startTime;
819
938
  // for Firefox 102 and older
820
- performance.measure(`🛸 ${apdex.key} [bm3_tti]`, {
821
- start: (_apdex$startTime = apdex.startTime) !== null && _apdex$startTime !== void 0 ? _apdex$startTime : interaction.start,
822
- end: apdex.stopTime
823
- });
939
+ if (fg('ufo_chrome_devtools_uplift')) {
940
+ var _apdex$startTime;
941
+ performance.measure(`🛸 ${apdex.key} [bm3_tti]`, {
942
+ start: (_apdex$startTime = apdex.startTime) !== null && _apdex$startTime !== void 0 ? _apdex$startTime : interaction.start,
943
+ end: apdex.stopTime,
944
+ detail: {
945
+ devtools: {
946
+ track: 'main metrics',
947
+ trackGroup: '🛸 reactUFO metrics',
948
+ color: 'primary-dark'
949
+ }
950
+ }
951
+ });
952
+ } else {
953
+ var _apdex$startTime2;
954
+ performance.measure(`🛸 ${apdex.key} [bm3_tti]`, {
955
+ start: (_apdex$startTime2 = apdex.startTime) !== null && _apdex$startTime2 !== void 0 ? _apdex$startTime2 : interaction.start,
956
+ end: apdex.stopTime
957
+ });
958
+ }
824
959
  } catch (e) {
825
960
  // do nothing
826
961
  }
@@ -834,12 +969,27 @@ export function addApdex(interactionId, apdexInfo) {
834
969
  if (interaction != null) {
835
970
  interaction.apdex.push(apdexInfo);
836
971
  try {
837
- var _apdexInfo$startTime;
838
972
  // for Firefox 102 and older
839
- performance.measure(`🛸 ${apdexInfo.key} [bm3_tti]`, {
840
- start: (_apdexInfo$startTime = apdexInfo.startTime) !== null && _apdexInfo$startTime !== void 0 ? _apdexInfo$startTime : interaction.start,
841
- end: apdexInfo.stopTime
842
- });
973
+ if (fg('ufo_chrome_devtools_uplift')) {
974
+ var _apdexInfo$startTime;
975
+ performance.measure(`🛸 ${apdexInfo.key} [bm3_tti]`, {
976
+ start: (_apdexInfo$startTime = apdexInfo.startTime) !== null && _apdexInfo$startTime !== void 0 ? _apdexInfo$startTime : interaction.start,
977
+ end: apdexInfo.stopTime,
978
+ detail: {
979
+ devtools: {
980
+ track: 'main metrics',
981
+ trackGroup: '🛸 reactUFO metrics',
982
+ color: 'primary-dark'
983
+ }
984
+ }
985
+ });
986
+ } else {
987
+ var _apdexInfo$startTime2;
988
+ performance.measure(`🛸 ${apdexInfo.key} [bm3_tti]`, {
989
+ start: (_apdexInfo$startTime2 = apdexInfo.startTime) !== null && _apdexInfo$startTime2 !== void 0 ? _apdexInfo$startTime2 : interaction.start,
990
+ end: apdexInfo.stopTime
991
+ });
992
+ }
843
993
  } catch (e) {
844
994
  // do nothing
845
995
  }
@@ -903,12 +1053,26 @@ export function addRedirect(interactionId, fromUfoName, nextUfoName, nextRouteNa
903
1053
  if (isPerformanceTracingEnabled()) {
904
1054
  const prevRedirect = interaction.redirects.at(-2);
905
1055
  try {
906
- var _prevRedirect$time;
907
1056
  // for Firefox 102 and older
908
- performance.measure(`🛸 ${nextUfoName} [redirect]`, {
909
- start: (_prevRedirect$time = prevRedirect === null || prevRedirect === void 0 ? void 0 : prevRedirect.time) !== null && _prevRedirect$time !== void 0 ? _prevRedirect$time : interaction.start,
910
- end: time
911
- });
1057
+ if (fg('ufo_chrome_devtools_uplift')) {
1058
+ var _prevRedirect$time;
1059
+ performance.measure(`🛸 ${nextUfoName} [redirect]`, {
1060
+ start: (_prevRedirect$time = prevRedirect === null || prevRedirect === void 0 ? void 0 : prevRedirect.time) !== null && _prevRedirect$time !== void 0 ? _prevRedirect$time : interaction.start,
1061
+ end: time,
1062
+ detail: {
1063
+ devtools: {
1064
+ track: '🛸 reactUFO detailed timings',
1065
+ color: 'tertiary'
1066
+ }
1067
+ }
1068
+ });
1069
+ } else {
1070
+ var _prevRedirect$time2;
1071
+ performance.measure(`🛸 ${nextUfoName} [redirect]`, {
1072
+ start: (_prevRedirect$time2 = prevRedirect === null || prevRedirect === void 0 ? void 0 : prevRedirect.time) !== null && _prevRedirect$time2 !== void 0 ? _prevRedirect$time2 : interaction.start,
1073
+ end: time
1074
+ });
1075
+ }
912
1076
  } catch (e) {
913
1077
  // do nothing
914
1078
  }
@@ -88,13 +88,14 @@ export default class PostInteractionLog {
88
88
  * Send the log if there is data
89
89
  */
90
90
  async sendPostInteractionLog() {
91
- var _this$vcObserver4, _this$vcObserver5;
91
+ var _this$vcObserver4, _config$vc, _config$vc2, _this$vcObserver5;
92
92
  if (!this.hasData() || !this.lastInteractionFinish || !this.sinkHandlerFn) {
93
93
  var _this$vcObserver3;
94
94
  this.reset();
95
95
  (_this$vcObserver3 = this.vcObserver) === null || _this$vcObserver3 === void 0 ? void 0 : _this$vcObserver3.stop();
96
96
  return;
97
97
  }
98
+ const config = getConfig();
98
99
  const postInteractionFinishVCResult = await ((_this$vcObserver4 = this.vcObserver) === null || _this$vcObserver4 === void 0 ? void 0 : _this$vcObserver4.getVCResult({
99
100
  start: this.lastInteractionFinish.start,
100
101
  stop: performance.now(),
@@ -102,8 +103,11 @@ export default class PostInteractionLog {
102
103
  // no need for TTI value here
103
104
  isEventAborted: !!this.lastInteractionFinish.abortReason,
104
105
  prefix: 'ufo',
105
- ...this.vcObserverSSRConfig,
106
- experienceKey: this.lastInteractionFinish.ufoName
106
+ experienceKey: this.lastInteractionFinish.ufoName,
107
+ interactionId: this.lastInteractionFinish.id,
108
+ includeSSRInV3: config === null || config === void 0 ? void 0 : (_config$vc = config.vc) === null || _config$vc === void 0 ? void 0 : _config$vc.includeSSRInV3,
109
+ includeSSRRatio: config === null || config === void 0 ? void 0 : (_config$vc2 = config.vc) === null || _config$vc2 === void 0 ? void 0 : _config$vc2.includeSSRRatio,
110
+ ...this.vcObserverSSRConfig
107
111
  }));
108
112
  (_this$vcObserver5 = this.vcObserver) === null || _this$vcObserver5 === void 0 ? void 0 : _this$vcObserver5.stop();
109
113
  this.sinkHandlerFn({
@@ -1,4 +1,5 @@
1
1
  var _process, _process$env;
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { isVCRevisionEnabled } from '../config';
3
4
  import { VCObserverNOOP } from './no-op-vc-observer';
4
5
  import { VCObserver } from './vc-observer';
@@ -111,6 +112,7 @@ export class VCObserverWrapper {
111
112
  interactionId: param.interactionId,
112
113
  ssr: param.includeSSRInV3 ? param.ssr : undefined
113
114
  })) : [];
115
+ fg('ufo_chrome_devtools_uplift') && this.addPerformanceMeasures(param.start, [...((v1v2Result === null || v1v2Result === void 0 ? void 0 : v1v2Result['ufo:vc:rev']) || []), ...(v3Result !== null && v3Result !== void 0 ? v3Result : [])]);
114
116
  if (!v3Result) {
115
117
  return v1v2Result !== null && v1v2Result !== void 0 ? v1v2Result : {};
116
118
  }
@@ -137,6 +139,46 @@ export class VCObserverWrapper {
137
139
  collectSSRPlaceholders() {
138
140
  this.ssrPlaceholderHandler.collectExistingPlaceholders();
139
141
  }
142
+ addPerformanceMeasures(start, measures) {
143
+ try {
144
+ measures.forEach(entry => {
145
+ var _entry$vcDetails, _entry$vcDetails$;
146
+ if (!entry || !entry.vcDetails) {
147
+ return;
148
+ }
149
+ const VCParts = Object.keys(entry.vcDetails);
150
+ performance.measure(`VC90 (${entry.revision})`, {
151
+ start,
152
+ duration: (_entry$vcDetails = entry.vcDetails) === null || _entry$vcDetails === void 0 ? void 0 : (_entry$vcDetails$ = _entry$vcDetails['90']) === null || _entry$vcDetails$ === void 0 ? void 0 : _entry$vcDetails$.t,
153
+ detail: {
154
+ devtools: {
155
+ track: `main metrics`,
156
+ trackGroup: '🛸 reactUFO metrics',
157
+ color: 'tertiary'
158
+ }
159
+ }
160
+ });
161
+ VCParts.forEach(key => {
162
+ var _entry$vcDetails2;
163
+ const duration = (_entry$vcDetails2 = entry.vcDetails) === null || _entry$vcDetails2 === void 0 ? void 0 : _entry$vcDetails2[key].t;
164
+ if (typeof duration !== 'number') {
165
+ return;
166
+ }
167
+ performance.measure(`VC${key}`, {
168
+ start,
169
+ duration,
170
+ detail: {
171
+ devtools: {
172
+ track: `VC ${entry.revision}`,
173
+ trackGroup: '🛸 reactUFO metrics',
174
+ color: key === '90' ? 'tertiary' : 'primary-light'
175
+ }
176
+ }
177
+ });
178
+ });
179
+ });
180
+ } catch (error) {}
181
+ }
140
182
  }
141
183
 
142
184
  // Some products set this variable to indicate it is running in SSR
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { isVCRevisionEnabled } from '../../config';
3
4
  import { getActiveInteraction } from '../../interaction-metrics';
4
5
  import { attachAbortListeners } from './attachAbortListeners';
@@ -188,29 +189,35 @@ export class VCObserver {
188
189
  if (isTTVCv1Disabled) {
189
190
  const duration = vcNext.VC[key];
190
191
  if (duration !== null && duration !== undefined) {
191
- performance.measure(`VC${key}`, {
192
- start,
193
- duration
194
- });
195
- performance.measure(`VC_Next${key}`, {
196
- start,
197
- duration
198
- });
192
+ if (!fg('ufo_chrome_devtools_uplift')) {
193
+ performance.measure(`VC${key}`, {
194
+ start,
195
+ duration
196
+ });
197
+ performance.measure(`VC_Next${key}`, {
198
+ start,
199
+ duration
200
+ });
201
+ }
199
202
  }
200
203
  } else {
201
204
  const ttvcV1duration = VC[key];
202
205
  if (ttvcV1duration !== null && ttvcV1duration !== undefined) {
203
- performance.measure(`VC${key}`, {
204
- start,
205
- duration: ttvcV1duration
206
- });
206
+ if (!fg('ufo_chrome_devtools_uplift')) {
207
+ performance.measure(`VC${key}`, {
208
+ start,
209
+ duration: ttvcV1duration
210
+ });
211
+ }
207
212
  }
208
213
  const ttvcV2duration = vcNext.VC[key];
209
214
  if (ttvcV2duration !== null && ttvcV2duration !== undefined) {
210
- performance.measure(`VC_Next${key}`, {
211
- start,
212
- duration: ttvcV2duration
213
- });
215
+ if (!fg('ufo_chrome_devtools_uplift')) {
216
+ performance.measure(`VC_Next${key}`, {
217
+ start,
218
+ duration: ttvcV2duration
219
+ });
220
+ }
214
221
  }
215
222
  }
216
223
  });