@microsoft/applicationinsights-core-js 2.7.4-nightly.2202-07 → 2.8.0-beta.2202-06

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 (108) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +860 -457
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +1193 -267
  7. package/dist/applicationinsights-core-js.api.md +54 -14
  8. package/dist/applicationinsights-core-js.d.ts +133 -45
  9. package/dist/applicationinsights-core-js.js +860 -457
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +133 -45
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +237 -82
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +45 -19
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +155 -87
  21. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +2 -27
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  26. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  27. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  28. package/dist-esm/JavaScriptSDK/EnvUtils.js +6 -6
  29. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/HelperFuncs.js +51 -11
  31. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
  33. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/NotificationManager.js +34 -36
  35. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  37. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +289 -119
  38. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  39. package/dist-esm/JavaScriptSDK/RandomHelper.js +29 -4
  40. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +2 -2
  42. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  43. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +82 -0
  44. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
  45. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  46. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
  49. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  50. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
  62. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
  63. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  66. package/dist-esm/applicationinsights-core-js.js +4 -4
  67. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  68. package/package.json +2 -2
  69. package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
  70. package/src/JavaScriptSDK/BaseCore.ts +330 -100
  71. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +69 -32
  72. package/src/JavaScriptSDK/ChannelController.ts +175 -103
  73. package/src/JavaScriptSDK/CoreUtils.ts +1 -28
  74. package/src/JavaScriptSDK/EnvUtils.ts +5 -5
  75. package/src/JavaScriptSDK/HelperFuncs.ts +57 -14
  76. package/src/JavaScriptSDK/InstrumentHooks.ts +3 -1
  77. package/src/JavaScriptSDK/NotificationManager.ts +32 -31
  78. package/src/JavaScriptSDK/PerfManager.ts +1 -1
  79. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +350 -133
  80. package/src/JavaScriptSDK/RandomHelper.ts +34 -3
  81. package/src/JavaScriptSDK/TelemetryHelpers.ts +4 -6
  82. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +119 -0
  83. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +17 -1
  84. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +7 -3
  85. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +5 -0
  86. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +23 -5
  87. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
  88. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +1 -1
  89. package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
  90. package/types/JavaScriptSDK/BaseCore.d.ts +30 -1
  91. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +13 -11
  92. package/types/JavaScriptSDK/ChannelController.d.ts +12 -17
  93. package/types/JavaScriptSDK/CoreUtils.d.ts +0 -6
  94. package/types/JavaScriptSDK/HelperFuncs.d.ts +14 -5
  95. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +49 -3
  96. package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
  97. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -3
  98. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +23 -0
  99. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +15 -0
  100. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +7 -3
  101. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +4 -0
  102. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +18 -3
  103. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
  104. package/types/applicationinsights-core-js.d.ts +5 -4
  105. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
  106. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
  107. package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
  108. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Core, 2.7.4-nightly.2202-07
2
+ * Application Insights JavaScript SDK - Core, 2.8.0-beta.2202-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -458,7 +458,7 @@
458
458
  var _isArray = Array.isArray;
459
459
  var _objToString = ObjProto[strToString];
460
460
  var _fnToString = ObjHasOwnProperty[strToString];
461
- _fnToString.call(ObjClass);
461
+ var _objFunctionString = _fnToString.call(ObjClass);
462
462
  var rCamelCase = /-([a-z])/g;
463
463
  var rNormalizeInvalid = /([^\w\d_$])/g;
464
464
  var rLeadingNumeric = /^(\d+[\w\d_$])/;
@@ -626,6 +626,22 @@
626
626
  function isSymbol(value) {
627
627
  return typeof value === "symbol";
628
628
  }
629
+ function isPlainObject(value) {
630
+ var result = false;
631
+ if (value && typeof value === "object") {
632
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
633
+ if (!proto) {
634
+ result = true;
635
+ }
636
+ else {
637
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
638
+ proto = proto[strConstructor];
639
+ }
640
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
641
+ }
642
+ }
643
+ return result;
644
+ }
629
645
  function toISOString(date) {
630
646
  if (date) {
631
647
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -840,19 +856,33 @@
840
856
  function throwError(message) {
841
857
  throw new Error(message);
842
858
  }
859
+ function _createProxyFunction(source, funcName) {
860
+ var srcFunc = null;
861
+ var src = null;
862
+ if (isFunction(source)) {
863
+ srcFunc = source;
864
+ }
865
+ else {
866
+ src = source;
867
+ }
868
+ return function () {
869
+ var originalArguments = arguments;
870
+ if (srcFunc) {
871
+ src = srcFunc();
872
+ }
873
+ if (src) {
874
+ return src[funcName].apply(src, originalArguments);
875
+ }
876
+ };
877
+ }
843
878
  function proxyAssign(target, source, chkSet) {
844
- if (target && source && target !== source && isObject(target) && isObject(source)) {
879
+ if (target && source && isObject(target) && isObject(source)) {
845
880
  var _loop_1 = function (field) {
846
881
  if (isString(field)) {
847
882
  var value = source[field];
848
883
  if (isFunction(value)) {
849
884
  if (!chkSet || chkSet(field, true, source, target)) {
850
- target[field] = (function (funcName) {
851
- return function () {
852
- var originalArguments = arguments;
853
- return source[funcName].apply(source, originalArguments);
854
- };
855
- })(field);
885
+ target[field] = _createProxyFunction(source, field);
856
886
  }
857
887
  }
858
888
  else if (!chkSet || chkSet(field, false, source, target)) {
@@ -875,6 +905,25 @@
875
905
  }
876
906
  return target;
877
907
  }
908
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
909
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
910
+ if (target && name && source) {
911
+ if (overwriteTarget || isUndefined(target[name])) {
912
+ target[name] = _createProxyFunction(source, theFunc);
913
+ }
914
+ }
915
+ }
916
+ function proxyFunctions(target, source, functionsToProxy, overwriteTarget) {
917
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
918
+ if (target && source && isObject(target) && isArray(functionsToProxy)) {
919
+ arrForEach(functionsToProxy, function (theFuncName) {
920
+ if (isString(theFuncName)) {
921
+ proxyFunctionAs(target, theFuncName, source, theFuncName, overwriteTarget);
922
+ }
923
+ });
924
+ }
925
+ return target;
926
+ }
878
927
  function createClassFromInterface(defaults) {
879
928
  return /** @class */ (function () {
880
929
  function class_1() {
@@ -894,6 +943,50 @@
894
943
  }
895
944
  return theObject;
896
945
  }
946
+ function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
947
+ var theArgs = arguments;
948
+ var extended = theArgs[0] || {};
949
+ var argLen = theArgs.length;
950
+ var deep = false;
951
+ var idx = 1;
952
+ if (argLen > 0 && isBoolean(extended)) {
953
+ deep = extended;
954
+ extended = theArgs[idx] || {};
955
+ idx++;
956
+ }
957
+ if (!isObject(extended)) {
958
+ extended = {};
959
+ }
960
+ for (; idx < argLen; idx++) {
961
+ var arg = theArgs[idx];
962
+ var isArgArray = isArray(arg);
963
+ var isArgObj = isObject(arg);
964
+ for (var prop in arg) {
965
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
966
+ if (!propOk) {
967
+ continue;
968
+ }
969
+ var newValue = arg[prop];
970
+ var isNewArray = void 0;
971
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
972
+ var clone = extended[prop];
973
+ if (isNewArray) {
974
+ if (!isArray(clone)) {
975
+ clone = [];
976
+ }
977
+ }
978
+ else if (!isPlainObject(clone)) {
979
+ clone = {};
980
+ }
981
+ newValue = objExtend(deep, clone, newValue);
982
+ }
983
+ if (newValue !== undefined) {
984
+ extended[prop] = newValue;
985
+ }
986
+ }
987
+ }
988
+ return extended;
989
+ }
897
990
 
898
991
  var strWindow = "window";
899
992
  var strDocument = "document";
@@ -909,6 +1002,7 @@
909
1002
  var strReactNative = "ReactNative";
910
1003
  var strMsie = "msie";
911
1004
  var strTrident = "trident/";
1005
+ var strXMLHttpRequest = "XMLHttpRequest";
912
1006
  var _isTrident = null;
913
1007
  var _navUserAgentCheck = null;
914
1008
  var _enableMocks = false;
@@ -1087,8 +1181,7 @@
1087
1181
  function isFetchSupported(withKeepAlive) {
1088
1182
  var isSupported = false;
1089
1183
  try {
1090
- var fetchApi = getGlobalInst("fetch");
1091
- isSupported = !!fetchApi;
1184
+ isSupported = !!getGlobalInst("fetch");
1092
1185
  var request = getGlobalInst("Request");
1093
1186
  if (isSupported && withKeepAlive && request) {
1094
1187
  isSupported = _hasProperty(request, "keepalive");
@@ -1100,9 +1193,9 @@
1100
1193
  }
1101
1194
  function useXDomainRequest() {
1102
1195
  if (_useXDomainRequest === null) {
1103
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
1196
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
1104
1197
  if (_useXDomainRequest && isXhrSupported()) {
1105
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
1198
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
1106
1199
  }
1107
1200
  }
1108
1201
  return _useXDomainRequest;
@@ -1110,7 +1203,7 @@
1110
1203
  function isXhrSupported() {
1111
1204
  var isSupported = false;
1112
1205
  try {
1113
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
1206
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
1114
1207
  isSupported = !!xmlHttpRequest;
1115
1208
  }
1116
1209
  catch (e) {
@@ -1456,252 +1549,247 @@
1456
1549
  return _defaultPerfManager;
1457
1550
  }
1458
1551
 
1459
- var TelemetryPluginChain = /** @class */ (function () {
1460
- function TelemetryPluginChain(plugin, defItemCtx) {
1461
- var _self = this;
1462
- var _nextProxy = null;
1463
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1464
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1465
- _self._hasRun = false;
1466
- _self.getPlugin = function () {
1467
- return plugin;
1468
- };
1469
- _self.getNext = function () {
1552
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1553
+ var strHasRunFlags = "_hasRun";
1554
+ var strGetTelCtx = "_getTelCtx";
1555
+ var _chainId = 0;
1556
+ function _getNextProxyStart(proxy, config, core, startAt) {
1557
+ while (proxy) {
1558
+ if (proxy.getPlugin() === startAt) {
1559
+ return proxy;
1560
+ }
1561
+ proxy = proxy.getNext();
1562
+ }
1563
+ return createTelemetryProxyChain([startAt], config, core);
1564
+ }
1565
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1566
+ var _nextProxy = null;
1567
+ var _onComplete = null;
1568
+ if (startAt) {
1569
+ _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
1570
+ }
1571
+ else {
1572
+ _nextProxy = telemetryChain;
1573
+ }
1574
+ var context = {
1575
+ core: function () {
1576
+ return core;
1577
+ },
1578
+ diagLog: function () {
1579
+ return safeGetLogger(core, config);
1580
+ },
1581
+ getCfg: function () {
1582
+ return config;
1583
+ },
1584
+ getExtCfg: _getExtCfg,
1585
+ getConfig: _getConfig,
1586
+ hasNext: function () {
1587
+ return _nextProxy != null;
1588
+ },
1589
+ getNext: function () {
1470
1590
  return _nextProxy;
1471
- };
1472
- _self.setNext = function (nextPlugin) {
1591
+ },
1592
+ setNext: function (nextPlugin) {
1473
1593
  _nextProxy = nextPlugin;
1474
- };
1475
- _self.processTelemetry = function (env, itemCtx) {
1476
- if (!itemCtx) {
1477
- itemCtx = defItemCtx;
1594
+ },
1595
+ processNext: function (env) {
1596
+ _processChain(function (nextPlugin) {
1597
+ nextPlugin.processTelemetry(env, context);
1598
+ });
1599
+ },
1600
+ iterate: _iterateChain,
1601
+ createNew: function (plugins, startAt) {
1602
+ if (plugins === void 0) { plugins = null; }
1603
+ if (isArray(plugins)) {
1604
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1478
1605
  }
1479
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1480
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1481
- if (plugin && _hasProcessTelemetry) {
1482
- _self._hasRun = true;
1483
- try {
1484
- itemCtx.setNext(_nextProxy);
1485
- if (_hasSetNext) {
1486
- plugin.setNextPlugin(_nextProxy);
1487
- }
1488
- _nextProxy && (_nextProxy._hasRun = false);
1489
- plugin.processTelemetry(env, itemCtx);
1490
- }
1491
- catch (error) {
1492
- var hasRun = _nextProxy && _nextProxy._hasRun;
1493
- if (!_nextProxy || !hasRun) {
1494
- itemCtx.diagLog().throwInternal(exports.LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1495
- }
1496
- if (_nextProxy && !hasRun) {
1497
- _nextProxy.processTelemetry(env, itemCtx);
1606
+ return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1607
+ },
1608
+ onComplete: function (onComplete) {
1609
+ _onComplete = onComplete;
1610
+ }
1611
+ };
1612
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1613
+ if (defaultValue === void 0) { defaultValue = {}; }
1614
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1615
+ var theConfig;
1616
+ if (config) {
1617
+ var extConfig = config.extensionConfig;
1618
+ if (extConfig && identifier) {
1619
+ theConfig = extConfig[identifier];
1620
+ }
1621
+ }
1622
+ if (!theConfig) {
1623
+ theConfig = defaultValue;
1624
+ }
1625
+ else if (isObject(defaultValue)) {
1626
+ if (mergeDefault !== 0 ) {
1627
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1628
+ if (config && mergeDefault === 2 ) {
1629
+ objForEachKey(defaultValue, function (field) {
1630
+ if (isNullOrUndefined(newConfig_1[field])) {
1631
+ var cfgValue = config[field];
1632
+ if (!isNullOrUndefined(cfgValue)) {
1633
+ newConfig_1[field] = cfgValue;
1634
+ }
1498
1635
  }
1499
- }
1500
- }
1501
- else if (_nextProxy) {
1502
- _self._hasRun = true;
1503
- _nextProxy.processTelemetry(env, itemCtx);
1504
- }
1505
- }, function () { return ({ item: env }); }, !(env.sync));
1506
- };
1507
- }
1508
- return TelemetryPluginChain;
1509
- }());
1510
-
1511
- function _createProxyChain(plugins, itemCtx) {
1512
- var proxies = [];
1513
- if (plugins && plugins.length > 0) {
1514
- var lastProxy = null;
1515
- for (var idx = 0; idx < plugins.length; idx++) {
1516
- var thePlugin = plugins[idx];
1517
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1518
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1519
- proxies.push(newProxy);
1520
- if (lastProxy) {
1521
- lastProxy.setNext(newProxy);
1636
+ });
1522
1637
  }
1523
- lastProxy = newProxy;
1524
1638
  }
1525
1639
  }
1640
+ return theConfig;
1526
1641
  }
1527
- return proxies.length > 0 ? proxies[0] : null;
1528
- }
1529
- function _copyProxyChain(proxy, itemCtx, startAt) {
1530
- var plugins = [];
1531
- var add = startAt ? false : true;
1532
- if (proxy) {
1533
- while (proxy) {
1534
- var thePlugin = proxy.getPlugin();
1535
- if (add || thePlugin === startAt) {
1536
- add = true;
1537
- plugins.push(thePlugin);
1642
+ function _getConfig(identifier, field, defaultValue) {
1643
+ if (defaultValue === void 0) { defaultValue = false; }
1644
+ var theValue;
1645
+ var extConfig = _getExtCfg(identifier, null);
1646
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1647
+ theValue = extConfig[field];
1648
+ }
1649
+ else if (config && !isNullOrUndefined(config[field])) {
1650
+ theValue = config[field];
1651
+ }
1652
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1653
+ }
1654
+ function _processChain(cb) {
1655
+ var nextPlugin = _nextProxy;
1656
+ if (nextPlugin) {
1657
+ _nextProxy = nextPlugin.getNext();
1658
+ cb(nextPlugin);
1659
+ }
1660
+ else {
1661
+ if (_onComplete) {
1662
+ _onComplete();
1663
+ _onComplete = null;
1538
1664
  }
1539
- proxy = proxy.getNext();
1540
1665
  }
1541
1666
  }
1542
- if (!add) {
1543
- plugins.push(startAt);
1667
+ function _iterateChain(cb) {
1668
+ while (_nextProxy) {
1669
+ _processChain(function (nextPlugin) {
1670
+ var plugin = nextPlugin.getPlugin();
1671
+ if (plugin) {
1672
+ cb(plugin);
1673
+ }
1674
+ });
1675
+ }
1544
1676
  }
1545
- return _createProxyChain(plugins, itemCtx);
1677
+ return context;
1546
1678
  }
1547
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1548
- var plugins = srcPlugins;
1549
- var add = false;
1550
- if (startAt && srcPlugins) {
1551
- plugins = [];
1552
- arrForEach(srcPlugins, function (thePlugin) {
1553
- if (add || thePlugin === startAt) {
1679
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1680
+ var firstProxy = null;
1681
+ var add = startAt ? false : true;
1682
+ if (isArray(plugins) && plugins.length > 0) {
1683
+ var lastProxy_1 = null;
1684
+ arrForEach(plugins, function (thePlugin) {
1685
+ if (!add && startAt === thePlugin) {
1554
1686
  add = true;
1555
- plugins.push(thePlugin);
1687
+ }
1688
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1689
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1690
+ if (!firstProxy) {
1691
+ firstProxy = newProxy;
1692
+ }
1693
+ if (lastProxy_1) {
1694
+ lastProxy_1._setNext(newProxy);
1695
+ }
1696
+ lastProxy_1 = newProxy;
1556
1697
  }
1557
1698
  });
1558
1699
  }
1559
- if (startAt && !add) {
1560
- if (!plugins) {
1561
- plugins = [];
1562
- }
1563
- plugins.push(startAt);
1700
+ if (startAt && !firstProxy) {
1701
+ return createTelemetryProxyChain([startAt], config, core);
1564
1702
  }
1565
- return _createProxyChain(plugins, itemCtx);
1703
+ return firstProxy;
1566
1704
  }
1567
- var ProcessTelemetryContext = /** @class */ (function () {
1568
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1569
- var _self = this;
1570
- var _nextProxy = null;
1571
- if (startAt !== null) {
1572
- if (plugins && isFunction(plugins.getPlugin)) {
1573
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1705
+ function createTelemetryPluginProxy(plugin, config, core) {
1706
+ var nextProxy = null;
1707
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1708
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1709
+ var chainId;
1710
+ if (plugin) {
1711
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1712
+ }
1713
+ else {
1714
+ chainId = "Unknown-0-" + _chainId++;
1715
+ }
1716
+ var proxyChain = {
1717
+ getPlugin: function () {
1718
+ return plugin;
1719
+ },
1720
+ getNext: function () {
1721
+ return nextProxy;
1722
+ },
1723
+ processTelemetry: _processTelemetry,
1724
+ _id: chainId,
1725
+ _setNext: function (nextPlugin) {
1726
+ nextProxy = nextPlugin;
1727
+ }
1728
+ };
1729
+ function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1730
+ if (!itemCtx) {
1731
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1732
+ itemCtx = plugin[strGetTelCtx]();
1574
1733
  }
1575
- else {
1576
- if (startAt) {
1577
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1578
- }
1579
- else if (isUndefined(startAt)) {
1580
- _nextProxy = _createProxyChain(plugins, _self);
1581
- }
1734
+ if (!itemCtx) {
1735
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1582
1736
  }
1583
1737
  }
1584
- _self.core = function () {
1585
- return core;
1586
- };
1587
- _self.diagLog = function () {
1588
- return safeGetLogger(core, config);
1589
- };
1590
- _self.getCfg = function () {
1591
- return config;
1592
- };
1593
- _self.getExtCfg = function (identifier, defaultValue) {
1594
- if (defaultValue === void 0) { defaultValue = {}; }
1595
- var theConfig;
1596
- if (config) {
1597
- var extConfig = config.extensionConfig;
1598
- if (extConfig && identifier) {
1599
- theConfig = extConfig[identifier];
1738
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1739
+ var hasRunContext = itemCtx[strHasRunFlags];
1740
+ if (!hasRunContext) {
1741
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1742
+ }
1743
+ doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1744
+ hasRunContext[chainId] = true;
1745
+ var hasRun = false;
1746
+ itemCtx.setNext(nextProxy);
1747
+ if (plugin) {
1748
+ try {
1749
+ var nextId = nextProxy ? nextProxy._id : "";
1750
+ if (nextId) {
1751
+ hasRunContext[nextId] = false;
1752
+ }
1753
+ hasRun = processPluginFn(itemCtx);
1754
+ }
1755
+ catch (error) {
1756
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1757
+ if (hasNextRun) {
1758
+ hasRun = true;
1759
+ }
1760
+ if (!nextProxy || !hasNextRun) {
1761
+ itemCtx.diagLog().throwInternal(exports.LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1762
+ }
1600
1763
  }
1601
1764
  }
1602
- return (theConfig ? theConfig : defaultValue);
1603
- };
1604
- _self.getConfig = function (identifier, field, defaultValue) {
1605
- if (defaultValue === void 0) { defaultValue = false; }
1606
- var theValue;
1607
- var extConfig = _self.getExtCfg(identifier, null);
1608
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1609
- theValue = extConfig[field];
1765
+ if (nextProxy && !hasRun) {
1766
+ processProxyFn(itemCtx);
1610
1767
  }
1611
- else if (config && !isNullOrUndefined(config[field])) {
1612
- theValue = config[field];
1768
+ }, details, isAsync);
1769
+ }
1770
+ function _processTelemetry(env, itemCtx) {
1771
+ _processChain(itemCtx, function (itemCtx) {
1772
+ if (!hasProcessTelemetry) {
1773
+ return false;
1613
1774
  }
1614
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1615
- };
1616
- _self.hasNext = function () {
1617
- return _nextProxy != null;
1618
- };
1619
- _self.getNext = function () {
1620
- return _nextProxy;
1621
- };
1622
- _self.setNext = function (nextPlugin) {
1623
- _nextProxy = nextPlugin;
1624
- };
1625
- _self.processNext = function (env) {
1626
- var nextPlugin = _nextProxy;
1627
- if (nextPlugin) {
1628
- _nextProxy = nextPlugin.getNext();
1629
- nextPlugin.processTelemetry(env, _self);
1775
+ if (hasSetNext) {
1776
+ plugin.setNextPlugin(nextProxy);
1630
1777
  }
1631
- };
1632
- _self.createNew = function (plugins, startAt) {
1633
- if (plugins === void 0) { plugins = null; }
1634
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1635
- };
1778
+ plugin.processTelemetry(env, itemCtx);
1779
+ return true;
1780
+ }, function (itemCtx) {
1781
+ nextProxy.processTelemetry(env, itemCtx);
1782
+ }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1636
1783
  }
1637
- return ProcessTelemetryContext;
1638
- }());
1639
-
1640
- var strIKey = "iKey";
1641
- var strExtensionConfig = "extensionConfig";
1642
-
1643
- var strGetPlugin = "getPlugin";
1644
- var BaseTelemetryPlugin = /** @class */ (function () {
1645
- function BaseTelemetryPlugin() {
1784
+ return objFreeze(proxyChain);
1785
+ }
1786
+ var ProcessTelemetryContext = /** @class */ (function () {
1787
+ function ProcessTelemetryContext(pluginChain, config, core, startAt) {
1646
1788
  var _self = this;
1647
- var _isinitialized = false;
1648
- var _rootCtx = null;
1649
- var _nextPlugin = null;
1650
- _self.core = null;
1651
- _self.diagLog = function (itemCtx) {
1652
- return _self._getTelCtx(itemCtx).diagLog();
1653
- };
1654
- _self.isInitialized = function () {
1655
- return _isinitialized;
1656
- };
1657
- _self.setInitialized = function (isInitialized) {
1658
- _isinitialized = isInitialized;
1659
- };
1660
- _self.setNextPlugin = function (next) {
1661
- _nextPlugin = next;
1662
- };
1663
- _self.processNext = function (env, itemCtx) {
1664
- if (itemCtx) {
1665
- itemCtx.processNext(env);
1666
- }
1667
- else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1668
- _nextPlugin.processTelemetry(env, null);
1669
- }
1670
- };
1671
- _self._getTelCtx = function (currentCtx) {
1672
- if (currentCtx === void 0) { currentCtx = null; }
1673
- var itemCtx = currentCtx;
1674
- if (!itemCtx) {
1675
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1676
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1677
- itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1678
- }
1679
- else {
1680
- itemCtx = rootCtx.createNew(null, _nextPlugin);
1681
- }
1682
- }
1683
- return itemCtx;
1684
- };
1685
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1686
- if (config) {
1687
- setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1688
- }
1689
- if (!pluginChain && core) {
1690
- pluginChain = core.getProcessTelContext().getNext();
1691
- }
1692
- var nextPlugin = _nextPlugin;
1693
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1694
- nextPlugin = _nextPlugin[strGetPlugin]();
1695
- }
1696
- _self.core = core;
1697
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1698
- _isinitialized = true;
1699
- };
1789
+ var context = createProcessTelemetryContext(pluginChain, config, core, startAt);
1790
+ proxyFunctions(_self, context, objKeys(context));
1700
1791
  }
1701
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1702
- this._baseTelInit(config, core, extensions, pluginChain);
1703
- };
1704
- return BaseTelemetryPlugin;
1792
+ return ProcessTelemetryContext;
1705
1793
  }());
1706
1794
 
1707
1795
  var processTelemetry = "processTelemetry";
@@ -1745,81 +1833,6 @@
1745
1833
  });
1746
1834
  }
1747
1835
 
1748
- var ChannelControllerPriority = 500;
1749
- var ChannelValidationMessage = "Channel has invalid priority";
1750
- var ChannelController = /** @class */ (function (_super) {
1751
- __extendsFn(ChannelController, _super);
1752
- function ChannelController() {
1753
- var _this = _super.call(this) || this;
1754
- _this.identifier = "ChannelControllerPlugin";
1755
- _this.priority = ChannelControllerPriority;
1756
- var _channelQueue;
1757
- dynamicProto(ChannelController, _this, function (_self, _base) {
1758
- _self.setNextPlugin = function (next) {
1759
- };
1760
- _self.processTelemetry = function (item, itemCtx) {
1761
- if (_channelQueue) {
1762
- arrForEach(_channelQueue, function (queues) {
1763
- if (queues.length > 0) {
1764
- var chainCtx = _this._getTelCtx(itemCtx).createNew(queues);
1765
- chainCtx.processNext(item);
1766
- }
1767
- });
1768
- }
1769
- };
1770
- _self.getChannelControls = function () {
1771
- return _channelQueue;
1772
- };
1773
- _self.initialize = function (config, core, extensions) {
1774
- if (_self.isInitialized()) {
1775
- return;
1776
- }
1777
- _base.initialize(config, core, extensions);
1778
- _createChannelQueues((config || {}).channels, extensions);
1779
- arrForEach(_channelQueue, function (queue) { return initializePlugins(new ProcessTelemetryContext(queue, config, core), extensions); });
1780
- };
1781
- });
1782
- function _checkQueuePriority(queue) {
1783
- arrForEach(queue, function (queueItem) {
1784
- if (queueItem.priority < ChannelControllerPriority) {
1785
- throwError(ChannelValidationMessage + queueItem.identifier);
1786
- }
1787
- });
1788
- }
1789
- function _addChannelQueue(queue) {
1790
- if (queue && queue.length > 0) {
1791
- queue = queue.sort(function (a, b) {
1792
- return a.priority - b.priority;
1793
- });
1794
- _checkQueuePriority(queue);
1795
- _channelQueue.push(queue);
1796
- }
1797
- }
1798
- function _createChannelQueues(channels, extensions) {
1799
- _channelQueue = [];
1800
- if (channels) {
1801
- arrForEach(channels, function (queue) { return _addChannelQueue(queue); });
1802
- }
1803
- if (extensions) {
1804
- var extensionQueue_1 = [];
1805
- arrForEach(extensions, function (plugin) {
1806
- if (plugin.priority > ChannelControllerPriority) {
1807
- extensionQueue_1.push(plugin);
1808
- }
1809
- });
1810
- _addChannelQueue(extensionQueue_1);
1811
- }
1812
- }
1813
- return _this;
1814
- }
1815
- ChannelController._staticInit = (function () {
1816
- var proto = ChannelController.prototype;
1817
- objDefineAccessors(proto, "ChannelControls", proto.getChannelControls);
1818
- objDefineAccessors(proto, "channelQueue", proto.getChannelControls);
1819
- })();
1820
- return ChannelController;
1821
- }(BaseTelemetryPlugin));
1822
-
1823
1836
  var strToGMTString = "toGMTString";
1824
1837
  var strToUTCString = "toUTCString";
1825
1838
  var strCookie = "cookie";
@@ -2066,24 +2079,362 @@
2066
2079
  return false;
2067
2080
  }
2068
2081
 
2069
- var validationError = "Extensions must provide callback to initialize";
2082
+ var strIKey = "iKey";
2083
+ var strExtensionConfig = "extensionConfig";
2084
+
2085
+ var ChannelControllerPriority = 500;
2086
+ var ChannelValidationMessage = "Channel has invalid priority - ";
2087
+ function _addChannelQueue(channelQueue, queue, config, core) {
2088
+ if (queue && isArray(queue) && queue.length > 0) {
2089
+ queue = queue.sort(function (a, b) {
2090
+ return a.priority - b.priority;
2091
+ });
2092
+ arrForEach(queue, function (queueItem) {
2093
+ if (queueItem.priority < ChannelControllerPriority) {
2094
+ throwError(ChannelValidationMessage + queueItem.identifier);
2095
+ }
2096
+ });
2097
+ channelQueue.push({
2098
+ queue: objFreeze(queue),
2099
+ chain: createTelemetryProxyChain(queue, config, core)
2100
+ });
2101
+ }
2102
+ }
2103
+ function createChannelControllerPlugin(channelQueue, core) {
2104
+ function _getTelCtx(itemCtx) {
2105
+ if (!itemCtx) {
2106
+ itemCtx = createProcessTelemetryContext(null, core.config, core, null);
2107
+ }
2108
+ return itemCtx;
2109
+ }
2110
+ function _processChannelQueue(itemCtx, processFn, onComplete) {
2111
+ if (channelQueue && channelQueue.length > 0) {
2112
+ var waiting_1 = channelQueue.length;
2113
+ arrForEach(channelQueue, function (channels) {
2114
+ if (channels && channels.queue.length > 0) {
2115
+ var channelChain = channels.chain;
2116
+ var chainCtx = _getTelCtx(itemCtx).createNew(channelChain);
2117
+ chainCtx.onComplete(function () {
2118
+ waiting_1--;
2119
+ if (waiting_1 === 0) {
2120
+ onComplete && onComplete();
2121
+ onComplete = null;
2122
+ }
2123
+ });
2124
+ processFn(chainCtx);
2125
+ }
2126
+ else {
2127
+ waiting_1--;
2128
+ }
2129
+ });
2130
+ if (waiting_1 === 0) {
2131
+ onComplete && onComplete();
2132
+ }
2133
+ }
2134
+ else {
2135
+ onComplete && onComplete();
2136
+ }
2137
+ }
2138
+ var isInitialized = false;
2139
+ var channelController = {
2140
+ identifier: "ChannelControllerPlugin",
2141
+ priority: ChannelControllerPriority,
2142
+ initialize: function (config, core, extensions, pluginChain) {
2143
+ isInitialized = true;
2144
+ arrForEach(channelQueue, function (channels) {
2145
+ if (channels && channels.queue.length > 0) {
2146
+ initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2147
+ }
2148
+ });
2149
+ },
2150
+ isInitialized: function () { return isInitialized; },
2151
+ processTelemetry: function (item, itemCtx) {
2152
+ _processChannelQueue(itemCtx, function (chainCtx) {
2153
+ chainCtx.processNext(item);
2154
+ }, function () {
2155
+ itemCtx.processNext(item);
2156
+ });
2157
+ },
2158
+ pause: function () {
2159
+ _processChannelQueue(null, function (chainCtx) {
2160
+ chainCtx.iterate(function (plugin) {
2161
+ plugin.pause && plugin.pause();
2162
+ });
2163
+ });
2164
+ },
2165
+ resume: function () {
2166
+ _processChannelQueue(null, function (chainCtx) {
2167
+ chainCtx.iterate(function (plugin) {
2168
+ plugin.resume && plugin.resume();
2169
+ });
2170
+ });
2171
+ },
2172
+ teardown: function () {
2173
+ _processChannelQueue(null, function (chainCtx) {
2174
+ chainCtx.iterate(function (plugin) {
2175
+ plugin.teardown && plugin.teardown();
2176
+ });
2177
+ });
2178
+ },
2179
+ flush: function (isAsync, callBack, sendReason, cbTimeout) {
2180
+ var doneIterating = false;
2181
+ var waiting = 0;
2182
+ var cbTimer = null;
2183
+ cbTimeout = cbTimeout || 5000;
2184
+ function doCallback() {
2185
+ if (doneIterating && waiting === 0) {
2186
+ if (cbTimer) {
2187
+ clearTimeout(cbTimer);
2188
+ cbTimer = null;
2189
+ }
2190
+ callBack && callBack(doneIterating);
2191
+ callBack = null;
2192
+ }
2193
+ }
2194
+ waiting = 1;
2195
+ _processChannelQueue(null, function (chainCtx) {
2196
+ chainCtx.iterate(function (plugin) {
2197
+ if (plugin.flush) {
2198
+ waiting++;
2199
+ if (!plugin.flush(isAsync, function () {
2200
+ waiting--;
2201
+ doCallback();
2202
+ }, sendReason)) {
2203
+ if (cbTimer == null) {
2204
+ cbTimer = setTimeout(function () {
2205
+ cbTimer = null;
2206
+ callBack && callBack(false);
2207
+ callBack = null;
2208
+ }, cbTimeout);
2209
+ }
2210
+ }
2211
+ }
2212
+ });
2213
+ }, function () {
2214
+ waiting--;
2215
+ doneIterating = true;
2216
+ doCallback();
2217
+ });
2218
+ }
2219
+ };
2220
+ return channelController;
2221
+ }
2222
+ function createChannelQueues(channels, extensions, config, core) {
2223
+ var channelQueue = [];
2224
+ if (channels) {
2225
+ arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, config, core); });
2226
+ }
2227
+ if (extensions) {
2228
+ var extensionQueue_1 = [];
2229
+ arrForEach(extensions, function (plugin) {
2230
+ if (plugin.priority > ChannelControllerPriority) {
2231
+ extensionQueue_1.push(plugin);
2232
+ }
2233
+ });
2234
+ _addChannelQueue(channelQueue, extensionQueue_1, config, core);
2235
+ }
2236
+ return channelQueue;
2237
+ }
2238
+
2239
+ var strGetPlugin = "getPlugin";
2240
+ var BaseTelemetryPlugin = /** @class */ (function () {
2241
+ function BaseTelemetryPlugin() {
2242
+ var _self = this;
2243
+ var _isinitialized;
2244
+ var _rootCtx;
2245
+ var _nextPlugin;
2246
+ var _hooks;
2247
+ _initDefaults();
2248
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
2249
+ _self.initialize = function (config, core, extensions, pluginChain) {
2250
+ _setDefaults(config, core, pluginChain);
2251
+ _isinitialized = true;
2252
+ };
2253
+ _self._addHook = function (hooks) {
2254
+ if (hooks) {
2255
+ if (isArray(hooks)) {
2256
+ _hooks = _hooks.concat(hooks);
2257
+ }
2258
+ else {
2259
+ _hooks.push(hooks);
2260
+ }
2261
+ }
2262
+ };
2263
+ });
2264
+ _self.diagLog = function (itemCtx) {
2265
+ return _getTelCtx(itemCtx).diagLog();
2266
+ };
2267
+ _self.isInitialized = function () {
2268
+ return _isinitialized;
2269
+ };
2270
+ _self.setInitialized = function (isInitialized) {
2271
+ _isinitialized = isInitialized;
2272
+ };
2273
+ _self.setNextPlugin = function (next) {
2274
+ _nextPlugin = next;
2275
+ };
2276
+ _self.processNext = function (env, itemCtx) {
2277
+ if (itemCtx) {
2278
+ itemCtx.processNext(env);
2279
+ }
2280
+ else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
2281
+ _nextPlugin.processTelemetry(env, null);
2282
+ }
2283
+ };
2284
+ _self._getTelCtx = _getTelCtx;
2285
+ function _getTelCtx(currentCtx) {
2286
+ if (currentCtx === void 0) { currentCtx = null; }
2287
+ var itemCtx = currentCtx;
2288
+ if (!itemCtx) {
2289
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
2290
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2291
+ itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
2292
+ }
2293
+ else {
2294
+ itemCtx = rootCtx.createNew(null, _nextPlugin);
2295
+ }
2296
+ }
2297
+ return itemCtx;
2298
+ }
2299
+ function _setDefaults(config, core, pluginChain) {
2300
+ if (config) {
2301
+ setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
2302
+ }
2303
+ if (!pluginChain && core) {
2304
+ pluginChain = core.getProcessTelContext().getNext();
2305
+ }
2306
+ var nextPlugin = _nextPlugin;
2307
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2308
+ nextPlugin = _nextPlugin[strGetPlugin]();
2309
+ }
2310
+ _self.core = core;
2311
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
2312
+ }
2313
+ function _initDefaults() {
2314
+ _isinitialized = false;
2315
+ _self.core = null;
2316
+ _rootCtx = null;
2317
+ _nextPlugin = null;
2318
+ _hooks = [];
2319
+ }
2320
+ }
2321
+ return BaseTelemetryPlugin;
2322
+ }());
2323
+
2324
+ var TelemetryInitializerPlugin = /** @class */ (function (_super) {
2325
+ __extendsFn(TelemetryInitializerPlugin, _super);
2326
+ function TelemetryInitializerPlugin() {
2327
+ var _this = _super.call(this) || this;
2328
+ _this.identifier = "TelemetryInitializerPlugin";
2329
+ _this.priority = 199;
2330
+ var _id;
2331
+ var _initializers;
2332
+ _initDefaults();
2333
+ dynamicProto(TelemetryInitializerPlugin, _this, function (_self, _base) {
2334
+ _self.addTelemetryInitializer = function (telemetryInitializer) {
2335
+ var theInitializer = {
2336
+ id: _id++,
2337
+ fn: telemetryInitializer
2338
+ };
2339
+ _initializers.push(theInitializer);
2340
+ var handler = {
2341
+ remove: function () {
2342
+ arrForEach(_initializers, function (initializer, idx) {
2343
+ if (initializer.id === theInitializer.id) {
2344
+ _initializers.splice(idx, 1);
2345
+ return -1;
2346
+ }
2347
+ });
2348
+ }
2349
+ };
2350
+ return handler;
2351
+ };
2352
+ _self.processTelemetry = function (item, itemCtx) {
2353
+ var doNotSendItem = false;
2354
+ var telemetryInitializersCount = _initializers.length;
2355
+ for (var i = 0; i < telemetryInitializersCount; ++i) {
2356
+ var telemetryInitializer = _initializers[i];
2357
+ if (telemetryInitializer) {
2358
+ try {
2359
+ if (telemetryInitializer.fn.apply(null, [item]) === false) {
2360
+ doNotSendItem = true;
2361
+ break;
2362
+ }
2363
+ }
2364
+ catch (e) {
2365
+ itemCtx.diagLog().throwInternal(exports.LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2366
+ }
2367
+ }
2368
+ }
2369
+ if (!doNotSendItem) {
2370
+ _self.processNext(item, itemCtx);
2371
+ }
2372
+ };
2373
+ _self.unload = function (itemCtx, isAsync) {
2374
+ _base.unload(itemCtx, isAsync);
2375
+ _initDefaults();
2376
+ };
2377
+ });
2378
+ function _initDefaults() {
2379
+ _id = 0;
2380
+ _initializers = [];
2381
+ }
2382
+ return _this;
2383
+ }
2384
+ return TelemetryInitializerPlugin;
2385
+ }(BaseTelemetryPlugin));
2386
+
2387
+ var strValidationError = "Plugins must provide initialize method";
2070
2388
  var strNotificationManager = "_notificationManager";
2071
2389
  function _createPerfManager(core, notificationMgr) {
2072
2390
  return new PerfManager(notificationMgr);
2073
2391
  }
2392
+ function _validateExtensions(logger, channelPriority, allExtensions) {
2393
+ var coreExtensions = [];
2394
+ var extPriorities = {};
2395
+ arrForEach(allExtensions, function (ext) {
2396
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
2397
+ throwError(strValidationError);
2398
+ }
2399
+ var extPriority = ext.priority;
2400
+ var identifier = ext.identifier;
2401
+ if (ext && extPriority) {
2402
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
2403
+ logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
2404
+ }
2405
+ else {
2406
+ extPriorities[extPriority] = identifier;
2407
+ }
2408
+ }
2409
+ if (!extPriority || extPriority < channelPriority) {
2410
+ coreExtensions.push(ext);
2411
+ }
2412
+ });
2413
+ return {
2414
+ all: allExtensions,
2415
+ core: coreExtensions
2416
+ };
2417
+ }
2074
2418
  var BaseCore = /** @class */ (function () {
2075
2419
  function BaseCore() {
2076
- var _isInitialized = false;
2420
+ var _isInitialized;
2077
2421
  var _eventQueue;
2078
- var _channelController;
2079
2422
  var _notificationManager;
2080
2423
  var _perfManager;
2424
+ var _cfgPerfManager;
2081
2425
  var _cookieManager;
2426
+ var _pluginChain;
2427
+ var _configExtensions;
2428
+ var _coreExtensions;
2429
+ var _channelControl;
2430
+ var _channelConfig;
2431
+ var _channelQueue;
2432
+ var _telemetryInitializerPlugin;
2433
+ var _internalLogsEventName;
2434
+ var _debugListener;
2435
+ var _internalLogPoller = 0;
2082
2436
  dynamicProto(BaseCore, this, function (_self) {
2083
- _self._extensions = new Array();
2084
- _channelController = new ChannelController();
2085
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: exports.LoggingSeverity.CRITICAL });
2086
- _eventQueue = [];
2437
+ _initDefaults();
2087
2438
  _self.isInitialized = function () { return _isInitialized; };
2088
2439
  _self.initialize = function (config, extensions, logger, notificationManager) {
2089
2440
  if (_self.isInitialized()) {
@@ -2095,48 +2446,18 @@
2095
2446
  _notificationManager = notificationManager;
2096
2447
  _self[strNotificationManager] = notificationManager;
2097
2448
  _self.config = config || {};
2098
- if (notificationManager && _self.config.disableDbgExt !== true) {
2099
- notificationManager.addNotificationListener(getDebugListener(config));
2100
- }
2101
- if (_self.config.enablePerfMgr) {
2102
- setValue(_self.config, "createPerfMgr", _createPerfManager);
2103
- }
2449
+ _initDebugListener(config);
2450
+ _initPerfManager(config);
2104
2451
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
2105
2452
  var extConfig = getSetValue(config, strExtensionConfig);
2106
2453
  extConfig.NotificationManager = notificationManager;
2107
2454
  if (logger) {
2108
2455
  _self.logger = logger;
2109
2456
  }
2110
- var allExtensions = [];
2111
- allExtensions.push.apply(allExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2112
- allExtensions = sortPlugins(allExtensions);
2113
- var coreExtensions = [];
2114
- var extPriorities = {};
2115
- arrForEach(allExtensions, function (ext) {
2116
- if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
2117
- throwError(validationError);
2118
- }
2119
- var extPriority = ext.priority;
2120
- var identifier = ext.identifier;
2121
- if (ext && extPriority) {
2122
- if (!isNullOrUndefined(extPriorities[extPriority])) {
2123
- logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
2124
- }
2125
- else {
2126
- extPriorities[extPriority] = identifier;
2127
- }
2128
- }
2129
- if (!extPriority || extPriority < _channelController.priority) {
2130
- coreExtensions.push(ext);
2131
- }
2132
- });
2133
- allExtensions.push(_channelController);
2134
- coreExtensions.push(_channelController);
2135
- allExtensions = sortPlugins(allExtensions);
2136
- _self._extensions = allExtensions;
2137
- initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);
2138
- initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);
2139
- _self._extensions = coreExtensions;
2457
+ _configExtensions = [];
2458
+ _configExtensions.push.apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2459
+ _channelConfig = (config || {}).channels;
2460
+ _initPluginChain(config);
2140
2461
  if (_self.getTransmissionControls().length === 0) {
2141
2462
  throwError("No channels available");
2142
2463
  }
@@ -2144,7 +2465,11 @@
2144
2465
  _self.releaseQueue();
2145
2466
  };
2146
2467
  _self.getTransmissionControls = function () {
2147
- return _channelController.getChannelControls();
2468
+ var controls = [];
2469
+ arrForEach(_channelQueue, function (channels) {
2470
+ controls.push(channels.queue);
2471
+ });
2472
+ return objFreeze(controls);
2148
2473
  };
2149
2474
  _self.track = function (telemetryItem) {
2150
2475
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
@@ -2158,12 +2483,7 @@
2158
2483
  }
2159
2484
  };
2160
2485
  _self.getProcessTelContext = function () {
2161
- var extensions = _self._extensions;
2162
- var thePlugins = extensions;
2163
- if (!extensions || extensions.length === 0) {
2164
- thePlugins = [_channelController];
2165
- }
2166
- return new ProcessTelemetryContext(thePlugins, _self.config, _self);
2486
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2167
2487
  };
2168
2488
  _self.getNotifyMgr = function () {
2169
2489
  if (!_notificationManager) {
@@ -2178,6 +2498,16 @@
2178
2498
  }
2179
2499
  return _notificationManager;
2180
2500
  };
2501
+ _self.addNotificationListener = function (listener) {
2502
+ if (_notificationManager) {
2503
+ _notificationManager.addNotificationListener(listener);
2504
+ }
2505
+ };
2506
+ _self.removeNotificationListener = function (listener) {
2507
+ if (_notificationManager) {
2508
+ _notificationManager.removeNotificationListener(listener);
2509
+ }
2510
+ };
2181
2511
  _self.getCookieMgr = function () {
2182
2512
  if (!_cookieManager) {
2183
2513
  _cookieManager = createCookieMgr(_self.config, _self.logger);
@@ -2188,12 +2518,12 @@
2188
2518
  _cookieManager = cookieMgr;
2189
2519
  };
2190
2520
  _self.getPerfMgr = function () {
2191
- if (!_perfManager) {
2521
+ if (!_perfManager && !_cfgPerfManager) {
2192
2522
  if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
2193
- _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2523
+ _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
2194
2524
  }
2195
2525
  }
2196
- return _perfManager || getGblPerfMgr();
2526
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
2197
2527
  };
2198
2528
  _self.setPerfMgr = function (perfMgr) {
2199
2529
  _perfManager = perfMgr;
@@ -2202,18 +2532,153 @@
2202
2532
  return _eventQueue.length;
2203
2533
  };
2204
2534
  _self.releaseQueue = function () {
2205
- if (_eventQueue.length > 0) {
2206
- arrForEach(_eventQueue, function (event) {
2535
+ if (_isInitialized && _eventQueue.length > 0) {
2536
+ var eventQueue = _eventQueue;
2537
+ _eventQueue = [];
2538
+ arrForEach(eventQueue, function (event) {
2207
2539
  _self.getProcessTelContext().processNext(event);
2208
2540
  });
2209
- _eventQueue = [];
2210
2541
  }
2211
2542
  };
2543
+ _self.pollInternalLogs = function (eventName) {
2544
+ _internalLogsEventName = eventName;
2545
+ var interval = _self.config.diagnosticLogInterval;
2546
+ if (!interval || !(interval > 0)) {
2547
+ interval = 10000;
2548
+ }
2549
+ if (_internalLogPoller) {
2550
+ clearInterval(_internalLogPoller);
2551
+ }
2552
+ _internalLogPoller = setInterval(function () {
2553
+ _flushInternalLogs();
2554
+ }, interval);
2555
+ return _internalLogPoller;
2556
+ };
2557
+ _self.stopPollingInternalLogs = function () {
2558
+ if (_internalLogPoller) {
2559
+ clearInterval(_internalLogPoller);
2560
+ _internalLogPoller = 0;
2561
+ _flushInternalLogs();
2562
+ }
2563
+ };
2564
+ proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2565
+ _self.getPlugin = _getPlugin;
2566
+ function _initDefaults() {
2567
+ _isInitialized = false;
2568
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: exports.LoggingSeverity.CRITICAL });
2569
+ _self.config = null;
2570
+ _self._extensions = [];
2571
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
2572
+ _eventQueue = [];
2573
+ _notificationManager = null;
2574
+ _perfManager = null;
2575
+ _cfgPerfManager = null;
2576
+ _cookieManager = null;
2577
+ _pluginChain = null;
2578
+ _coreExtensions = null;
2579
+ _configExtensions = null;
2580
+ _channelControl = null;
2581
+ _channelConfig = null;
2582
+ _channelQueue = null;
2583
+ _internalLogsEventName = null;
2584
+ }
2585
+ function _initPluginChain(config) {
2586
+ var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
2587
+ _coreExtensions = theExtensions.core;
2588
+ _pluginChain = null;
2589
+ var allExtensions = theExtensions.all;
2590
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
2591
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2592
+ allExtensions.push(_channelControl);
2593
+ _coreExtensions.push(_channelControl);
2594
+ _self._extensions = sortPlugins(allExtensions);
2595
+ _channelControl.initialize(config, _self, allExtensions);
2596
+ initializePlugins(_self.getProcessTelContext(), allExtensions);
2597
+ _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2598
+ }
2599
+ function _getPlugin(pluginIdentifier) {
2600
+ var theExt = null;
2601
+ var thePlugin = null;
2602
+ arrForEach(_self._extensions, function (ext) {
2603
+ if (ext.identifier === pluginIdentifier) {
2604
+ thePlugin = ext;
2605
+ return -1;
2606
+ }
2607
+ });
2608
+ if (thePlugin) {
2609
+ theExt = {
2610
+ plugin: thePlugin
2611
+ };
2612
+ }
2613
+ return theExt;
2614
+ }
2615
+ function _getPluginChain() {
2616
+ if (!_pluginChain) {
2617
+ var extensions = (_coreExtensions || []).slice();
2618
+ extensions.push(_telemetryInitializerPlugin);
2619
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
2620
+ }
2621
+ return _pluginChain;
2622
+ }
2623
+ function _flushInternalLogs() {
2624
+ var queue = _self.logger ? _self.logger.queue : [];
2625
+ if (queue) {
2626
+ arrForEach(queue, function (logMessage) {
2627
+ var item = {
2628
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
2629
+ iKey: _self.config.instrumentationKey,
2630
+ time: toISOString(new Date()),
2631
+ baseType: _InternalLogMessage.dataType,
2632
+ baseData: { message: logMessage.message }
2633
+ };
2634
+ _self.track(item);
2635
+ });
2636
+ queue.length = 0;
2637
+ }
2638
+ }
2639
+ function _initDebugListener(config) {
2640
+ if (config.disableDbgExt === true && _debugListener) {
2641
+ _notificationManager.removeNotificationListener(_debugListener);
2642
+ _debugListener = null;
2643
+ }
2644
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
2645
+ _debugListener = getDebugListener(config);
2646
+ _notificationManager.addNotificationListener(_debugListener);
2647
+ }
2648
+ }
2649
+ function _initPerfManager(config) {
2650
+ if (!config.enablePerfMgr && _cfgPerfManager) {
2651
+ _cfgPerfManager = null;
2652
+ }
2653
+ if (config.enablePerfMgr) {
2654
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
2655
+ }
2656
+ }
2212
2657
  });
2213
2658
  }
2214
2659
  return BaseCore;
2215
2660
  }());
2216
2661
 
2662
+ var strEventsSent = "eventsSent";
2663
+ var strEventsDiscarded = "eventsDiscarded";
2664
+ var strEventsSendRequest = "eventsSendRequest";
2665
+ var strPerfEvent = "perfEvent";
2666
+ function _runListeners(listeners, name, isAsync, callback) {
2667
+ arrForEach(listeners, function (listener) {
2668
+ if (listener && listener[name]) {
2669
+ if (isAsync) {
2670
+ setTimeout(function () { return callback(listener); }, 0);
2671
+ }
2672
+ else {
2673
+ try {
2674
+ callback(listener);
2675
+ }
2676
+ catch (e) {
2677
+ }
2678
+ }
2679
+ }
2680
+ });
2681
+ }
2217
2682
  var NotificationManager = /** @class */ (function () {
2218
2683
  function NotificationManager(config) {
2219
2684
  this.listeners = [];
@@ -2230,50 +2695,29 @@
2230
2695
  }
2231
2696
  };
2232
2697
  _self.eventsSent = function (events) {
2233
- arrForEach(_self.listeners, function (listener) {
2234
- if (listener && listener.eventsSent) {
2235
- setTimeout(function () { return listener.eventsSent(events); }, 0);
2236
- }
2698
+ _runListeners(_self.listeners, strEventsSent, true, function (listener) {
2699
+ listener[strEventsSent](events);
2237
2700
  });
2238
2701
  };
2239
2702
  _self.eventsDiscarded = function (events, reason) {
2240
- arrForEach(_self.listeners, function (listener) {
2241
- if (listener && listener.eventsDiscarded) {
2242
- setTimeout(function () { return listener.eventsDiscarded(events, reason); }, 0);
2243
- }
2703
+ _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
2704
+ listener[strEventsDiscarded](events, reason);
2244
2705
  });
2245
2706
  };
2246
2707
  _self.eventsSendRequest = function (sendReason, isAsync) {
2247
- arrForEach(_self.listeners, function (listener) {
2248
- if (listener && listener.eventsSendRequest) {
2249
- if (isAsync) {
2250
- setTimeout(function () { return listener.eventsSendRequest(sendReason, isAsync); }, 0);
2251
- }
2252
- else {
2253
- try {
2254
- listener.eventsSendRequest(sendReason, isAsync);
2255
- }
2256
- catch (e) {
2257
- }
2258
- }
2259
- }
2708
+ _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
2709
+ listener[strEventsSendRequest](sendReason, isAsync);
2260
2710
  });
2261
2711
  };
2262
2712
  _self.perfEvent = function (perfEvent) {
2263
2713
  if (perfEvent) {
2264
2714
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
2265
- arrForEach(_self.listeners, function (listener) {
2266
- if (listener && listener.perfEvent) {
2267
- if (perfEvent.isAsync) {
2268
- setTimeout(function () { return listener.perfEvent(perfEvent); }, 0);
2269
- }
2270
- else {
2271
- try {
2272
- listener.perfEvent(perfEvent);
2273
- }
2274
- catch (e) {
2275
- }
2276
- }
2715
+ _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
2716
+ if (perfEvent.isAsync) {
2717
+ setTimeout(function () { return listener[strPerfEvent](perfEvent); }, 0);
2718
+ }
2719
+ else {
2720
+ listener[strPerfEvent](perfEvent);
2277
2721
  }
2278
2722
  });
2279
2723
  }
@@ -2288,7 +2732,6 @@
2288
2732
  __extendsFn(AppInsightsCore, _super);
2289
2733
  function AppInsightsCore() {
2290
2734
  var _this = _super.call(this) || this;
2291
- var _internalLogPoller = 0;
2292
2735
  dynamicProto(AppInsightsCore, _this, function (_self, _base) {
2293
2736
  _self.initialize = function (config, extensions, logger, notificationManager) {
2294
2737
  _base.initialize(config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
@@ -2303,48 +2746,6 @@
2303
2746
  _base.track(telemetryItem);
2304
2747
  }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
2305
2748
  };
2306
- _self.addNotificationListener = function (listener) {
2307
- var manager = _self.getNotifyMgr();
2308
- if (manager) {
2309
- manager.addNotificationListener(listener);
2310
- }
2311
- };
2312
- _self.removeNotificationListener = function (listener) {
2313
- var manager = _self.getNotifyMgr();
2314
- if (manager) {
2315
- manager.removeNotificationListener(listener);
2316
- }
2317
- };
2318
- _self.pollInternalLogs = function (eventName) {
2319
- var interval = _self.config.diagnosticLogInterval;
2320
- if (!interval || !(interval > 0)) {
2321
- interval = 10000;
2322
- }
2323
- if (_internalLogPoller) {
2324
- _self.stopPollingInternalLogs();
2325
- }
2326
- _internalLogPoller = setInterval(function () {
2327
- var queue = _self.logger ? _self.logger.queue : [];
2328
- arrForEach(queue, function (logMessage) {
2329
- var item = {
2330
- name: eventName ? eventName : "InternalMessageId: " + logMessage.messageId,
2331
- iKey: _self.config.instrumentationKey,
2332
- time: toISOString(new Date()),
2333
- baseType: _InternalLogMessage.dataType,
2334
- baseData: { message: logMessage.message }
2335
- };
2336
- _self.track(item);
2337
- });
2338
- queue.length = 0;
2339
- }, interval);
2340
- return _internalLogPoller;
2341
- };
2342
- _self.stopPollingInternalLogs = function () {
2343
- if (!_internalLogPoller)
2344
- return;
2345
- clearInterval(_internalLogPoller);
2346
- _internalLogPoller = 0;
2347
- };
2348
2749
  function _validateTelemetryItem(telemetryItem) {
2349
2750
  if (isNullOrUndefined(telemetryItem.name)) {
2350
2751
  _notifyInvalidEvent(telemetryItem);
@@ -2391,18 +2792,18 @@
2391
2792
  return 0;
2392
2793
  }
2393
2794
  function random32(signed) {
2394
- var value;
2795
+ var value = 0;
2395
2796
  var c = getCrypto() || getMsCrypto();
2396
2797
  if (c && c.getRandomValues) {
2397
2798
  value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
2398
2799
  }
2399
- else if (isIE()) {
2800
+ if (value === 0 && isIE()) {
2400
2801
  if (!_mwcSeeded) {
2401
2802
  _autoSeedMwc();
2402
2803
  }
2403
2804
  value = mwcRandom32() & MaxUInt32;
2404
2805
  }
2405
- else {
2806
+ if (value === 0) {
2406
2807
  value = Math.floor((UInt32Mask * Math.random()) | 0);
2407
2808
  }
2408
2809
  if (!signed) {
@@ -2427,6 +2828,23 @@
2427
2828
  }
2428
2829
  return value;
2429
2830
  }
2831
+ function newId(maxLength) {
2832
+ if (maxLength === void 0) { maxLength = 22; }
2833
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2834
+ var number = random32() >>> 0;
2835
+ var chars = 0;
2836
+ var result = "";
2837
+ while (result.length < maxLength) {
2838
+ chars++;
2839
+ result += base64chars.charAt(number & 0x3F);
2840
+ number >>>= 6;
2841
+ if (chars === 5) {
2842
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2843
+ chars = 0;
2844
+ }
2845
+ }
2846
+ return result;
2847
+ }
2430
2848
 
2431
2849
  var strVisibilityChangeEvt = "visibilitychange";
2432
2850
  var strPageHide = "pagehide";
@@ -2524,23 +2942,6 @@
2524
2942
  }
2525
2943
  return dateNow();
2526
2944
  }
2527
- function newId(maxLength) {
2528
- if (maxLength === void 0) { maxLength = 22; }
2529
- var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2530
- var number = random32() >>> 0;
2531
- var chars = 0;
2532
- var result = "";
2533
- while (result.length < maxLength) {
2534
- chars++;
2535
- result += base64chars.charAt(number & 0x3F);
2536
- number >>>= 6;
2537
- if (chars === 5) {
2538
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2539
- chars = 0;
2540
- }
2541
- }
2542
- return result;
2543
- }
2544
2945
  function generateW3CId() {
2545
2946
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
2546
2947
  var oct = "", tmp;
@@ -2702,6 +3103,7 @@
2702
3103
  };
2703
3104
  var hookCtx = [];
2704
3105
  var cbArgs = _createArgs([funcArgs], orgArgs);
3106
+ funcArgs.evt = getGlobalInst("event");
2705
3107
  function _createArgs(target, theArgs) {
2706
3108
  _arrLoop(theArgs, function (arg) {
2707
3109
  target.push(arg);
@@ -2840,6 +3242,7 @@
2840
3242
  exports.canUseCookies = canUseCookies;
2841
3243
  exports.createClassFromInterface = createClassFromInterface;
2842
3244
  exports.createCookieMgr = createCookieMgr;
3245
+ exports.createProcessTelemetryContext = createProcessTelemetryContext;
2843
3246
  exports.dateNow = dateNow;
2844
3247
  exports.deleteCookie = deleteCookie;
2845
3248
  exports.detachEvent = detachEvent;