o11y 240.0.0 → 240.7.0

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.
Files changed (47) hide show
  1. package/dist/modules/o11y/client/client.js +131 -26
  2. package/dist/modules/o11y/client/client.js.map +1 -1
  3. package/dist/modules/o11y/client/collectors/core-collector/CoreCollector.d.ts +4 -0
  4. package/dist/modules/o11y/client/collectors/core-collector/interfaces/LogMessage.d.ts +1 -0
  5. package/dist/modules/o11y/client/interfaces/IdleDetector.d.ts +1 -1
  6. package/dist/modules/o11y/client/interfaces/IdleDetectorOptions.d.ts +3 -0
  7. package/dist/modules/o11y/client/interfaces/IdleDetectorReport.d.ts +10 -0
  8. package/dist/modules/o11y/client/interfaces/LogMeta.d.ts +1 -0
  9. package/dist/modules/o11y/client/interfaces/index.d.ts +2 -0
  10. package/dist/modules/o11y/client/library/IdleDetectorImpl.d.ts +11 -2
  11. package/dist/modules/o11y/client/library/NextgenImpl.d.ts +1 -0
  12. package/dist/modules/o11y/client/shared/Utility.d.ts +1 -0
  13. package/dist/modules/o11y/collectors/collectors/core-collector/CoreCollector.d.ts +4 -0
  14. package/dist/modules/o11y/collectors/collectors/core-collector/interfaces/LogMessage.d.ts +1 -0
  15. package/dist/modules/o11y/collectors/collectors.js +35 -66
  16. package/dist/modules/o11y/collectors/collectors.js.map +1 -1
  17. package/dist/modules/o11y/collectors/interfaces/IdleDetector.d.ts +1 -1
  18. package/dist/modules/o11y/collectors/interfaces/IdleDetectorOptions.d.ts +3 -0
  19. package/dist/modules/o11y/collectors/interfaces/IdleDetectorReport.d.ts +10 -0
  20. package/dist/modules/o11y/collectors/interfaces/LogMeta.d.ts +1 -0
  21. package/dist/modules/o11y/collectors/interfaces/index.d.ts +2 -0
  22. package/dist/modules/o11y/collectors/library/IdleDetectorImpl.d.ts +11 -2
  23. package/dist/modules/o11y/collectors/library/NextgenImpl.d.ts +1 -0
  24. package/dist/modules/o11y/collectors/shared/Utility.d.ts +1 -0
  25. package/dist/modules/o11y/shared/collectors/core-collector/CoreCollector.d.ts +4 -0
  26. package/dist/modules/o11y/shared/collectors/core-collector/interfaces/LogMessage.d.ts +1 -0
  27. package/dist/modules/o11y/shared/interfaces/IdleDetector.d.ts +1 -1
  28. package/dist/modules/o11y/shared/interfaces/IdleDetectorOptions.d.ts +3 -0
  29. package/dist/modules/o11y/shared/interfaces/IdleDetectorReport.d.ts +10 -0
  30. package/dist/modules/o11y/shared/interfaces/LogMeta.d.ts +1 -0
  31. package/dist/modules/o11y/shared/interfaces/index.d.ts +2 -0
  32. package/dist/modules/o11y/shared/library/IdleDetectorImpl.d.ts +11 -2
  33. package/dist/modules/o11y/shared/library/NextgenImpl.d.ts +1 -0
  34. package/dist/modules/o11y/shared/shared/Utility.d.ts +1 -0
  35. package/dist/modules/o11y/shared/shared.js +6 -0
  36. package/dist/modules/o11y/shared/shared.js.map +1 -1
  37. package/dist/modules/o11y/web_vitals/collectors/core-collector/CoreCollector.d.ts +4 -0
  38. package/dist/modules/o11y/web_vitals/collectors/core-collector/interfaces/LogMessage.d.ts +1 -0
  39. package/dist/modules/o11y/web_vitals/interfaces/IdleDetector.d.ts +1 -1
  40. package/dist/modules/o11y/web_vitals/interfaces/IdleDetectorOptions.d.ts +3 -0
  41. package/dist/modules/o11y/web_vitals/interfaces/IdleDetectorReport.d.ts +10 -0
  42. package/dist/modules/o11y/web_vitals/interfaces/LogMeta.d.ts +1 -0
  43. package/dist/modules/o11y/web_vitals/interfaces/index.d.ts +2 -0
  44. package/dist/modules/o11y/web_vitals/library/IdleDetectorImpl.d.ts +11 -2
  45. package/dist/modules/o11y/web_vitals/library/NextgenImpl.d.ts +1 -0
  46. package/dist/modules/o11y/web_vitals/shared/Utility.d.ts +1 -0
  47. package/package.json +3 -21
@@ -366,6 +366,9 @@ const activity={namespace:"sf.instrumentation",name:"Activity",pbjsSchema:{"nest
366
366
  const error={namespace:"sf.instrumentation",name:"Error",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"Error":{"reserved":[[5,5],[7,7]],"fields":{"activityId":{"options":{},"id":6,"type":"string"},"stack":{"options":{},"id":3,"type":"string"},"name":{"options":{},"id":1,"type":"string"},"message":{"options":{"(meta.max_length)":200},"id":2,"type":"string"},"userPayload":{"options":{},"id":4,"type":"Payload"}}},"Payload":{"fields":{"payload":{"options":{},"id":2,"type":"bytes"},
367
367
  "schemaName":{"options":{},"id":1,"type":"string"}}}}}}}}}};
368
368
 
369
+ const idle_detector_report={namespace:"sf.instrumentation",name:"IdleDetectorReport",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"IdleDetectorReport":{"options":{"(meta.msg.desc)":"This is used by the Idle Detector in o11y"},"fields":{"listenerCount":{"options":{},"id":3,"type":"uint32"},"busyTasks":{"options":{},"rule":"repeated","id":5,"type":"string"},"busyDurations":{"options":{},"rule":"repeated","id":6,"type":"double"},"pollableCount":{"options":{},"id":4,"type":"uint32"},
370
+ "pollCounts":{"options":{},"rule":"repeated","id":8,"type":"double"},"logThreshold":{"options":{},"id":2,"type":"double"},"maxDuration":{"options":{},"id":1,"type":"double"},"pollables":{"options":{},"rule":"repeated","id":7,"type":"string"}}}}}}}}}};
371
+
369
372
  const instrumented_event={namespace:"sf.instrumentation",name:"InstrumentedEvent",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"MouseEvent":{"fields":{"cancelable":{"options":{},"id":5,"type":"bool"},"ctrlKey":{"options":{},"id":9,"type":"bool"},"type":{"options":{},"id":25,"type":"string"},"button":{"options":{},"id":3,"type":"uint32"},"offsetX":{"options":{},"id":17,"type":"uint32"},"eventPhase":{"options":{},"id":12,"type":"uint32"},"shiftKey":{"options":{},"id":23,
370
373
  "type":"bool"},"offsetY":{"options":{},"id":18,"type":"uint32"},"composed":{"options":{},"id":8,"type":"bool"},"altKey":{"options":{},"id":1,"type":"bool"},"isTrusted":{"options":{},"id":13,"type":"bool"},"buttons":{"options":{},"id":4,"type":"uint32"},"movementY":{"options":{},"id":16,"type":"uint32"},"clientY":{"options":{},"id":7,"type":"uint32"},"clientX":{"options":{},"id":6,"type":"uint32"},"movementX":{"options":{},"id":15,"type":"uint32"},"defaultPrevented":{"options":{},"id":10,"type":"bool"},
371
374
  "metaKey":{"options":{},"id":14,"type":"bool"},"timeStamp":{"options":{},"id":24,"type":"double"},"bubbles":{"options":{},"id":2,"type":"bool"},"detail":{"options":{},"id":11,"type":"int64"},"pageY":{"options":{},"id":20,"type":"uint32"},"pageX":{"options":{},"id":19,"type":"uint32"},"screenX":{"options":{},"id":21,"type":"uint32"},"screenY":{"options":{},"id":22,"type":"uint32"}}},"InstrumentedEvent":{"oneofs":{"event":{"oneof":["mouseEvent"]}},"reserved":[[4,4],"xpath",[6,6],[8,8]],"fields":{"mouseEvent":{"options":{},
@@ -539,9 +542,9 @@ class LogValidator {
539
542
  if (fieldDataValue.length > maxItemCountAppLimit) {
540
543
  errorCode = 7;
541
544
  }
542
- for (const arrayKey in fieldDataValue) {
543
- this.matchFieldTypes(errorInfos, [...fieldNames, arrayKey], fieldDataValue[arrayKey], protobufType, descriptor, schemaId, key);
544
- }
545
+ fieldDataValue.forEach((value, index) => {
546
+ this.matchFieldTypes(errorInfos, [...fieldNames, index.toString()], value, protobufType, descriptor, schemaId, key);
547
+ });
545
548
  }
546
549
  else {
547
550
  errorCode = 1;
@@ -1406,6 +1409,7 @@ class NextgenImpl {
1406
1409
  constructor() {
1407
1410
  this._logCollectors = new Set();
1408
1411
  this._instruments = new Map();
1412
+ this._seqBySchema = new Map();
1409
1413
  this._sequence = 0;
1410
1414
  this._forceDisabledLogCollectors = new Set();
1411
1415
  this._logCollectorFailures = new Map();
@@ -1479,18 +1483,20 @@ class NextgenImpl {
1479
1483
  }
1480
1484
  addLog(loggerName, schema, data, timestamp, rootId, pagePayload, appPayload) {
1481
1485
  this._sequence += 1;
1482
- const sequence = this._sequence;
1483
- const loggerAppName = this.appName;
1484
- const connectionType = utility.getConnectionType();
1486
+ const schemaId = schemaUtil.getSchemaId(schema);
1487
+ let schemaSequence = this._seqBySchema.get(schemaId) || 0;
1488
+ schemaSequence += 1;
1489
+ this._seqBySchema.set(schemaId, schemaSequence);
1485
1490
  const logMeta = {
1486
1491
  timestamp,
1487
1492
  rootId,
1488
- sequence,
1493
+ sequence: this._sequence,
1494
+ schemaSequence,
1489
1495
  loggerName,
1490
1496
  pagePayload: pagePayload ? utility.clone(pagePayload) : undefined,
1491
1497
  appPayload: appPayload ? utility.clone(appPayload) : undefined,
1492
- loggerAppName,
1493
- connectionType
1498
+ loggerAppName: this.appName,
1499
+ connectionType: utility.getConnectionType()
1494
1500
  };
1495
1501
  if (this._isBufferingEnabled) {
1496
1502
  this._buffer.push({ schema, data: utility.clone(data), logMeta });
@@ -1617,7 +1623,7 @@ class Index {
1617
1623
  return this._nextgen;
1618
1624
  }
1619
1625
  registerInstrumentedApp(name, options) {
1620
- if (options && options.isProduction) {
1626
+ if (!options || options.isProduction !== false) {
1621
1627
  utility.markProduction();
1622
1628
  }
1623
1629
  const retVal = this._lazyNextGen.registerApp(name, options);
@@ -1669,19 +1675,35 @@ class TaskerImpl {
1669
1675
  }
1670
1676
  }
1671
1677
 
1678
+ const defaultLogThreshold = 300;
1672
1679
  class IdleDetectorImpl {
1673
- constructor() {
1680
+ constructor(options) {
1674
1681
  this._instr = getInstrumentation('IdleDetector');
1675
- this._taskers = new Set();
1682
+ this._taskers = new Map();
1676
1683
  this._listeners = new Set();
1677
1684
  this._busyCheckers = new Map();
1685
+ this._logThreshold = defaultLogThreshold;
1686
+ this._endedTasks = new Array();
1687
+ this._pollableReport = new Array();
1678
1688
  this._timerCheckQueued = 0;
1689
+ if (utility.requireArgumentIfDefined(options === null || options === void 0 ? void 0 : options.logThreshold, 'options.logThreshold', 'number')) {
1690
+ this._logThreshold = options.logThreshold;
1691
+ }
1679
1692
  }
1680
1693
  requestIdleDetectedCallback(callback) {
1681
1694
  utility.requireArgument(callback, 'callback', 'function');
1695
+ if (this._listeners.size === 0) {
1696
+ this._firstCallbackTime = utility.time().perfNow;
1697
+ }
1682
1698
  this._listeners.add(callback);
1683
1699
  this.checkIfLoaded();
1684
1700
  }
1701
+ reportTaskEnded(tasker) {
1702
+ if (this._listeners.size) {
1703
+ const snapshot = Object.assign({}, this._taskers.get(tasker));
1704
+ this._endedTasks.push(snapshot);
1705
+ }
1706
+ }
1685
1707
  declareNotifierTaskSingle(name) {
1686
1708
  utility.requireArgument(name, 'name', 'string');
1687
1709
  const tasker = this.addTasker(name, 1);
@@ -1705,7 +1727,22 @@ class IdleDetectorImpl {
1705
1727
  throw new Error('existingBusyCount accepts only non-negative integers');
1706
1728
  }
1707
1729
  }
1708
- return this.addTasker(name, existingBusyCount);
1730
+ const tasker = this.addTasker(name, existingBusyCount);
1731
+ const retVal = {
1732
+ get isBusy() {
1733
+ return tasker.isBusy;
1734
+ },
1735
+ add: () => {
1736
+ if (!tasker.isBusy) {
1737
+ const meta = this._taskers.get(tasker);
1738
+ meta.start = utility.time().perfNow;
1739
+ meta.end = undefined;
1740
+ }
1741
+ tasker.add();
1742
+ },
1743
+ done: tasker.done.bind(tasker)
1744
+ };
1745
+ return retVal;
1709
1746
  }
1710
1747
  declarePollableTaskMulti(name, isBusyChecker) {
1711
1748
  utility.requireArgument(name, 'name', 'string');
@@ -1714,26 +1751,37 @@ class IdleDetectorImpl {
1714
1751
  }
1715
1752
  addTasker(name, existingBusyCount) {
1716
1753
  const tasker = new TaskerImpl(name, existingBusyCount, () => {
1754
+ this._taskers.get(tasker).end = utility.time().perfNow;
1755
+ this.reportTaskEnded(tasker);
1717
1756
  this.checkIfLoaded();
1718
1757
  }, () => {
1719
- throw new Error(`Tasker '${tasker.name}' is done too many times.`);
1758
+ this._instr.error(`Overdone: ${tasker.name}`);
1759
+ utility.noProdThrow(`Tasker '${tasker.name}' is done too many times.`);
1760
+ });
1761
+ this._taskers.set(tasker, {
1762
+ name,
1763
+ start: existingBusyCount > 0 ? utility.time().perfNow : undefined,
1764
+ end: undefined
1720
1765
  });
1721
- this._taskers.add(tasker);
1722
1766
  return tasker;
1723
1767
  }
1724
1768
  areAllNotifiersIdle() {
1725
- return !Array.from(this._taskers.values()).some((t) => t.isBusy);
1769
+ return !Array.from(this._taskers.keys()).some((t) => t.isBusy);
1726
1770
  }
1727
- areAllPollablesIdle() {
1728
- return !Array.from(this._busyCheckers.keys()).some((sc, index) => {
1771
+ getFirstBusyPollable() {
1772
+ const entry = Array.from(this._busyCheckers).find((entry) => {
1773
+ const isBusyChecker = entry[0];
1774
+ const name = entry[1];
1729
1775
  try {
1730
- return sc();
1776
+ return isBusyChecker();
1731
1777
  }
1732
1778
  catch (e) {
1733
- this._instr.error(e, `BusyChecker #${index}`);
1779
+ this._instr.error(e, `BusyChecker ${name}`);
1780
+ utility.noProdThrow(e);
1734
1781
  return false;
1735
1782
  }
1736
1783
  });
1784
+ return entry ? entry[1] : undefined;
1737
1785
  }
1738
1786
  checkIfLoaded() {
1739
1787
  if (!this._listeners.size) {
@@ -1753,29 +1801,84 @@ class IdleDetectorImpl {
1753
1801
  doubleCheck() {
1754
1802
  this._timerCheckQueued = 0;
1755
1803
  if (this.areAllNotifiersIdle()) {
1756
- if (!this.areAllPollablesIdle()) {
1804
+ const pollableName = this.getFirstBusyPollable();
1805
+ if (pollableName !== undefined) {
1806
+ this.addToPollableReport(pollableName);
1757
1807
  this._timerCheckQueued = window.setTimeout(() => {
1758
1808
  this.doubleCheck();
1759
1809
  }, 15);
1760
1810
  }
1761
1811
  else {
1812
+ const maxDuration = utility.time().perfNow - this._firstCallbackTime;
1762
1813
  const listeners = Array.from(this._listeners.values());
1763
1814
  this._listeners.clear();
1764
- this.notify(listeners);
1815
+ this._firstCallbackTime = undefined;
1816
+ const endedTasks = this._endedTasks.splice(0);
1817
+ const pollableReport = this._pollableReport.splice(0);
1818
+ this.notify(listeners, maxDuration, endedTasks, pollableReport);
1765
1819
  }
1766
1820
  }
1767
1821
  }
1768
- notify(listeners) {
1769
- const idleTimestamp = utility.time().tsNow;
1822
+ addToPollableReport(name) {
1823
+ const lastEntry = this._pollableReport.length
1824
+ ? this._pollableReport[this._pollableReport.length - 1]
1825
+ : undefined;
1826
+ if ((lastEntry === null || lastEntry === void 0 ? void 0 : lastEntry.name) === name) {
1827
+ lastEntry.count += 1;
1828
+ }
1829
+ else {
1830
+ this._pollableReport.push({
1831
+ name,
1832
+ count: 1
1833
+ });
1834
+ }
1835
+ }
1836
+ notify(listeners, maxDuration, taskReport, pollableReport) {
1837
+ if (maxDuration >= this._logThreshold) {
1838
+ const logData = this._getReport(maxDuration, listeners.length, taskReport, pollableReport);
1839
+ this._instr.log(idle_detector_report, logData);
1840
+ }
1841
+ const tsNow = utility.time().tsNow;
1770
1842
  for (const [index, listener] of listeners.entries()) {
1771
1843
  try {
1772
- listener(idleTimestamp);
1844
+ listener(tsNow);
1773
1845
  }
1774
1846
  catch (e) {
1775
1847
  this._instr.error(e, `Listener #${index}`);
1848
+ utility.noProdThrow(e);
1776
1849
  }
1777
1850
  }
1778
1851
  }
1852
+ getReport() {
1853
+ const perfNow = utility.time().perfNow;
1854
+ const maxDuration = this._firstCallbackTime > 0 ? perfNow - this._firstCallbackTime : undefined;
1855
+ const onGoingTasks = Array.from(this._taskers.entries())
1856
+ .filter((e) => e[0].isBusy)
1857
+ .map((e) => ({
1858
+ name: e[1].name,
1859
+ start: e[1].start,
1860
+ end: perfNow
1861
+ }));
1862
+ return this._getReport(maxDuration, this._listeners.size, this._endedTasks.concat(onGoingTasks), this._pollableReport);
1863
+ }
1864
+ _getReport(maxDuration, listenerCount, taskReport, pollableReport) {
1865
+ const sortedTaskers = taskReport
1866
+ .map((t) => ({
1867
+ name: t.name,
1868
+ duration: t.end - t.start
1869
+ }))
1870
+ .sort((a, b) => b.duration - a.duration);
1871
+ return {
1872
+ logThreshold: this._logThreshold,
1873
+ maxDuration,
1874
+ listenerCount,
1875
+ pollableCount: this._busyCheckers.size,
1876
+ busyTasks: sortedTaskers.map((t) => t.name),
1877
+ busyDurations: sortedTaskers.map((t) => t.duration),
1878
+ pollables: pollableReport.map((p) => p.name),
1879
+ pollCounts: pollableReport.map((p) => p.count)
1880
+ };
1881
+ }
1779
1882
  }
1780
1883
 
1781
1884
  const bgColorMap = {
@@ -1816,7 +1919,9 @@ class ConsoleCollector {
1816
1919
  }
1817
1920
  }
1818
1921
 
1819
- const idleDetector = new IdleDetectorImpl();
1922
+ const idleDetector = new IdleDetectorImpl({
1923
+ logThreshold: 300
1924
+ });
1820
1925
 
1821
1926
  export { ConsoleCollector, getInstrumentation, idleDetector, registerInstrumentedApp, time };
1822
1927
  //# sourceMappingURL=client.js.map