@microsoft/applicationinsights-web 2.8.0-beta.2203-04 → 2.8.0-beta.2203-07

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 (50) hide show
  1. package/browser/{ai.2.8.0-beta.2203-04.cjs.js → ai.2.8.0-beta.2203-07.cjs.js} +668 -370
  2. package/browser/ai.2.8.0-beta.2203-07.cjs.js.map +1 -0
  3. package/browser/ai.2.8.0-beta.2203-07.cjs.min.js +6 -0
  4. package/browser/ai.2.8.0-beta.2203-07.cjs.min.js.map +1 -0
  5. package/browser/{ai.2.8.0-beta.2203-04.gbl.js → ai.2.8.0-beta.2203-07.gbl.js} +668 -370
  6. package/browser/ai.2.8.0-beta.2203-07.gbl.js.map +1 -0
  7. package/browser/ai.2.8.0-beta.2203-07.gbl.min.js +6 -0
  8. package/browser/ai.2.8.0-beta.2203-07.gbl.min.js.map +1 -0
  9. package/browser/ai.2.8.0-beta.2203-07.integrity.json +66 -0
  10. package/browser/{ai.2.8.0-beta.2203-04.js → ai.2.8.0-beta.2203-07.js} +668 -370
  11. package/browser/ai.2.8.0-beta.2203-07.js.map +1 -0
  12. package/browser/ai.2.8.0-beta.2203-07.min.js +6 -0
  13. package/browser/ai.2.8.0-beta.2203-07.min.js.map +1 -0
  14. package/browser/ai.2.cjs.js +667 -369
  15. package/browser/ai.2.cjs.js.map +1 -1
  16. package/browser/ai.2.cjs.min.js +2 -2
  17. package/browser/ai.2.cjs.min.js.map +1 -1
  18. package/browser/ai.2.gbl.js +667 -369
  19. package/browser/ai.2.gbl.js.map +1 -1
  20. package/browser/ai.2.gbl.min.js +2 -2
  21. package/browser/ai.2.gbl.min.js.map +1 -1
  22. package/browser/ai.2.js +667 -369
  23. package/browser/ai.2.js.map +1 -1
  24. package/browser/ai.2.min.js +2 -2
  25. package/browser/ai.2.min.js.map +1 -1
  26. package/dist/applicationinsights-web.api.json +429 -176
  27. package/dist/applicationinsights-web.api.md +20 -25
  28. package/dist/applicationinsights-web.d.ts +145 -110
  29. package/dist/applicationinsights-web.js +668 -370
  30. package/dist/applicationinsights-web.js.map +1 -1
  31. package/dist/applicationinsights-web.min.js +2 -2
  32. package/dist/applicationinsights-web.min.js.map +1 -1
  33. package/dist/applicationinsights-web.rollup.d.ts +145 -110
  34. package/dist-esm/ApplicationInsightsContainer.js +1 -1
  35. package/dist-esm/ApplicationInsightsDeprecated.js +1 -1
  36. package/dist-esm/Init.js +1 -1
  37. package/dist-esm/Initialization.js +1 -1
  38. package/dist-esm/applicationinsights-web.js +1 -1
  39. package/package.json +7 -7
  40. package/types/Initialization.d.ts +1 -1
  41. package/browser/ai.2.8.0-beta.2203-04.cjs.js.map +0 -1
  42. package/browser/ai.2.8.0-beta.2203-04.cjs.min.js +0 -6
  43. package/browser/ai.2.8.0-beta.2203-04.cjs.min.js.map +0 -1
  44. package/browser/ai.2.8.0-beta.2203-04.gbl.js.map +0 -1
  45. package/browser/ai.2.8.0-beta.2203-04.gbl.min.js +0 -6
  46. package/browser/ai.2.8.0-beta.2203-04.gbl.min.js.map +0 -1
  47. package/browser/ai.2.8.0-beta.2203-04.integrity.json +0 -66
  48. package/browser/ai.2.8.0-beta.2203-04.js.map +0 -1
  49. package/browser/ai.2.8.0-beta.2203-04.min.js +0 -6
  50. package/browser/ai.2.8.0-beta.2203-04.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Web, 2.8.0-beta.2203-04
2
+ * Application Insights JavaScript SDK - Web, 2.8.0-beta.2203-07
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  'use strict';
@@ -355,6 +355,7 @@ var strSetNextPlugin = "setNextPlugin";
355
355
  var strIsInitialized = "isInitialized";
356
356
  var strTeardown = "teardown";
357
357
  var strCore = "core";
358
+ var strUpdate = "update";
358
359
  var strDisabled = "disabled";
359
360
  var strDoTeardown = "_doTeardown";
360
361
  var strProcessNext = "processNext";
@@ -823,7 +824,7 @@ function optimizeObject(theObject) {
823
824
  }
824
825
  return theObject;
825
826
  }
826
- function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
827
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
827
828
  var theArgs = arguments;
828
829
  var extended = theArgs[0] || {};
829
830
  var argLen = theArgs.length;
@@ -1270,6 +1271,10 @@ var DiagnosticLogger = /** @class */ (function () {
1270
1271
  }
1271
1272
  return DiagnosticLogger;
1272
1273
  }());
1274
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1275
+ if (isUserAct === void 0) { isUserAct = false; }
1276
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1277
+ }
1273
1278
 
1274
1279
  var strExecutionContextKey = "ctx";
1275
1280
  var _defaultPerfManager = null;
@@ -1694,7 +1699,7 @@ function _createInternalContext(telemetryChain, config, core, startAt) {
1694
1699
  completeDetails.func.call(completeDetails.self, completeDetails.args);
1695
1700
  }
1696
1701
  catch (e) {
1697
- core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1702
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1698
1703
  }
1699
1704
  });
1700
1705
  _onComplete = [];
@@ -1793,6 +1798,27 @@ function createProcessTelemetryUnloadContext(telemetryChain, config, core, start
1793
1798
  context.createNew = _createNew;
1794
1799
  return context;
1795
1800
  }
1801
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1802
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1803
+ var context = internalContext.ctx;
1804
+ function _processNext(updateState) {
1805
+ return context.iterate(function (plugin) {
1806
+ if (isFunction(plugin[strUpdate])) {
1807
+ plugin[strUpdate](context, updateState);
1808
+ }
1809
+ });
1810
+ }
1811
+ function _createNew(plugins, startAt) {
1812
+ if (plugins === void 0) { plugins = null; }
1813
+ if (isArray(plugins)) {
1814
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1815
+ }
1816
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1817
+ }
1818
+ context.processNext = _processNext;
1819
+ context.createNew = _createNew;
1820
+ return context;
1821
+ }
1796
1822
  function createTelemetryProxyChain(plugins, config, core, startAt) {
1797
1823
  var firstProxy = null;
1798
1824
  var add = startAt ? false : true;
@@ -1839,6 +1865,7 @@ function createTelemetryPluginProxy(plugin, config, core) {
1839
1865
  },
1840
1866
  processTelemetry: _processTelemetry,
1841
1867
  unload: _unloadPlugin,
1868
+ update: _updatePlugin,
1842
1869
  _id: chainId,
1843
1870
  _setNext: function (nextPlugin) {
1844
1871
  nextProxy = nextPlugin;
@@ -1878,7 +1905,7 @@ function createTelemetryPluginProxy(plugin, config, core) {
1878
1905
  hasRun = true;
1879
1906
  }
1880
1907
  if (!nextProxy || !hasNextRun) {
1881
- itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1908
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1882
1909
  }
1883
1910
  }
1884
1911
  }, details, isAsync);
@@ -1926,6 +1953,24 @@ function createTelemetryPluginProxy(plugin, config, core) {
1926
1953
  unloadCtx.processNext(unloadState);
1927
1954
  }
1928
1955
  }
1956
+ function _updatePlugin(updateCtx, updateState) {
1957
+ function _callUpdate() {
1958
+ var hasRun = false;
1959
+ if (plugin) {
1960
+ var pluginState = _getPluginState(plugin);
1961
+ var pluginCore = plugin[strCore] || pluginState.core;
1962
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1963
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1964
+ hasRun = true;
1965
+ }
1966
+ }
1967
+ }
1968
+ return hasRun;
1969
+ }
1970
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1971
+ updateCtx.processNext(updateState);
1972
+ }
1973
+ }
1929
1974
  return objFreeze(proxyChain);
1930
1975
  }
1931
1976
 
@@ -2095,7 +2140,7 @@ function areCookiesSupported(logger) {
2095
2140
  _supportsCookies = doc[strCookie] !== undefined;
2096
2141
  }
2097
2142
  catch (e) {
2098
- logger && logger.throwInternal(2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2143
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2099
2144
  }
2100
2145
  }
2101
2146
  return _supportsCookies;
@@ -2224,6 +2269,17 @@ function createChannelControllerPlugin(channelQueue, core) {
2224
2269
  }
2225
2270
  _runChainOnComplete();
2226
2271
  }
2272
+ function _doUpdate(updateCtx, updateState) {
2273
+ var theUpdateState = updateState || {
2274
+ reason: 0
2275
+ };
2276
+ _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2277
+ chainCtx[strProcessNext](theUpdateState);
2278
+ }, function () {
2279
+ updateCtx[strProcessNext](theUpdateState);
2280
+ });
2281
+ return true;
2282
+ }
2227
2283
  function _doTeardown(unloadCtx, unloadState) {
2228
2284
  var theUnloadState = unloadState || {
2229
2285
  reason: 0 ,
@@ -2275,7 +2331,8 @@ function createChannelControllerPlugin(channelQueue, core) {
2275
2331
  }, function () {
2276
2332
  itemCtx[strProcessNext](item);
2277
2333
  });
2278
- }
2334
+ },
2335
+ update: _doUpdate
2279
2336
  },
2280
2337
  _a[strPause] = function () {
2281
2338
  _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
@@ -2336,6 +2393,7 @@ function createChannelControllerPlugin(channelQueue, core) {
2336
2393
  doneIterating = true;
2337
2394
  doCallback();
2338
2395
  });
2396
+ return true;
2339
2397
  },
2340
2398
  _a._setQueue = function (queue) {
2341
2399
  channelQueue = queue;
@@ -2373,7 +2431,7 @@ function createUnloadHandlerContainer() {
2373
2431
  handler(unloadCtx, unloadState);
2374
2432
  }
2375
2433
  catch (e) {
2376
- unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2434
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2377
2435
  }
2378
2436
  });
2379
2437
  handlers = [];
@@ -2432,6 +2490,30 @@ var BaseTelemetryPlugin = /** @class */ (function () {
2432
2490
  }
2433
2491
  return result;
2434
2492
  };
2493
+ _self.update = function (updateCtx, updateState) {
2494
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
2495
+ return;
2496
+ }
2497
+ var result;
2498
+ var updateDone = false;
2499
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2500
+ var theUpdateState = updateState || {
2501
+ reason: 0
2502
+ };
2503
+ function _updateCallback() {
2504
+ if (!updateDone) {
2505
+ updateDone = true;
2506
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2507
+ }
2508
+ }
2509
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2510
+ _updateCallback();
2511
+ }
2512
+ else {
2513
+ result = true;
2514
+ }
2515
+ return result;
2516
+ };
2435
2517
  _self._addHook = function (hooks) {
2436
2518
  if (hooks) {
2437
2519
  if (isArray(hooks)) {
@@ -2546,7 +2628,7 @@ var TelemetryInitializerPlugin = /** @class */ (function (_super) {
2546
2628
  }
2547
2629
  }
2548
2630
  catch (e) {
2549
- itemCtx.diagLog().throwInternal(1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2631
+ _throwInternal(itemCtx.diagLog(), 1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2550
2632
  }
2551
2633
  }
2552
2634
  }
@@ -2667,8 +2749,8 @@ var BaseCore = /** @class */ (function () {
2667
2749
  _configExtensions = [];
2668
2750
  _configExtensions.push.apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2669
2751
  _channelConfig = (config || {}).channels;
2670
- _initPluginChain(config);
2671
- if (_self.getTransmissionControls().length === 0) {
2752
+ _initPluginChain(config, null);
2753
+ if (!_channelQueue || _channelQueue.length === 0) {
2672
2754
  throwError("No channels available");
2673
2755
  }
2674
2756
  _isInitialized = true;
@@ -2789,16 +2871,12 @@ var BaseCore = /** @class */ (function () {
2789
2871
  _self.stopPollingInternalLogs();
2790
2872
  processUnloadCtx.processNext(unloadState);
2791
2873
  }
2792
- if (_channelControl) {
2793
- _channelControl.flush(isAsync, _doUnload, 6 , cbTimeout);
2794
- }
2795
- else {
2796
- _doUnload(true);
2874
+ if (!_flushChannels(isAsync, _doUnload, 6 , cbTimeout)) {
2875
+ _doUnload(false);
2797
2876
  }
2798
2877
  };
2799
2878
  _self.getPlugin = _getPlugin;
2800
2879
  _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
2801
- if (isAsync === void 0) { isAsync = true; }
2802
2880
  if (!plugin) {
2803
2881
  addCb && addCb(false);
2804
2882
  _logOrThrowError(strValidationError);
@@ -2810,22 +2888,28 @@ var BaseCore = /** @class */ (function () {
2810
2888
  _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2811
2889
  return;
2812
2890
  }
2891
+ var updateState = {
2892
+ reason: 16
2893
+ };
2813
2894
  function _addPlugin(removed) {
2814
2895
  _configExtensions.push(plugin);
2815
- _initPluginChain(_self.config);
2896
+ updateState.added = [plugin];
2897
+ _initPluginChain(_self.config, updateState);
2816
2898
  addCb && addCb(true);
2817
2899
  }
2818
2900
  if (existingPlugin) {
2819
- var removedPlugins = [existingPlugin.plugin];
2901
+ var removedPlugins_1 = [existingPlugin.plugin];
2820
2902
  var unloadState = {
2821
2903
  reason: 2 ,
2822
2904
  isAsync: isAsync
2823
2905
  };
2824
- _removePlugins(removedPlugins, unloadState, function (removed) {
2906
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
2825
2907
  if (!removed) {
2826
2908
  addCb && addCb(false);
2827
2909
  }
2828
2910
  else {
2911
+ updateState.removed = removedPlugins_1;
2912
+ updateState.reason |= 32 ;
2829
2913
  _addPlugin();
2830
2914
  }
2831
2915
  });
@@ -2837,6 +2921,7 @@ var BaseCore = /** @class */ (function () {
2837
2921
  _self.evtNamespace = function () {
2838
2922
  return _evtNamespace;
2839
2923
  };
2924
+ _self.flush = _flushChannels;
2840
2925
  proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2841
2926
  function _initDefaults() {
2842
2927
  _isInitialized = false;
@@ -2863,7 +2948,7 @@ var BaseCore = /** @class */ (function () {
2863
2948
  function _createTelCtx() {
2864
2949
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2865
2950
  }
2866
- function _initPluginChain(config) {
2951
+ function _initPluginChain(config, updateState) {
2867
2952
  var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
2868
2953
  _coreExtensions = theExtensions.core;
2869
2954
  _pluginChain = null;
@@ -2889,6 +2974,9 @@ var BaseCore = /** @class */ (function () {
2889
2974
  _channelControl.initialize(config, _self, allExtensions);
2890
2975
  initializePlugins(_createTelCtx(), allExtensions);
2891
2976
  _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2977
+ if (updateState) {
2978
+ _doUpdate(updateState);
2979
+ }
2892
2980
  }
2893
2981
  function _getPlugin(pluginIdentifier) {
2894
2982
  var theExt = null;
@@ -2921,7 +3009,10 @@ var BaseCore = /** @class */ (function () {
2921
3009
  };
2922
3010
  _removePlugins(pluginsToRemove, unloadState, function (removed) {
2923
3011
  if (removed) {
2924
- _initPluginChain(_self.config);
3012
+ _initPluginChain(_self.config, {
3013
+ reason: 32 ,
3014
+ removed: pluginsToRemove
3015
+ });
2925
3016
  }
2926
3017
  removeCb && removeCb(removed);
2927
3018
  });
@@ -2996,6 +3087,13 @@ var BaseCore = /** @class */ (function () {
2996
3087
  queue.length = 0;
2997
3088
  }
2998
3089
  }
3090
+ function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
3091
+ if (_channelControl) {
3092
+ return _channelControl.flush(isAsync, callBack, sendReason || 6 , cbTimeout);
3093
+ }
3094
+ callBack && callBack(false);
3095
+ return true;
3096
+ }
2999
3097
  function _initDebugListener(config) {
3000
3098
  if (config.disableDbgExt === true && _debugListener) {
3001
3099
  _notificationManager[strRemoveNotificationListener](_debugListener);
@@ -3018,10 +3116,16 @@ var BaseCore = /** @class */ (function () {
3018
3116
  var extConfig = getSetValue(config, strExtensionConfig);
3019
3117
  extConfig.NotificationManager = _notificationManager;
3020
3118
  }
3119
+ function _doUpdate(updateState) {
3120
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
3121
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3122
+ updateCtx.processNext(updateState);
3123
+ }
3124
+ }
3021
3125
  function _logOrThrowError(message) {
3022
3126
  var logger = _self.logger;
3023
3127
  if (logger) {
3024
- logger.throwInternal(2 , 73 , message);
3128
+ _throwInternal(logger, 2 , 73 , message);
3025
3129
  }
3026
3130
  else {
3027
3131
  throwError(message);
@@ -3136,6 +3240,8 @@ var AppInsightsCore = /** @class */ (function (_super) {
3136
3240
  var strOnPrefix = "on";
3137
3241
  var strAttachEvent = "attachEvent";
3138
3242
  var strAddEventHelper = "addEventListener";
3243
+ var strDetachEvent = "detachEvent";
3244
+ var strRemoveEventListener = "removeEventListener";
3139
3245
  var strEvents = "events";
3140
3246
  var strVisibilityChangeEvt = "visibilitychange";
3141
3247
  var strPageHide = "pagehide";
@@ -3152,12 +3258,12 @@ function _normalizeNamespace(name) {
3152
3258
  }
3153
3259
  return name;
3154
3260
  }
3155
- function _getEvtNamespace(eventName, namespaces) {
3156
- if (namespaces) {
3261
+ function _getEvtNamespace(eventName, evtNamespace) {
3262
+ if (evtNamespace) {
3157
3263
  var theNamespace_1 = "";
3158
- if (isArray(namespaces)) {
3264
+ if (isArray(evtNamespace)) {
3159
3265
  theNamespace_1 = "";
3160
- arrForEach(namespaces, function (name) {
3266
+ arrForEach(evtNamespace, function (name) {
3161
3267
  name = _normalizeNamespace(name);
3162
3268
  if (name) {
3163
3269
  if (name[0] !== ".") {
@@ -3168,7 +3274,7 @@ function _getEvtNamespace(eventName, namespaces) {
3168
3274
  });
3169
3275
  }
3170
3276
  else {
3171
- theNamespace_1 = _normalizeNamespace(namespaces);
3277
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
3172
3278
  }
3173
3279
  if (theNamespace_1) {
3174
3280
  if (theNamespace_1[0] !== ".") {
@@ -3192,6 +3298,16 @@ function _getRegisteredEvents(target, evtName, addDefault) {
3192
3298
  }
3193
3299
  return registeredEvents;
3194
3300
  }
3301
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
3302
+ if (obj && evtName && evtName.type) {
3303
+ if (obj[strRemoveEventListener]) {
3304
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3305
+ }
3306
+ else if (obj[strDetachEvent]) {
3307
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3308
+ }
3309
+ }
3310
+ }
3195
3311
  function _doAttach(obj, evtName, handlerRef, useCapture) {
3196
3312
  var result = false;
3197
3313
  if (obj && evtName && evtName.type && handlerRef) {
@@ -3206,6 +3322,34 @@ function _doAttach(obj, evtName, handlerRef, useCapture) {
3206
3322
  }
3207
3323
  return result;
3208
3324
  }
3325
+ function _doUnregister(target, events, evtName, unRegFn) {
3326
+ var idx = events.length;
3327
+ while (idx--) {
3328
+ var theEvent = events[idx];
3329
+ if (theEvent) {
3330
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3331
+ if (!unRegFn || unRegFn(theEvent)) {
3332
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3333
+ events.splice(idx, 1);
3334
+ }
3335
+ }
3336
+ }
3337
+ }
3338
+ }
3339
+ function _unregisterEvents(target, evtName, unRegFn) {
3340
+ if (evtName.type) {
3341
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
3342
+ }
3343
+ else {
3344
+ var eventCache = elmNodeData.get(target, strEvents, {});
3345
+ objForEachKey(eventCache, function (evtType, events) {
3346
+ _doUnregister(target, events, evtName, unRegFn);
3347
+ });
3348
+ if (objKeys(eventCache).length === 0) {
3349
+ elmNodeData.kill(target, strEvents);
3350
+ }
3351
+ }
3352
+ }
3209
3353
  function mergeEvtNamespace(theNamespace, namespaces) {
3210
3354
  var newNamespaces;
3211
3355
  if (namespaces) {
@@ -3243,6 +3387,27 @@ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3243
3387
  }
3244
3388
  return result;
3245
3389
  }
3390
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3391
+ if (useCapture === void 0) { useCapture = false; }
3392
+ if (target) {
3393
+ try {
3394
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3395
+ var found_1 = false;
3396
+ _unregisterEvents(target, evtName_1, function (regEvent) {
3397
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3398
+ found_1 = true;
3399
+ return true;
3400
+ }
3401
+ return false;
3402
+ });
3403
+ if (!found_1) {
3404
+ _doDetach(target, evtName_1, handlerRef, useCapture);
3405
+ }
3406
+ }
3407
+ catch (e) {
3408
+ }
3409
+ }
3410
+ }
3246
3411
  function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3247
3412
  if (useCapture === void 0) { useCapture = false; }
3248
3413
  return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
@@ -3683,7 +3848,7 @@ function dataSanitizeKey(logger, name) {
3683
3848
  name = strTrim(name.toString());
3684
3849
  if (name.length > 150 ) {
3685
3850
  nameTrunc = name.substring(0, 150 );
3686
- logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3851
+ _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3687
3852
  }
3688
3853
  }
3689
3854
  return nameTrunc || name;
@@ -3696,7 +3861,7 @@ function dataSanitizeString(logger, value, maxLength) {
3696
3861
  value = strTrim(value);
3697
3862
  if (value.toString().length > maxLength) {
3698
3863
  valueTrunc = value.toString().substring(0, maxLength);
3699
- logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3864
+ _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3700
3865
  }
3701
3866
  }
3702
3867
  return valueTrunc || value;
@@ -3709,7 +3874,7 @@ function dataSanitizeMessage(logger, message) {
3709
3874
  if (message) {
3710
3875
  if (message.length > 32768 ) {
3711
3876
  messageTrunc = message.substring(0, 32768 );
3712
- logger && logger.throwInternal(2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3877
+ _throwInternal(logger, 2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3713
3878
  }
3714
3879
  }
3715
3880
  return messageTrunc || message;
@@ -3720,7 +3885,7 @@ function dataSanitizeException(logger, exception) {
3720
3885
  var value = "" + exception;
3721
3886
  if (value.length > 32768 ) {
3722
3887
  exceptionTrunc = value.substring(0, 32768 );
3723
- logger && logger.throwInternal(2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3888
+ _throwInternal(logger, 2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3724
3889
  }
3725
3890
  }
3726
3891
  return exceptionTrunc || exception;
@@ -3734,7 +3899,7 @@ function dataSanitizeProperties(logger, properties) {
3734
3899
  value = getJSON().stringify(value);
3735
3900
  }
3736
3901
  catch (e) {
3737
- logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3902
+ _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3738
3903
  }
3739
3904
  }
3740
3905
  value = dataSanitizeString(logger, value, 8192 );
@@ -3765,7 +3930,7 @@ function dataSanitizeInput(logger, input, maxLength, _msgId) {
3765
3930
  input = strTrim(input);
3766
3931
  if (input.length > maxLength) {
3767
3932
  inputTrunc = input.substring(0, maxLength);
3768
- logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3933
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3769
3934
  }
3770
3935
  }
3771
3936
  return inputTrunc || input;
@@ -3903,8 +4068,12 @@ function utlDisableStorage() {
3903
4068
  _canUseLocalStorage = false;
3904
4069
  _canUseSessionStorage = false;
3905
4070
  }
3906
- function utlCanUseLocalStorage() {
3907
- if (_canUseLocalStorage === undefined) {
4071
+ function utlEnableStorage() {
4072
+ _canUseLocalStorage = utlCanUseLocalStorage(true);
4073
+ _canUseSessionStorage = utlCanUseSessionStorage(true);
4074
+ }
4075
+ function utlCanUseLocalStorage(reset) {
4076
+ if (reset || _canUseLocalStorage === undefined) {
3908
4077
  _canUseLocalStorage = !!_getVerifiedStorageObject(StorageType.LocalStorage);
3909
4078
  }
3910
4079
  return _canUseLocalStorage;
@@ -3917,7 +4086,7 @@ function utlGetLocalStorage(logger, name) {
3917
4086
  }
3918
4087
  catch (e) {
3919
4088
  _canUseLocalStorage = false;
3920
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
4089
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3921
4090
  }
3922
4091
  }
3923
4092
  return null;
@@ -3931,7 +4100,7 @@ function utlSetLocalStorage(logger, name, data) {
3931
4100
  }
3932
4101
  catch (e) {
3933
4102
  _canUseLocalStorage = false;
3934
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
4103
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3935
4104
  }
3936
4105
  }
3937
4106
  return false;
@@ -3945,13 +4114,13 @@ function utlRemoveStorage(logger, name) {
3945
4114
  }
3946
4115
  catch (e) {
3947
4116
  _canUseLocalStorage = false;
3948
- logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4117
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
3949
4118
  }
3950
4119
  }
3951
4120
  return false;
3952
4121
  }
3953
- function utlCanUseSessionStorage() {
3954
- if (_canUseSessionStorage === undefined) {
4122
+ function utlCanUseSessionStorage(reset) {
4123
+ if (reset || _canUseSessionStorage === undefined) {
3955
4124
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
3956
4125
  }
3957
4126
  return _canUseSessionStorage;
@@ -3973,7 +4142,7 @@ function utlGetSessionStorage(logger, name) {
3973
4142
  }
3974
4143
  catch (e) {
3975
4144
  _canUseSessionStorage = false;
3976
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
4145
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3977
4146
  }
3978
4147
  }
3979
4148
  return null;
@@ -3987,7 +4156,7 @@ function utlSetSessionStorage(logger, name, data) {
3987
4156
  }
3988
4157
  catch (e) {
3989
4158
  _canUseSessionStorage = false;
3990
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
4159
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3991
4160
  }
3992
4161
  }
3993
4162
  return false;
@@ -4001,7 +4170,7 @@ function utlRemoveSessionStorage(logger, name) {
4001
4170
  }
4002
4171
  catch (e) {
4003
4172
  _canUseSessionStorage = false;
4004
- logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4173
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4005
4174
  }
4006
4175
  }
4007
4176
  return false;
@@ -5425,11 +5594,9 @@ var PageViewManager = /** @class */ (function () {
5425
5594
  if (core) {
5426
5595
  _logger = core.logger;
5427
5596
  }
5428
- function _flushChannels() {
5597
+ function _flushChannels(isAsync) {
5429
5598
  if (core) {
5430
- arrForEach(core.getTransmissionControls(), function (queues) {
5431
- arrForEach(queues, function (q) { q.flush(true); });
5432
- });
5599
+ core.flush(isAsync);
5433
5600
  }
5434
5601
  }
5435
5602
  function _addQueue(cb) {
@@ -5452,7 +5619,7 @@ var PageViewManager = /** @class */ (function () {
5452
5619
  intervalHandle = null;
5453
5620
  }
5454
5621
  if (doFlush) {
5455
- _flushChannels();
5622
+ _flushChannels(true);
5456
5623
  }
5457
5624
  }), 100);
5458
5625
  }
@@ -5470,7 +5637,7 @@ var PageViewManager = /** @class */ (function () {
5470
5637
  }
5471
5638
  if (!pageViewPerformanceManager.isPerformanceTimingSupported()) {
5472
5639
  appInsights.sendPageViewInternal(pageView, customProperties);
5473
- _flushChannels();
5640
+ _flushChannels(true);
5474
5641
  _logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NavigationTimingNotSupported, "trackPageView: navigation timing API used for calculation of page duration is not supported in this browser. This page view will be collected without duration and timing info.");
5475
5642
  return;
5476
5643
  }
@@ -5496,7 +5663,7 @@ var PageViewManager = /** @class */ (function () {
5496
5663
  customProperties["duration"] = customDuration;
5497
5664
  }
5498
5665
  appInsights.sendPageViewInternal(pageView, customProperties);
5499
- _flushChannels();
5666
+ _flushChannels(true);
5500
5667
  pageViewSent = true;
5501
5668
  }
5502
5669
  var maxDurationLimit = 60000;
@@ -5542,6 +5709,17 @@ var PageViewManager = /** @class */ (function () {
5542
5709
  return processed;
5543
5710
  });
5544
5711
  };
5712
+ _self.teardown = function (unloadCtx, unloadState) {
5713
+ if (intervalHandle) {
5714
+ clearInterval(intervalHandle);
5715
+ intervalHandle = null;
5716
+ var allItems = itemQueue.slice(0);
5717
+ itemQueue = [];
5718
+ arrForEach(allItems, function (item) {
5719
+ if (item()) ;
5720
+ });
5721
+ }
5722
+ };
5545
5723
  });
5546
5724
  }
5547
5725
  return PageViewManager;
@@ -5736,6 +5914,33 @@ var PageViewPerformanceManager = /** @class */ (function () {
5736
5914
  return PageViewPerformanceManager;
5737
5915
  }());
5738
5916
 
5917
+ var Timing = /** @class */ (function () {
5918
+ function Timing(logger, name) {
5919
+ var _self = this;
5920
+ var _events = {};
5921
+ _self.start = function (name) {
5922
+ if (typeof _events[name] !== "undefined") {
5923
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
5924
+ }
5925
+ _events[name] = +new Date;
5926
+ };
5927
+ _self.stop = function (name, url, properties, measurements) {
5928
+ var start = _events[name];
5929
+ if (isNaN(start)) {
5930
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
5931
+ }
5932
+ else {
5933
+ var end = +new Date;
5934
+ var duration = dateTimeUtilsDuration(start, end);
5935
+ _self.action(name, url, duration, properties, measurements);
5936
+ }
5937
+ delete _events[name];
5938
+ _events[name] = undefined;
5939
+ };
5940
+ }
5941
+ return Timing;
5942
+ }());
5943
+
5739
5944
  var durationProperty = "duration";
5740
5945
  var strEvent = "event";
5741
5946
  function _dispatchEvent(target, evnt) {
@@ -5753,47 +5958,78 @@ function _getReason(error) {
5753
5958
  }
5754
5959
  return error || "";
5755
5960
  }
5756
- var ApplicationInsights = /** @class */ (function (_super) {
5757
- __extendsFn(ApplicationInsights, _super);
5758
- function ApplicationInsights() {
5961
+ var MinMilliSeconds = 60000;
5962
+ function _configMilliseconds(value, defValue) {
5963
+ value = value || defValue;
5964
+ if (value < MinMilliSeconds) {
5965
+ value = MinMilliSeconds;
5966
+ }
5967
+ return value;
5968
+ }
5969
+ function _getDefaultConfig(config) {
5970
+ if (!config) {
5971
+ config = {};
5972
+ }
5973
+ config.sessionRenewalMs = _configMilliseconds(config.sessionRenewalMs, 30 * 60 * 1000);
5974
+ config.sessionExpirationMs = _configMilliseconds(config.sessionExpirationMs, 24 * 60 * 60 * 1000);
5975
+ config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
5976
+ config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
5977
+ config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
5978
+ config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
5979
+ if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
5980
+ config.samplingPercentage = 100;
5981
+ }
5982
+ config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
5983
+ config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
5984
+ config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
5985
+ config.namePrefix = config.namePrefix || "";
5986
+ config.enableDebug = stringToBoolOrDefault(config.enableDebug);
5987
+ config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
5988
+ config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
5989
+ return config;
5990
+ }
5991
+ function _updateStorageUsage(extConfig) {
5992
+ if (!isUndefined(extConfig.isStorageUseDisabled)) {
5993
+ if (extConfig.isStorageUseDisabled) {
5994
+ utlDisableStorage();
5995
+ }
5996
+ else {
5997
+ utlEnableStorage();
5998
+ }
5999
+ }
6000
+ }
6001
+ var AnalyticsPlugin = /** @class */ (function (_super) {
6002
+ __extendsFn(AnalyticsPlugin, _super);
6003
+ function AnalyticsPlugin() {
5759
6004
  var _this = _super.call(this) || this;
5760
6005
  _this.identifier = AnalyticsPluginIdentifier;
5761
6006
  _this.priority = 180;
5762
6007
  _this.autoRoutePVDelay = 500;
5763
6008
  var _eventTracking;
5764
6009
  var _pageTracking;
5765
- var _properties;
6010
+ var _pageViewManager;
6011
+ var _pageViewPerformanceManager;
6012
+ var _pageVisitTimeManager;
6013
+ var _preInitTelemetryInitializers;
6014
+ var _isBrowserLinkTrackingEnabled;
6015
+ var _browserLinkInitializerAdded;
6016
+ var _enableAutoRouteTracking;
6017
+ var _historyListenerAdded;
6018
+ var _disableExceptionTracking;
6019
+ var _autoExceptionInstrumented;
6020
+ var _enableUnhandledPromiseRejectionTracking;
6021
+ var _autoUnhandledPromiseInstrumented;
5766
6022
  var _prevUri;
5767
6023
  var _currUri;
5768
- dynamicProto(ApplicationInsights, _this, function (_self, _base) {
5769
- var location = getLocation(true);
5770
- _prevUri = location && location.href || "";
6024
+ var _evtNamespace;
6025
+ dynamicProto(AnalyticsPlugin, _this, function (_self, _base) {
6026
+ var _addHook = _base._addHook;
6027
+ _initDefaults();
5771
6028
  _self.getCookieMgr = function () {
5772
6029
  return safeGetCookieMgr(_self.core);
5773
6030
  };
5774
6031
  _self.processTelemetry = function (env, itemCtx) {
5775
- doPerf(_self.core, function () { return _self.identifier + ":processTelemetry"; }, function () {
5776
- var doNotSendItem = false;
5777
- var telemetryInitializersCount = _self._telemetryInitializers.length;
5778
- itemCtx = _self._getTelCtx(itemCtx);
5779
- for (var i = 0; i < telemetryInitializersCount; ++i) {
5780
- var telemetryInitializer = _self._telemetryInitializers[i];
5781
- if (telemetryInitializer) {
5782
- try {
5783
- if (telemetryInitializer.apply(null, [env]) === false) {
5784
- doNotSendItem = true;
5785
- break;
5786
- }
5787
- }
5788
- catch (e) {
5789
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
5790
- }
5791
- }
5792
- }
5793
- if (!doNotSendItem) {
5794
- _self.processNext(env, itemCtx);
5795
- }
5796
- }, function () { return ({ item: env }); }, !(env.sync));
6032
+ _self.processNext(env, itemCtx);
5797
6033
  };
5798
6034
  _self.trackEvent = function (event, customProperties) {
5799
6035
  try {
@@ -5801,7 +6037,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5801
6037
  _self.core.track(telemetryItem);
5802
6038
  }
5803
6039
  catch (e) {
5804
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6040
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5805
6041
  }
5806
6042
  };
5807
6043
  _self.startTrackEvent = function (name) {
@@ -5809,7 +6045,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5809
6045
  _eventTracking.start(name);
5810
6046
  }
5811
6047
  catch (e) {
5812
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6048
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5813
6049
  }
5814
6050
  };
5815
6051
  _self.stopTrackEvent = function (name, properties, measurements) {
@@ -5817,7 +6053,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5817
6053
  _eventTracking.stop(name, undefined, properties);
5818
6054
  }
5819
6055
  catch (e) {
5820
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6056
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5821
6057
  }
5822
6058
  };
5823
6059
  _self.trackTrace = function (trace, customProperties) {
@@ -5826,7 +6062,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5826
6062
  _self.core.track(telemetryItem);
5827
6063
  }
5828
6064
  catch (e) {
5829
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6065
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5830
6066
  }
5831
6067
  };
5832
6068
  _self.trackMetric = function (metric, customProperties) {
@@ -5835,19 +6071,19 @@ var ApplicationInsights = /** @class */ (function (_super) {
5835
6071
  _self.core.track(telemetryItem);
5836
6072
  }
5837
6073
  catch (e) {
5838
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6074
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5839
6075
  }
5840
6076
  };
5841
6077
  _self.trackPageView = function (pageView, customProperties) {
5842
6078
  try {
5843
6079
  var inPv = pageView || {};
5844
- _self._pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
6080
+ _pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
5845
6081
  if (_self.config.autoTrackPageVisitTime) {
5846
- _self._pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
6082
+ _pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
5847
6083
  }
5848
6084
  }
5849
6085
  catch (e) {
5850
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6086
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5851
6087
  }
5852
6088
  };
5853
6089
  _self.sendPageViewInternal = function (pageView, properties, systemProperties) {
@@ -5863,12 +6099,13 @@ var ApplicationInsights = /** @class */ (function (_super) {
5863
6099
  _self.core.track(telemetryItem);
5864
6100
  };
5865
6101
  _self.trackPageViewPerformance = function (pageViewPerformance, customProperties) {
6102
+ var inPvp = pageViewPerformance || {};
5866
6103
  try {
5867
- _self._pageViewPerformanceManager.populatePageViewPerformanceEvent(pageViewPerformance);
5868
- _self.sendPageViewPerformanceInternal(pageViewPerformance, customProperties);
6104
+ _pageViewPerformanceManager.populatePageViewPerformanceEvent(inPvp);
6105
+ _self.sendPageViewPerformanceInternal(inPvp, customProperties);
5869
6106
  }
5870
6107
  catch (e) {
5871
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6108
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5872
6109
  }
5873
6110
  };
5874
6111
  _self.startTrackPage = function (name) {
@@ -5880,7 +6117,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5880
6117
  _pageTracking.start(name);
5881
6118
  }
5882
6119
  catch (e) {
5883
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6120
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5884
6121
  }
5885
6122
  };
5886
6123
  _self.stopTrackPage = function (name, url, properties, measurement) {
@@ -5895,11 +6132,11 @@ var ApplicationInsights = /** @class */ (function (_super) {
5895
6132
  }
5896
6133
  _pageTracking.stop(name, url, properties, measurement);
5897
6134
  if (_self.config.autoTrackPageVisitTime) {
5898
- _self._pageVisitTimeManager.trackPreviousPageVisit(name, url);
6135
+ _pageVisitTimeManager.trackPreviousPageVisit(name, url);
5899
6136
  }
5900
6137
  }
5901
6138
  catch (e) {
5902
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6139
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5903
6140
  }
5904
6141
  };
5905
6142
  _self.sendExceptionInternal = function (exception, customProperties, systemProperties) {
@@ -5909,11 +6146,14 @@ var ApplicationInsights = /** @class */ (function (_super) {
5909
6146
  _self.core.track(telemetryItem);
5910
6147
  };
5911
6148
  _self.trackException = function (exception, customProperties) {
6149
+ if (exception && !exception.exception && exception.error) {
6150
+ exception.exception = exception.error;
6151
+ }
5912
6152
  try {
5913
6153
  _self.sendExceptionInternal(exception, customProperties);
5914
6154
  }
5915
6155
  catch (e) {
5916
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6156
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5917
6157
  }
5918
6158
  };
5919
6159
  _self._onerror = function (exception) {
@@ -5947,158 +6187,98 @@ var ApplicationInsights = /** @class */ (function (_super) {
5947
6187
  }
5948
6188
  catch (e) {
5949
6189
  var errorString = error ? (error.name + ", " + error.message) : "null";
5950
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
6190
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
5951
6191
  + getExceptionName(e), { exception: dumpObj(e), errorString: errorString });
5952
6192
  }
5953
6193
  };
5954
6194
  _self.addTelemetryInitializer = function (telemetryInitializer) {
5955
- _self._telemetryInitializers.push(telemetryInitializer);
6195
+ if (_self.core) {
6196
+ return _self.core.addTelemetryInitializer(telemetryInitializer);
6197
+ }
6198
+ if (!_preInitTelemetryInitializers) {
6199
+ _preInitTelemetryInitializers = [];
6200
+ }
6201
+ _preInitTelemetryInitializers.push(telemetryInitializer);
5956
6202
  };
5957
6203
  _self.initialize = function (config, core, extensions, pluginChain) {
5958
6204
  if (_self.isInitialized()) {
5959
6205
  return;
5960
6206
  }
5961
6207
  if (isNullOrUndefined(core)) {
5962
- throw Error("Error initializing");
6208
+ throwError("Error initializing");
5963
6209
  }
5964
6210
  _base.initialize(config, core, extensions, pluginChain);
5965
- _self.setInitialized(false);
5966
- var ctx = _self._getTelCtx();
5967
- var identifier = _self.identifier;
5968
- _self.config = ctx.getExtCfg(identifier);
5969
- var defaults = ApplicationInsights.getDefaultConfig(config);
5970
- if (defaults !== undefined) {
5971
- objForEachKey(defaults, function (field, value) {
5972
- _self.config[field] = ctx.getConfig(identifier, field, value);
5973
- if (_self.config[field] === undefined) {
5974
- _self.config[field] = value;
5975
- }
5976
- });
5977
- }
5978
- if (_self.config.isStorageUseDisabled) {
5979
- utlDisableStorage();
5980
- }
5981
- var configGetters = {
5982
- instrumentationKey: function () { return config.instrumentationKey; },
5983
- accountId: function () { return _self.config.accountId || config.accountId; },
5984
- sessionRenewalMs: function () { return _self.config.sessionRenewalMs || config.sessionRenewalMs; },
5985
- sessionExpirationMs: function () { return _self.config.sessionExpirationMs || config.sessionExpirationMs; },
5986
- sampleRate: function () { return _self.config.samplingPercentage || config.samplingPercentage; },
5987
- sdkExtension: function () { return _self.config.sdkExtension || config.sdkExtension; },
5988
- isBrowserLinkTrackingEnabled: function () { return _self.config.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled; },
5989
- appId: function () { return _self.config.appId || config.appId; }
5990
- };
5991
- _self._pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
5992
- _self._pageViewManager = new PageViewManager(_this, _self.config.overridePageViewDuration, _self.core, _self._pageViewPerformanceManager);
5993
- _self._pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
5994
- _self._telemetryInitializers = _self._telemetryInitializers || [];
5995
- _addDefaultTelemetryInitializers(configGetters);
5996
- _eventTracking = new Timing(_self.diagLog(), "trackEvent");
5997
- _eventTracking.action =
5998
- function (name, url, duration, properties) {
5999
- if (!properties) {
6211
+ try {
6212
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
6213
+ if (_preInitTelemetryInitializers) {
6214
+ arrForEach(_preInitTelemetryInitializers, function (initializer) {
6215
+ core.addTelemetryInitializer(initializer);
6216
+ });
6217
+ _preInitTelemetryInitializers = null;
6218
+ }
6219
+ var extConfig = _populateDefaults(config);
6220
+ _updateStorageUsage(extConfig);
6221
+ _pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
6222
+ _pageViewManager = new PageViewManager(_this, extConfig.overridePageViewDuration, _self.core, _pageViewPerformanceManager);
6223
+ _pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
6224
+ _updateBrowserLinkTracking(extConfig, config);
6225
+ _eventTracking = new Timing(_self.diagLog(), "trackEvent");
6226
+ _eventTracking.action =
6227
+ function (name, url, duration, properties) {
6228
+ if (!properties) {
6229
+ properties = {};
6230
+ }
6231
+ properties[durationProperty] = duration.toString();
6232
+ _self.trackEvent({ name: name, properties: properties });
6233
+ };
6234
+ _pageTracking = new Timing(_self.diagLog(), "trackPageView");
6235
+ _pageTracking.action = function (name, url, duration, properties, measurements) {
6236
+ if (isNullOrUndefined(properties)) {
6000
6237
  properties = {};
6001
6238
  }
6002
6239
  properties[durationProperty] = duration.toString();
6003
- _self.trackEvent({ name: name, properties: properties });
6004
- };
6005
- _pageTracking = new Timing(_self.diagLog(), "trackPageView");
6006
- _pageTracking.action = function (name, url, duration, properties, measurements) {
6007
- if (isNullOrUndefined(properties)) {
6008
- properties = {};
6009
- }
6010
- properties[durationProperty] = duration.toString();
6011
- var pageViewItem = {
6012
- name: name,
6013
- uri: url,
6014
- properties: properties,
6015
- measurements: measurements
6016
- };
6017
- _self.sendPageViewInternal(pageViewItem, properties);
6018
- };
6019
- var _window = getWindow();
6020
- var _history = getHistory();
6021
- var _location = getLocation(true);
6022
- var instance = _this;
6023
- if (_self.config.disableExceptionTracking === false &&
6024
- !_self.config.autoExceptionInstrumented && _window) {
6025
- var onerror_1 = "onerror";
6026
- var originalOnError_1 = _window[onerror_1];
6027
- _window.onerror = function (message, url, lineNumber, columnNumber, error) {
6028
- var evt = _window[strEvent];
6029
- var handled = originalOnError_1 && originalOnError_1(message, url, lineNumber, columnNumber, error);
6030
- if (handled !== true) {
6031
- instance._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, evt));
6032
- }
6033
- return handled;
6034
- };
6035
- _self.config.autoExceptionInstrumented = true;
6036
- }
6037
- if (_self.config.disableExceptionTracking === false &&
6038
- _self.config.enableUnhandledPromiseRejectionTracking === true &&
6039
- !_self.config.autoUnhandledPromiseInstrumented && _window) {
6040
- var onunhandledrejection_1 = "onunhandledrejection";
6041
- var originalOnUnhandledRejection_1 = _window[onunhandledrejection_1];
6042
- _window[onunhandledrejection_1] = function (error) {
6043
- var evt = _window[strEvent];
6044
- var handled = originalOnUnhandledRejection_1 && originalOnUnhandledRejection_1.call(_window, error);
6045
- if (handled !== true) {
6046
- instance._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, evt));
6047
- }
6048
- return handled;
6240
+ var pageViewItem = {
6241
+ name: name,
6242
+ uri: url,
6243
+ properties: properties,
6244
+ measurements: measurements
6245
+ };
6246
+ _self.sendPageViewInternal(pageViewItem, properties);
6049
6247
  };
6050
- _self.config.autoUnhandledPromiseInstrumented = true;
6051
- }
6052
- if (_self.config.enableAutoRouteTracking === true
6053
- && _history && isFunction(_history.pushState) && isFunction(_history.replaceState)
6054
- && _window
6055
- && typeof Event !== "undefined") {
6056
- var _self_1 = _this;
6057
- arrForEach(extensions, function (extension) {
6058
- if (extension.identifier === PropertiesPluginIdentifier) {
6059
- _properties = extension;
6060
- }
6061
- });
6062
- _history.pushState = (function (f) { return function pushState() {
6063
- var ret = f.apply(this, arguments);
6064
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "pushState"));
6065
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
6066
- return ret;
6067
- }; })(_history.pushState);
6068
- _history.replaceState = (function (f) { return function replaceState() {
6069
- var ret = f.apply(this, arguments);
6070
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "replaceState"));
6071
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
6072
- return ret;
6073
- }; })(_history.replaceState);
6074
- if (_window.addEventListener) {
6075
- _window.addEventListener(_self_1.config.namePrefix + "popstate", function () {
6076
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
6077
- });
6078
- _window.addEventListener(_self_1.config.namePrefix + "locationchange", function () {
6079
- if (_properties && _properties.context && _properties.context.telemetryTrace) {
6080
- _properties.context.telemetryTrace.traceID = generateW3CId();
6081
- var traceLocationName = "_unknown_";
6082
- if (_location && _location.pathname) {
6083
- traceLocationName = _location.pathname + (_location.hash || "");
6084
- }
6085
- _properties.context.telemetryTrace.name = dataSanitizeString(_self_1.diagLog(), traceLocationName);
6086
- }
6087
- if (_currUri) {
6088
- _prevUri = _currUri;
6089
- _currUri = _location && _location.href || "";
6090
- }
6091
- else {
6092
- _currUri = _location && _location.href || "";
6093
- }
6094
- setTimeout((function (uri) {
6095
- _self_1.trackPageView({ refUri: uri, properties: { duration: 0 } });
6096
- }).bind(_this, _prevUri), _self_1.autoRoutePVDelay);
6097
- });
6248
+ if (hasWindow()) {
6249
+ _updateExceptionTracking(extConfig);
6250
+ _updateLocationChange(extConfig);
6098
6251
  }
6099
6252
  }
6100
- _self.setInitialized(true);
6253
+ catch (e) {
6254
+ _self.setInitialized(false);
6255
+ throw e;
6256
+ }
6257
+ };
6258
+ _self._doTeardown = function (unloadCtx, unloadState) {
6259
+ _pageViewManager && _pageViewManager.teardown(unloadCtx, unloadState);
6260
+ eventOff(window, null, null, _evtNamespace);
6261
+ _initDefaults();
6101
6262
  };
6263
+ function _populateDefaults(config) {
6264
+ var ctx = createProcessTelemetryContext(null, config, _self.core);
6265
+ var identifier = _self.identifier;
6266
+ var defaults = _getDefaultConfig(config);
6267
+ var extConfig = _self.config = ctx.getExtCfg(identifier);
6268
+ if (defaults !== undefined) {
6269
+ objForEachKey(defaults, function (field, value) {
6270
+ extConfig[field] = ctx.getConfig(identifier, field, value);
6271
+ if (extConfig[field] === undefined) {
6272
+ extConfig = value;
6273
+ }
6274
+ });
6275
+ }
6276
+ return extConfig;
6277
+ }
6278
+ function _updateBrowserLinkTracking(extConfig, config) {
6279
+ _isBrowserLinkTrackingEnabled = extConfig.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled;
6280
+ _addDefaultTelemetryInitializers();
6281
+ }
6102
6282
  function trackPageVisitTime(pageName, pageUrl, pageVisitTime) {
6103
6283
  var properties = { PageName: pageName, PageUrl: pageUrl };
6104
6284
  _self.trackMetric({
@@ -6109,11 +6289,11 @@ var ApplicationInsights = /** @class */ (function (_super) {
6109
6289
  sampleCount: 1
6110
6290
  }, properties);
6111
6291
  }
6112
- function _addDefaultTelemetryInitializers(configGetters) {
6113
- if (!configGetters.isBrowserLinkTrackingEnabled()) {
6292
+ function _addDefaultTelemetryInitializers() {
6293
+ if (!_browserLinkInitializerAdded && _isBrowserLinkTrackingEnabled) {
6114
6294
  var browserLinkPaths_1 = ["/browserLinkSignalR/", "/__browserLink/"];
6115
6295
  var dropBrowserLinkRequests = function (envelope) {
6116
- if (envelope.baseType === RemoteDependencyData.dataType) {
6296
+ if (_isBrowserLinkTrackingEnabled && envelope.baseType === RemoteDependencyData.dataType) {
6117
6297
  var remoteData = envelope.baseData;
6118
6298
  if (remoteData) {
6119
6299
  for (var i = 0; i < browserLinkPaths_1.length; i++) {
@@ -6125,70 +6305,147 @@ var ApplicationInsights = /** @class */ (function (_super) {
6125
6305
  }
6126
6306
  return true;
6127
6307
  };
6128
- _addTelemetryInitializer(dropBrowserLinkRequests);
6308
+ _self.addTelemetryInitializer(dropBrowserLinkRequests);
6309
+ _browserLinkInitializerAdded = true;
6129
6310
  }
6130
6311
  }
6131
- function _addTelemetryInitializer(telemetryInitializer) {
6132
- _self._telemetryInitializers.push(telemetryInitializer);
6133
- }
6134
6312
  function _sendCORSException(exception, properties) {
6135
6313
  var telemetryItem = TelemetryItemCreator.create(exception, Exception.dataType, Exception.envelopeType, _self.diagLog(), properties);
6136
6314
  _self.core.track(telemetryItem);
6137
6315
  }
6138
- });
6139
- return _this;
6140
- }
6141
- ApplicationInsights.getDefaultConfig = function (config) {
6142
- if (!config) {
6143
- config = {};
6144
- }
6145
- config.sessionRenewalMs = 30 * 60 * 1000;
6146
- config.sessionExpirationMs = 24 * 60 * 60 * 1000;
6147
- config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
6148
- config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
6149
- config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
6150
- config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
6151
- if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
6152
- config.samplingPercentage = 100;
6153
- }
6154
- config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
6155
- config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
6156
- config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
6157
- config.namePrefix = config.namePrefix || "";
6158
- config.enableDebug = stringToBoolOrDefault(config.enableDebug);
6159
- config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
6160
- config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
6161
- return config;
6162
- };
6163
- ApplicationInsights.Version = "2.8.0-beta.2203-04";
6164
- return ApplicationInsights;
6165
- }(BaseTelemetryPlugin));
6166
- var Timing = /** @class */ (function () {
6167
- function Timing(logger, name) {
6168
- var _self = this;
6169
- var _events = {};
6170
- _self.start = function (name) {
6171
- if (typeof _events[name] !== "undefined") {
6172
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
6316
+ function _updateExceptionTracking(extConfig) {
6317
+ var _window = getWindow();
6318
+ var locn = getLocation(true);
6319
+ _disableExceptionTracking = extConfig.disableExceptionTracking;
6320
+ if (!_disableExceptionTracking && !_autoExceptionInstrumented && !extConfig.autoExceptionInstrumented) {
6321
+ _addHook(InstrumentFunc(_window, "onerror", {
6322
+ ns: _evtNamespace,
6323
+ rsp: function (callDetails, message, url, lineNumber, columnNumber, error) {
6324
+ if (!_disableExceptionTracking && callDetails.rslt !== true) {
6325
+ _self._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, callDetails.evt));
6326
+ }
6327
+ }
6328
+ }));
6329
+ _autoExceptionInstrumented = true;
6330
+ }
6331
+ _addUnhandledPromiseRejectionTracking(extConfig, _window, locn);
6173
6332
  }
6174
- _events[name] = +new Date;
6175
- };
6176
- _self.stop = function (name, url, properties, measurements) {
6177
- var start = _events[name];
6178
- if (isNaN(start)) {
6179
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
6333
+ function _updateLocationChange(extConfig) {
6334
+ var win = getWindow();
6335
+ var locn = getLocation(true);
6336
+ _enableAutoRouteTracking = extConfig.enableAutoRouteTracking === true;
6337
+ if (win && _enableAutoRouteTracking && hasHistory()) {
6338
+ var _history = getHistory();
6339
+ if (isFunction(_history.pushState) && isFunction(_history.replaceState) && typeof Event !== strShimUndefined) {
6340
+ _addHistoryListener(extConfig, win, _history, locn);
6341
+ }
6342
+ }
6180
6343
  }
6181
- else {
6182
- var end = +new Date;
6183
- var duration = dateTimeUtilsDuration(start, end);
6184
- _self.action(name, url, duration, properties, measurements);
6344
+ function _addHistoryListener(extConfig, win, history, locn) {
6345
+ function _popstateHandler() {
6346
+ if (_enableAutoRouteTracking) {
6347
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6348
+ }
6349
+ }
6350
+ function _locationChangeHandler() {
6351
+ if (_currUri) {
6352
+ _prevUri = _currUri;
6353
+ _currUri = locn && locn.href || "";
6354
+ }
6355
+ else {
6356
+ _currUri = locn && locn.href || "";
6357
+ }
6358
+ if (_enableAutoRouteTracking) {
6359
+ var properties = _self.core.getPlugin(PropertiesPluginIdentifier);
6360
+ if (properties) {
6361
+ var context = properties.plugin.context;
6362
+ if (context && context.telemetryTrace) {
6363
+ context.telemetryTrace.traceID = generateW3CId();
6364
+ var traceLocationName = "_unknown_";
6365
+ if (locn && locn.pathname) {
6366
+ traceLocationName = locn.pathname + (locn.hash || "");
6367
+ }
6368
+ context.telemetryTrace.name = dataSanitizeString(_self.diagLog(), traceLocationName);
6369
+ }
6370
+ }
6371
+ setTimeout((function (uri) {
6372
+ _self.trackPageView({ refUri: uri, properties: { duration: 0 } });
6373
+ }).bind(this, _prevUri), _self.autoRoutePVDelay);
6374
+ }
6375
+ }
6376
+ if (!_historyListenerAdded) {
6377
+ _addHook(InstrumentFunc(history, "pushState", {
6378
+ ns: _evtNamespace,
6379
+ rsp: function () {
6380
+ if (_enableAutoRouteTracking) {
6381
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "pushState"));
6382
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6383
+ }
6384
+ }
6385
+ }));
6386
+ _addHook(InstrumentFunc(history, "replaceState", {
6387
+ ns: _evtNamespace,
6388
+ rsp: function () {
6389
+ if (_enableAutoRouteTracking) {
6390
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "replaceState"));
6391
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6392
+ }
6393
+ }
6394
+ }));
6395
+ eventOn(win, extConfig.namePrefix + "popstate", _popstateHandler, _evtNamespace);
6396
+ eventOn(win, extConfig.namePrefix + "locationchange", _locationChangeHandler, _evtNamespace);
6397
+ _historyListenerAdded = true;
6398
+ }
6399
+ }
6400
+ function _addUnhandledPromiseRejectionTracking(extConfig, _window, _location) {
6401
+ _enableUnhandledPromiseRejectionTracking = extConfig.enableUnhandledPromiseRejectionTracking === true;
6402
+ if (_enableUnhandledPromiseRejectionTracking && !_autoUnhandledPromiseInstrumented) {
6403
+ _addHook(InstrumentFunc(_window, "onunhandledrejection", {
6404
+ ns: _evtNamespace,
6405
+ rsp: function (callDetails, error) {
6406
+ if (_enableUnhandledPromiseRejectionTracking && callDetails.rslt !== true) {
6407
+ _self._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, callDetails.evt));
6408
+ }
6409
+ }
6410
+ }));
6411
+ _autoUnhandledPromiseInstrumented = true;
6412
+ extConfig.autoUnhandledPromiseInstrumented = _autoUnhandledPromiseInstrumented;
6413
+ }
6185
6414
  }
6186
- delete _events[name];
6187
- _events[name] = undefined;
6188
- };
6415
+ function _throwInternal(severity, msgId, msg, properties, isUserAct) {
6416
+ _self.diagLog().throwInternal(severity, msgId, msg, properties, isUserAct);
6417
+ }
6418
+ function _initDefaults() {
6419
+ _eventTracking = null;
6420
+ _pageTracking = null;
6421
+ _pageViewManager = null;
6422
+ _pageViewPerformanceManager = null;
6423
+ _pageVisitTimeManager = null;
6424
+ _preInitTelemetryInitializers = null;
6425
+ _isBrowserLinkTrackingEnabled = false;
6426
+ _browserLinkInitializerAdded = false;
6427
+ _enableAutoRouteTracking = false;
6428
+ _historyListenerAdded = false;
6429
+ _disableExceptionTracking = false;
6430
+ _autoExceptionInstrumented = false;
6431
+ _enableUnhandledPromiseRejectionTracking = false;
6432
+ _autoUnhandledPromiseInstrumented = false;
6433
+ var location = getLocation(true);
6434
+ _prevUri = location && location.href || "";
6435
+ _currUri = null;
6436
+ _evtNamespace = null;
6437
+ }
6438
+ objDefineAccessors(_self, "_pageViewManager", function () { return _pageViewManager; });
6439
+ objDefineAccessors(_self, "_pageViewPerformanceManager", function () { return _pageViewPerformanceManager; });
6440
+ objDefineAccessors(_self, "_pageVisitTimeManager", function () { return _pageVisitTimeManager; });
6441
+ objDefineAccessors(_self, "_evtNamespace", function () { return "." + _evtNamespace; });
6442
+ });
6443
+ return _this;
6189
6444
  }
6190
- return Timing;
6191
- }());
6445
+ AnalyticsPlugin.Version = "2.8.0-beta.2203-07";
6446
+ AnalyticsPlugin.getDefaultConfig = _getDefaultConfig;
6447
+ return AnalyticsPlugin;
6448
+ }(BaseTelemetryPlugin));
6192
6449
 
6193
6450
  var BaseSendBuffer = /** @class */ (function () {
6194
6451
  function BaseSendBuffer(logger, config) {
@@ -6467,7 +6724,7 @@ function EnvelopeCreatorInit(logger, telemetryItem) {
6467
6724
  }
6468
6725
  }
6469
6726
  var EnvelopeCreator = {
6470
- Version: "2.8.0-beta.2203-04"
6727
+ Version: "2.8.0-beta.2203-07"
6471
6728
  };
6472
6729
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
6473
6730
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -6762,65 +7019,81 @@ var Serializer = /** @class */ (function () {
6762
7019
  return Serializer;
6763
7020
  }());
6764
7021
 
6765
- var OfflineListener = /** @class */ (function () {
6766
- function OfflineListener() {
6767
- var _window = getWindow();
6768
- var _document = getDocument();
6769
- var isListening = false;
6770
- var _onlineStatus = true;
6771
- dynamicProto(OfflineListener, this, function (_self) {
6772
- try {
6773
- if (_window) {
6774
- if (attachEvent(_window, "online", _setOnline)) {
6775
- attachEvent(_window, "offline", _setOffline);
6776
- isListening = true;
6777
- }
6778
- }
6779
- if (_document) {
6780
- var target = _document.body || _document;
6781
- if (!isUndefined(target.ononline)) {
6782
- target.ononline = _setOnline;
6783
- target.onoffline = _setOffline;
6784
- isListening = true;
6785
- }
6786
- }
6787
- if (isListening) {
6788
- var _navigator = getNavigator();
6789
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6790
- _onlineStatus = _navigator.onLine;
6791
- }
7022
+ function _disableEvents(target, evtNamespace) {
7023
+ eventOff(target, null, null, evtNamespace);
7024
+ }
7025
+ function createOfflineListener(parentEvtNamespace) {
7026
+ var _document = getDocument();
7027
+ var _navigator = getNavigator();
7028
+ var _isListening = false;
7029
+ var _onlineStatus = true;
7030
+ var _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
7031
+ try {
7032
+ if (_enableEvents(getWindow())) {
7033
+ _isListening = true;
7034
+ }
7035
+ if (_document) {
7036
+ var target = _document.body || _document;
7037
+ if (target.ononline) {
7038
+ if (_enableEvents(target)) {
7039
+ _isListening = true;
6792
7040
  }
6793
7041
  }
6794
- catch (e) {
6795
- isListening = false;
7042
+ }
7043
+ if (_isListening) {
7044
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
7045
+ _onlineStatus = _navigator.onLine;
6796
7046
  }
6797
- _self.isListening = isListening;
6798
- _self.isOnline = function () {
6799
- var result = true;
6800
- var _navigator = getNavigator();
6801
- if (isListening) {
6802
- result = _onlineStatus;
6803
- }
6804
- else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6805
- result = _navigator.onLine;
6806
- }
6807
- return result;
6808
- };
6809
- _self.isOffline = function () {
6810
- return !_self.isOnline();
6811
- };
6812
- function _setOnline() {
6813
- _onlineStatus = true;
7047
+ }
7048
+ }
7049
+ catch (e) {
7050
+ _isListening = false;
7051
+ }
7052
+ function _enableEvents(target) {
7053
+ var enabled = false;
7054
+ if (target) {
7055
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
7056
+ if (enabled) {
7057
+ eventOn(target, "offline", _setOffline, _evtNamespace);
6814
7058
  }
6815
- function _setOffline() {
6816
- _onlineStatus = false;
7059
+ }
7060
+ return enabled;
7061
+ }
7062
+ function _setOnline() {
7063
+ _onlineStatus = true;
7064
+ }
7065
+ function _setOffline() {
7066
+ _onlineStatus = false;
7067
+ }
7068
+ function _isOnline() {
7069
+ var result = true;
7070
+ if (_isListening) {
7071
+ result = _onlineStatus;
7072
+ }
7073
+ else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
7074
+ result = _navigator.onLine;
7075
+ }
7076
+ return result;
7077
+ }
7078
+ function _unload() {
7079
+ var win = getWindow();
7080
+ if (win && _isListening) {
7081
+ _disableEvents(win, _evtNamespace);
7082
+ if (_document) {
7083
+ var target = _document.body || _document;
7084
+ if (!isUndefined(target.ononline)) {
7085
+ _disableEvents(target, _evtNamespace);
7086
+ }
6817
7087
  }
6818
- });
7088
+ _isListening = false;
7089
+ }
6819
7090
  }
6820
- OfflineListener.Offline = new OfflineListener;
6821
- return OfflineListener;
6822
- }());
6823
- var Offline = OfflineListener.Offline;
7091
+ return {
7092
+ isOnline: _isOnline,
7093
+ isListening: function () { return _isListening; },
7094
+ unload: _unload
7095
+ };
7096
+ }
6824
7097
 
6825
7098
  var MIN_INPUT_LENGTH = 8;
6826
7099
  var HashCodeScoreGenerator = /** @class */ (function () {
@@ -6948,22 +7221,22 @@ var Sender = /** @class */ (function (_super) {
6948
7221
  var _this = _super.call(this) || this;
6949
7222
  _this.priority = 1001;
6950
7223
  _this.identifier = BreezeChannelIdentifier;
7224
+ _this._senderConfig = _getDefaultAppInsightsChannelConfig();
6951
7225
  var _consecutiveErrors;
6952
7226
  var _retryAt;
6953
7227
  var _lastSend;
6954
- var _paused = false;
7228
+ var _paused;
6955
7229
  var _timeoutHandle;
6956
7230
  var _serializer;
6957
7231
  var _stamp_specific_redirects;
6958
- var _headers = {};
7232
+ var _headers;
6959
7233
  var _syncFetchPayload = 0;
6960
7234
  var _fallbackSender;
6961
7235
  var _syncUnloadSender;
6962
- _this._senderConfig = _getDefaultAppInsightsChannelConfig();
7236
+ var _offlineListener;
7237
+ var _evtNamespace;
6963
7238
  dynamicProto(Sender, _this, function (_self, _base) {
6964
- function _notImplemented() {
6965
- throwError("Method not implemented.");
6966
- }
7239
+ _initDefaults();
6967
7240
  _self.pause = function () {
6968
7241
  _clearScheduledTimer();
6969
7242
  _paused = true;
@@ -6986,7 +7259,7 @@ var Sender = /** @class */ (function (_super) {
6986
7259
  _self.triggerSend(isAsync, null, sendReason || 1 );
6987
7260
  }
6988
7261
  catch (e) {
6989
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
7262
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6990
7263
  }
6991
7264
  }
6992
7265
  };
@@ -6997,7 +7270,7 @@ var Sender = /** @class */ (function (_super) {
6997
7270
  _self.triggerSend(true, _doUnloadSend, 2 );
6998
7271
  }
6999
7272
  catch (e) {
7000
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FailedToSendQueuedTelemetry, "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
7273
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FailedToSendQueuedTelemetry, "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
7001
7274
  }
7002
7275
  }
7003
7276
  else {
@@ -7005,7 +7278,6 @@ var Sender = /** @class */ (function (_super) {
7005
7278
  }
7006
7279
  }
7007
7280
  };
7008
- _self.teardown = _notImplemented;
7009
7281
  _self.addHeader = function (name, value) {
7010
7282
  _headers[name] = value;
7011
7283
  };
@@ -7020,6 +7292,8 @@ var Sender = /** @class */ (function (_super) {
7020
7292
  _self._sender = null;
7021
7293
  _stamp_specific_redirects = 0;
7022
7294
  var diagLog = _self.diagLog();
7295
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
7296
+ _offlineListener = createOfflineListener(_evtNamespace);
7023
7297
  var defaultConfig = _getDefaultAppInsightsChannelConfig();
7024
7298
  objForEachKey(defaultConfig, function (field, value) {
7025
7299
  _self._senderConfig[field] = function () { return ctx.getConfig(identifier, field, value()); };
@@ -7028,7 +7302,7 @@ var Sender = /** @class */ (function (_super) {
7028
7302
  ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
7029
7303
  _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
7030
7304
  if (!_validateInstrumentationKey(config)) {
7031
- diagLog.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
7305
+ _throwInternal(diagLog, LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
7032
7306
  }
7033
7307
  if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
7034
7308
  arrForEach(_self._senderConfig.customHeaders(), function (customHeader) {
@@ -7074,22 +7348,22 @@ var Sender = /** @class */ (function (_super) {
7074
7348
  return;
7075
7349
  }
7076
7350
  if (!telemetryItem) {
7077
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
7351
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
7078
7352
  return;
7079
7353
  }
7080
7354
  if (telemetryItem.baseData && !telemetryItem.baseType) {
7081
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
7355
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
7082
7356
  return;
7083
7357
  }
7084
7358
  if (!telemetryItem.baseType) {
7085
7359
  telemetryItem.baseType = "EventData";
7086
7360
  }
7087
7361
  if (!_self._sender) {
7088
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
7362
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
7089
7363
  return;
7090
7364
  }
7091
7365
  if (!_isSampledIn(telemetryItem)) {
7092
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
7366
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
7093
7367
  return;
7094
7368
  }
7095
7369
  else {
@@ -7099,7 +7373,7 @@ var Sender = /** @class */ (function (_super) {
7099
7373
  var defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
7100
7374
  var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, itemCtx.diagLog(), convertUndefined);
7101
7375
  if (!aiEnvelope_1) {
7102
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
7376
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
7103
7377
  return;
7104
7378
  }
7105
7379
  var doNotSendItem_1 = false;
@@ -7112,7 +7386,7 @@ var Sender = /** @class */ (function (_super) {
7112
7386
  }
7113
7387
  }
7114
7388
  catch (e) {
7115
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
7389
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
7116
7390
  }
7117
7391
  });
7118
7392
  delete telemetryItem.tags[ProcessLegacy];
@@ -7130,7 +7404,7 @@ var Sender = /** @class */ (function (_super) {
7130
7404
  _setupTimer();
7131
7405
  }
7132
7406
  catch (e) {
7133
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.FailedAddingTelemetryToBuffer, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7407
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.FailedAddingTelemetryToBuffer, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7134
7408
  }
7135
7409
  _self.processNext(telemetryItem, itemCtx);
7136
7410
  };
@@ -7165,13 +7439,18 @@ var Sender = /** @class */ (function (_super) {
7165
7439
  catch (e) {
7166
7440
  var ieVer = getIEVersion();
7167
7441
  if (!ieVer || ieVer > 9) {
7168
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7442
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7169
7443
  }
7170
7444
  }
7171
7445
  }
7172
7446
  };
7447
+ _self._doTeardown = function (unloadCtx, unloadState) {
7448
+ _self.onunloadFlush();
7449
+ _offlineListener.unload();
7450
+ _initDefaults();
7451
+ };
7173
7452
  _self._onError = function (payload, message, event) {
7174
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
7453
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
7175
7454
  _self._buffer.clearSent(payload);
7176
7455
  };
7177
7456
  _self._onPartialSuccess = function (payload, results) {
@@ -7196,7 +7475,7 @@ var Sender = /** @class */ (function (_super) {
7196
7475
  }
7197
7476
  if (retry.length > 0) {
7198
7477
  _resendPayload(retry);
7199
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
7478
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
7200
7479
  "Delivered: " + payload.length + ", Failed: " + failed.length +
7201
7480
  ". Will retry to send " + retry.length + " our of " + results.itemsReceived + " items");
7202
7481
  }
@@ -7241,18 +7520,18 @@ var Sender = /** @class */ (function (_super) {
7241
7520
  }
7242
7521
  if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
7243
7522
  _resendPayload(payload);
7244
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7523
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7245
7524
  "Response code " + status + ". Will retry to send " + payload.length + " items.");
7246
7525
  }
7247
7526
  else {
7248
7527
  _self._onError(payload, errorMessage);
7249
7528
  }
7250
7529
  }
7251
- else if (Offline.isOffline()) {
7530
+ else if (_offlineListener && !_offlineListener.isOnline()) {
7252
7531
  if (!_self._senderConfig.isRetryDisabled()) {
7253
7532
  var offlineBackOffMultiplier = 10;
7254
7533
  _resendPayload(payload, offlineBackOffMultiplier);
7255
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(Offline.isOffline(), ". Will retry to send ").concat(payload.length, " items."));
7534
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(!_offlineListener.isOnline(), ". Will retry to send ").concat(payload.length, " items."));
7256
7535
  }
7257
7536
  }
7258
7537
  else {
@@ -7319,8 +7598,8 @@ var Sender = /** @class */ (function (_super) {
7319
7598
  }
7320
7599
  }
7321
7600
  if (droppedPayload.length > 0) {
7322
- _fallbackSender(droppedPayload, true);
7323
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
7601
+ _fallbackSender && _fallbackSender(droppedPayload, true);
7602
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
7324
7603
  }
7325
7604
  }
7326
7605
  }
@@ -7361,7 +7640,7 @@ var Sender = /** @class */ (function (_super) {
7361
7640
  }
7362
7641
  else {
7363
7642
  _fallbackSender && _fallbackSender(payload, true);
7364
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
7643
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
7365
7644
  }
7366
7645
  }
7367
7646
  }
@@ -7452,7 +7731,7 @@ var Sender = /** @class */ (function (_super) {
7452
7731
  }
7453
7732
  }
7454
7733
  catch (e) {
7455
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
7734
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
7456
7735
  response: response
7457
7736
  });
7458
7737
  }
@@ -7523,7 +7802,7 @@ var Sender = /** @class */ (function (_super) {
7523
7802
  xdr.onerror = function (event) { return _self._onError(payload, _formatErrorMessageXdr(xdr), event); };
7524
7803
  var hostingProtocol = _window && _window.location && _window.location.protocol || "";
7525
7804
  if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
7526
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7805
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7527
7806
  "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
7528
7807
  buffer.clear();
7529
7808
  return;
@@ -7554,7 +7833,7 @@ var Sender = /** @class */ (function (_super) {
7554
7833
  manager.eventsSendRequest(sendRequest, isAsync);
7555
7834
  }
7556
7835
  catch (e) {
7557
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
7836
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
7558
7837
  }
7559
7838
  }
7560
7839
  }
@@ -7567,6 +7846,25 @@ var Sender = /** @class */ (function (_super) {
7567
7846
  var regexp = new RegExp(UUID_Regex);
7568
7847
  return regexp.test(config.instrumentationKey);
7569
7848
  }
7849
+ function _initDefaults() {
7850
+ _self._sender = null;
7851
+ _self._buffer = null;
7852
+ _self._appId = null;
7853
+ _self._sample = null;
7854
+ _headers = {};
7855
+ _offlineListener = null;
7856
+ _consecutiveErrors = 0;
7857
+ _retryAt = null;
7858
+ _lastSend = null;
7859
+ _paused = false;
7860
+ _timeoutHandle = null;
7861
+ _serializer = null;
7862
+ _stamp_specific_redirects = 0;
7863
+ _syncFetchPayload = 0;
7864
+ _fallbackSender = null;
7865
+ _syncUnloadSender = null;
7866
+ _evtNamespace = null;
7867
+ }
7570
7868
  });
7571
7869
  return _this;
7572
7870
  }
@@ -7736,7 +8034,7 @@ var Device = /** @class */ (function () {
7736
8034
  return Device;
7737
8035
  }());
7738
8036
 
7739
- var Version = "2.8.0-beta.2203-04";
8037
+ var Version = "2.8.0-beta.2203-07";
7740
8038
  var Internal = /** @class */ (function () {
7741
8039
  function Internal(config) {
7742
8040
  this.sdkVersion = (config.sdkExtension && config.sdkExtension() ? config.sdkExtension() + "_" : "") + "javascript:" + Version;
@@ -9159,7 +9457,7 @@ var Initialization = /** @class */ (function () {
9159
9457
  config.endpointUrl = ingest ? "".concat(ingest, "/v2/track") : config.endpointUrl;
9160
9458
  config.instrumentationKey = cs.instrumentationkey || config.instrumentationKey;
9161
9459
  }
9162
- _self.appInsights = new ApplicationInsights();
9460
+ _self.appInsights = new AnalyticsPlugin();
9163
9461
  _self.properties = new PropertiesPlugin$1();
9164
9462
  _self.dependencies = new AjaxMonitor();
9165
9463
  _self.core = new AppInsightsCore();
@@ -9459,4 +9757,4 @@ catch (e) {
9459
9757
 
9460
9758
  exports.ApplicationInsights = Initialization;
9461
9759
  exports.Telemetry = Telemetry;
9462
- //# sourceMappingURL=ai.2.8.0-beta.2203-04.cjs.js.map
9760
+ //# sourceMappingURL=ai.2.8.0-beta.2203-07.cjs.js.map