@microsoft/applicationinsights-web 2.8.0-beta.2203-02 → 2.8.0-beta.2203-05

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-02.cjs.js → ai.2.8.0-beta.2203-05.cjs.js} +828 -359
  2. package/browser/ai.2.8.0-beta.2203-05.cjs.js.map +1 -0
  3. package/browser/ai.2.8.0-beta.2203-05.cjs.min.js +6 -0
  4. package/browser/ai.2.8.0-beta.2203-05.cjs.min.js.map +1 -0
  5. package/browser/{ai.2.8.0-beta.2203-02.gbl.js → ai.2.8.0-beta.2203-05.gbl.js} +828 -359
  6. package/browser/ai.2.8.0-beta.2203-05.gbl.js.map +1 -0
  7. package/browser/ai.2.8.0-beta.2203-05.gbl.min.js +6 -0
  8. package/browser/ai.2.8.0-beta.2203-05.gbl.min.js.map +1 -0
  9. package/browser/ai.2.8.0-beta.2203-05.integrity.json +66 -0
  10. package/browser/{ai.2.8.0-beta.2203-02.js → ai.2.8.0-beta.2203-05.js} +828 -359
  11. package/browser/ai.2.8.0-beta.2203-05.js.map +1 -0
  12. package/browser/ai.2.8.0-beta.2203-05.min.js +6 -0
  13. package/browser/ai.2.8.0-beta.2203-05.min.js.map +1 -0
  14. package/browser/ai.2.cjs.js +827 -358
  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 +827 -358
  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 +827 -358
  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 +735 -167
  27. package/dist/applicationinsights-web.api.md +22 -19
  28. package/dist/applicationinsights-web.d.ts +168 -106
  29. package/dist/applicationinsights-web.js +828 -359
  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 +168 -106
  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-02.cjs.js.map +0 -1
  42. package/browser/ai.2.8.0-beta.2203-02.cjs.min.js +0 -6
  43. package/browser/ai.2.8.0-beta.2203-02.cjs.min.js.map +0 -1
  44. package/browser/ai.2.8.0-beta.2203-02.gbl.js.map +0 -1
  45. package/browser/ai.2.8.0-beta.2203-02.gbl.min.js +0 -6
  46. package/browser/ai.2.8.0-beta.2203-02.gbl.min.js.map +0 -1
  47. package/browser/ai.2.8.0-beta.2203-02.integrity.json +0 -66
  48. package/browser/ai.2.8.0-beta.2203-02.js.map +0 -1
  49. package/browser/ai.2.8.0-beta.2203-02.min.js +0 -6
  50. package/browser/ai.2.8.0-beta.2203-02.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Web, 2.8.0-beta.2203-02
2
+ * Application Insights JavaScript SDK - Web, 2.8.0-beta.2203-05
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";
@@ -811,7 +812,7 @@ function createEnumStyle(values) {
811
812
  objForEachKey(values, function (field, value) {
812
813
  enumClass[field] = value;
813
814
  if (!isUndefined(enumClass[value])) {
814
- throwError("Value: [" + value + "] already exists for " + field);
815
+ throwError("[" + value + "] exists for " + field);
815
816
  }
816
817
  enumClass[value] = field;
817
818
  });
@@ -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;
@@ -1640,8 +1645,11 @@ function _getNextProxyStart(proxy, config, core, startAt) {
1640
1645
  return createTelemetryProxyChain([startAt], config, core);
1641
1646
  }
1642
1647
  function _createInternalContext(telemetryChain, config, core, startAt) {
1643
- var _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1648
+ var _nextProxy = null;
1644
1649
  var _onComplete = [];
1650
+ if (startAt !== null) {
1651
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1652
+ }
1645
1653
  var context = {
1646
1654
  _next: _moveNext,
1647
1655
  ctx: {
@@ -1691,7 +1699,7 @@ function _createInternalContext(telemetryChain, config, core, startAt) {
1691
1699
  completeDetails.func.call(completeDetails.self, completeDetails.args);
1692
1700
  }
1693
1701
  catch (e) {
1694
- core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1702
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1695
1703
  }
1696
1704
  });
1697
1705
  _onComplete = [];
@@ -1790,6 +1798,27 @@ function createProcessTelemetryUnloadContext(telemetryChain, config, core, start
1790
1798
  context.createNew = _createNew;
1791
1799
  return context;
1792
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
+ }
1793
1822
  function createTelemetryProxyChain(plugins, config, core, startAt) {
1794
1823
  var firstProxy = null;
1795
1824
  var add = startAt ? false : true;
@@ -1836,6 +1865,7 @@ function createTelemetryPluginProxy(plugin, config, core) {
1836
1865
  },
1837
1866
  processTelemetry: _processTelemetry,
1838
1867
  unload: _unloadPlugin,
1868
+ update: _updatePlugin,
1839
1869
  _id: chainId,
1840
1870
  _setNext: function (nextPlugin) {
1841
1871
  nextProxy = nextPlugin;
@@ -1875,7 +1905,7 @@ function createTelemetryPluginProxy(plugin, config, core) {
1875
1905
  hasRun = true;
1876
1906
  }
1877
1907
  if (!nextProxy || !hasNextRun) {
1878
- 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));
1879
1909
  }
1880
1910
  }
1881
1911
  }, details, isAsync);
@@ -1923,6 +1953,24 @@ function createTelemetryPluginProxy(plugin, config, core) {
1923
1953
  unloadCtx.processNext(unloadState);
1924
1954
  }
1925
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
+ }
1926
1974
  return objFreeze(proxyChain);
1927
1975
  }
1928
1976
 
@@ -2092,7 +2140,7 @@ function areCookiesSupported(logger) {
2092
2140
  _supportsCookies = doc[strCookie] !== undefined;
2093
2141
  }
2094
2142
  catch (e) {
2095
- 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) });
2096
2144
  }
2097
2145
  }
2098
2146
  return _supportsCookies;
@@ -2221,6 +2269,17 @@ function createChannelControllerPlugin(channelQueue, core) {
2221
2269
  }
2222
2270
  _runChainOnComplete();
2223
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
+ }
2224
2283
  function _doTeardown(unloadCtx, unloadState) {
2225
2284
  var theUnloadState = unloadState || {
2226
2285
  reason: 0 ,
@@ -2272,7 +2331,8 @@ function createChannelControllerPlugin(channelQueue, core) {
2272
2331
  }, function () {
2273
2332
  itemCtx[strProcessNext](item);
2274
2333
  });
2275
- }
2334
+ },
2335
+ update: _doUpdate
2276
2336
  },
2277
2337
  _a[strPause] = function () {
2278
2338
  _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
@@ -2357,6 +2417,30 @@ function createChannelQueues(channels, extensions, config, core) {
2357
2417
  return channelQueue;
2358
2418
  }
2359
2419
 
2420
+ function createUnloadHandlerContainer() {
2421
+ var handlers = [];
2422
+ function _addHandler(handler) {
2423
+ if (handler) {
2424
+ handlers.push(handler);
2425
+ }
2426
+ }
2427
+ function _runHandlers(unloadCtx, unloadState) {
2428
+ arrForEach(handlers, function (handler) {
2429
+ try {
2430
+ handler(unloadCtx, unloadState);
2431
+ }
2432
+ catch (e) {
2433
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2434
+ }
2435
+ });
2436
+ handlers = [];
2437
+ }
2438
+ return {
2439
+ add: _addHandler,
2440
+ run: _runHandlers
2441
+ };
2442
+ }
2443
+
2360
2444
  var strGetPlugin = "getPlugin";
2361
2445
  var BaseTelemetryPlugin = /** @class */ (function () {
2362
2446
  function BaseTelemetryPlugin() {
@@ -2364,6 +2448,7 @@ var BaseTelemetryPlugin = /** @class */ (function () {
2364
2448
  var _isinitialized;
2365
2449
  var _rootCtx;
2366
2450
  var _nextPlugin;
2451
+ var _unloadHandlerContainer;
2367
2452
  var _hooks;
2368
2453
  _initDefaults();
2369
2454
  dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
@@ -2385,6 +2470,7 @@ var BaseTelemetryPlugin = /** @class */ (function () {
2385
2470
  function _unloadCallback() {
2386
2471
  if (!unloadDone) {
2387
2472
  unloadDone = true;
2473
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
2388
2474
  arrForEach(_hooks, function (fn) {
2389
2475
  fn.rm();
2390
2476
  });
@@ -2403,6 +2489,30 @@ var BaseTelemetryPlugin = /** @class */ (function () {
2403
2489
  }
2404
2490
  return result;
2405
2491
  };
2492
+ _self.update = function (updateCtx, updateState) {
2493
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
2494
+ return;
2495
+ }
2496
+ var result;
2497
+ var updateDone = false;
2498
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2499
+ var theUpdateState = updateState || {
2500
+ reason: 0
2501
+ };
2502
+ function _updateCallback() {
2503
+ if (!updateDone) {
2504
+ updateDone = true;
2505
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2506
+ }
2507
+ }
2508
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2509
+ _updateCallback();
2510
+ }
2511
+ else {
2512
+ result = true;
2513
+ }
2514
+ return result;
2515
+ };
2406
2516
  _self._addHook = function (hooks) {
2407
2517
  if (hooks) {
2408
2518
  if (isArray(hooks)) {
@@ -2413,6 +2523,7 @@ var BaseTelemetryPlugin = /** @class */ (function () {
2413
2523
  }
2414
2524
  }
2415
2525
  };
2526
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2416
2527
  });
2417
2528
  _self.diagLog = function (itemCtx) {
2418
2529
  return _getTelCtx(itemCtx).diagLog();
@@ -2469,6 +2580,7 @@ var BaseTelemetryPlugin = /** @class */ (function () {
2469
2580
  _rootCtx = null;
2470
2581
  _nextPlugin = null;
2471
2582
  _hooks = [];
2583
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2472
2584
  }
2473
2585
  }
2474
2586
  return BaseTelemetryPlugin;
@@ -2515,7 +2627,7 @@ var TelemetryInitializerPlugin = /** @class */ (function (_super) {
2515
2627
  }
2516
2628
  }
2517
2629
  catch (e) {
2518
- itemCtx.diagLog().throwInternal(1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2630
+ _throwInternal(itemCtx.diagLog(), 1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2519
2631
  }
2520
2632
  }
2521
2633
  }
@@ -2538,6 +2650,8 @@ var TelemetryInitializerPlugin = /** @class */ (function (_super) {
2538
2650
 
2539
2651
  var strValidationError = "Plugins must provide initialize method";
2540
2652
  var strNotificationManager = "_notificationManager";
2653
+ var strSdkUnloadingError = "SDK is still unloading...";
2654
+ var strSdkNotInitialized = "SDK is not initialized";
2541
2655
  function _createPerfManager(core, notificationMgr) {
2542
2656
  return new PerfManager(notificationMgr);
2543
2657
  }
@@ -2567,6 +2681,16 @@ function _validateExtensions(logger, channelPriority, allExtensions) {
2567
2681
  core: coreExtensions
2568
2682
  };
2569
2683
  }
2684
+ function _isPluginPresent(thePlugin, plugins) {
2685
+ var exists = false;
2686
+ arrForEach(plugins, function (plugin) {
2687
+ if (plugin === thePlugin) {
2688
+ exists = true;
2689
+ return -1;
2690
+ }
2691
+ });
2692
+ return exists;
2693
+ }
2570
2694
  function _createDummyNotificationManager() {
2571
2695
  var _a;
2572
2696
  return objCreateFn((_a = {},
@@ -2591,15 +2715,20 @@ var BaseCore = /** @class */ (function () {
2591
2715
  var _channelControl;
2592
2716
  var _channelConfig;
2593
2717
  var _channelQueue;
2718
+ var _isUnloading;
2594
2719
  var _telemetryInitializerPlugin;
2595
2720
  var _internalLogsEventName;
2596
2721
  var _evtNamespace;
2722
+ var _unloadHandlers;
2597
2723
  var _debugListener;
2598
2724
  var _internalLogPoller = 0;
2599
2725
  dynamicProto(BaseCore, this, function (_self) {
2600
2726
  _initDefaults();
2601
2727
  _self.isInitialized = function () { return _isInitialized; };
2602
2728
  _self.initialize = function (config, extensions, logger, notificationManager) {
2729
+ if (_isUnloading) {
2730
+ throwError(strSdkUnloadingError);
2731
+ }
2603
2732
  if (_self.isInitialized()) {
2604
2733
  throwError("Core should not be initialized more than once");
2605
2734
  }
@@ -2612,15 +2741,14 @@ var BaseCore = /** @class */ (function () {
2612
2741
  _initDebugListener(config);
2613
2742
  _initPerfManager(config);
2614
2743
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
2615
- var extConfig = getSetValue(config, strExtensionConfig);
2616
- extConfig.NotificationManager = notificationManager;
2744
+ _initExtConfig(config);
2617
2745
  if (logger) {
2618
2746
  _self.logger = logger;
2619
2747
  }
2620
2748
  _configExtensions = [];
2621
2749
  _configExtensions.push.apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2622
2750
  _channelConfig = (config || {}).channels;
2623
- _initPluginChain(config);
2751
+ _initPluginChain(config, null);
2624
2752
  if (_self.getTransmissionControls().length === 0) {
2625
2753
  throwError("No channels available");
2626
2754
  }
@@ -2638,7 +2766,7 @@ var BaseCore = /** @class */ (function () {
2638
2766
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
2639
2767
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
2640
2768
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
2641
- if (_self.isInitialized()) {
2769
+ if (!_isUnloading && _self.isInitialized()) {
2642
2770
  _createTelCtx().processNext(telemetryItem);
2643
2771
  }
2644
2772
  else {
@@ -2653,14 +2781,14 @@ var BaseCore = /** @class */ (function () {
2653
2781
  }
2654
2782
  return _notificationManager;
2655
2783
  };
2656
- _self.addNotificationListener = function (listener) {
2784
+ _self[strAddNotificationListener] = function (listener) {
2657
2785
  if (_notificationManager) {
2658
- _notificationManager.addNotificationListener(listener);
2786
+ _notificationManager[strAddNotificationListener](listener);
2659
2787
  }
2660
2788
  };
2661
- _self.removeNotificationListener = function (listener) {
2789
+ _self[strRemoveNotificationListener] = function (listener) {
2662
2790
  if (_notificationManager) {
2663
- _notificationManager.removeNotificationListener(listener);
2791
+ _notificationManager[strRemoveNotificationListener](listener);
2664
2792
  }
2665
2793
  };
2666
2794
  _self.getCookieMgr = function () {
@@ -2717,10 +2845,86 @@ var BaseCore = /** @class */ (function () {
2717
2845
  }
2718
2846
  };
2719
2847
  proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2848
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
2849
+ if (isAsync === void 0) { isAsync = true; }
2850
+ if (!_isInitialized) {
2851
+ throwError(strSdkNotInitialized);
2852
+ }
2853
+ if (_isUnloading) {
2854
+ throwError(strSdkUnloadingError);
2855
+ }
2856
+ var unloadState = {
2857
+ reason: 50 ,
2858
+ isAsync: isAsync,
2859
+ flushComplete: false
2860
+ };
2861
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
2862
+ processUnloadCtx.onComplete(function () {
2863
+ _initDefaults();
2864
+ unloadComplete && unloadComplete(unloadState);
2865
+ }, _self);
2866
+ function _doUnload(flushComplete) {
2867
+ unloadState.flushComplete = flushComplete;
2868
+ _isUnloading = true;
2869
+ _unloadHandlers.run(processUnloadCtx, unloadState);
2870
+ _self.stopPollingInternalLogs();
2871
+ processUnloadCtx.processNext(unloadState);
2872
+ }
2873
+ if (_channelControl) {
2874
+ _channelControl.flush(isAsync, _doUnload, 6 , cbTimeout);
2875
+ }
2876
+ else {
2877
+ _doUnload(true);
2878
+ }
2879
+ };
2720
2880
  _self.getPlugin = _getPlugin;
2881
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
2882
+ if (isAsync === void 0) { isAsync = true; }
2883
+ if (!plugin) {
2884
+ addCb && addCb(false);
2885
+ _logOrThrowError(strValidationError);
2886
+ return;
2887
+ }
2888
+ var existingPlugin = _getPlugin(plugin.identifier);
2889
+ if (existingPlugin && !replaceExisting) {
2890
+ addCb && addCb(false);
2891
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2892
+ return;
2893
+ }
2894
+ var updateState = {
2895
+ reason: 16
2896
+ };
2897
+ function _addPlugin(removed) {
2898
+ _configExtensions.push(plugin);
2899
+ updateState.added = [plugin];
2900
+ _initPluginChain(_self.config, updateState);
2901
+ addCb && addCb(true);
2902
+ }
2903
+ if (existingPlugin) {
2904
+ var removedPlugins_1 = [existingPlugin.plugin];
2905
+ var unloadState = {
2906
+ reason: 2 ,
2907
+ isAsync: isAsync
2908
+ };
2909
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
2910
+ if (!removed) {
2911
+ addCb && addCb(false);
2912
+ }
2913
+ else {
2914
+ updateState.removed = removedPlugins_1;
2915
+ updateState.reason |= 32 ;
2916
+ _addPlugin();
2917
+ }
2918
+ });
2919
+ }
2920
+ else {
2921
+ _addPlugin();
2922
+ }
2923
+ };
2721
2924
  _self.evtNamespace = function () {
2722
2925
  return _evtNamespace;
2723
2926
  };
2927
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2724
2928
  function _initDefaults() {
2725
2929
  _isInitialized = false;
2726
2930
  _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
@@ -2738,13 +2942,15 @@ var BaseCore = /** @class */ (function () {
2738
2942
  _channelControl = null;
2739
2943
  _channelConfig = null;
2740
2944
  _channelQueue = null;
2945
+ _isUnloading = false;
2741
2946
  _internalLogsEventName = null;
2742
2947
  _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2948
+ _unloadHandlers = createUnloadHandlerContainer();
2743
2949
  }
2744
2950
  function _createTelCtx() {
2745
2951
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2746
2952
  }
2747
- function _initPluginChain(config) {
2953
+ function _initPluginChain(config, updateState) {
2748
2954
  var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
2749
2955
  _coreExtensions = theExtensions.core;
2750
2956
  _pluginChain = null;
@@ -2770,6 +2976,9 @@ var BaseCore = /** @class */ (function () {
2770
2976
  _channelControl.initialize(config, _self, allExtensions);
2771
2977
  initializePlugins(_createTelCtx(), allExtensions);
2772
2978
  _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2979
+ if (updateState) {
2980
+ _doUpdate(updateState);
2981
+ }
2773
2982
  }
2774
2983
  function _getPlugin(pluginIdentifier) {
2775
2984
  var theExt = null;
@@ -2792,6 +3001,23 @@ var BaseCore = /** @class */ (function () {
2792
3001
  isEnabled: function () {
2793
3002
  var pluginState = _getPluginState(thePlugin);
2794
3003
  return !pluginState[strTeardown] && !pluginState[strDisabled];
3004
+ },
3005
+ remove: function (isAsync, removeCb) {
3006
+ if (isAsync === void 0) { isAsync = true; }
3007
+ var pluginsToRemove = [thePlugin];
3008
+ var unloadState = {
3009
+ reason: 1 ,
3010
+ isAsync: isAsync
3011
+ };
3012
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
3013
+ if (removed) {
3014
+ _initPluginChain(_self.config, {
3015
+ reason: 32 ,
3016
+ removed: pluginsToRemove
3017
+ });
3018
+ }
3019
+ removeCb && removeCb(removed);
3020
+ });
2795
3021
  }
2796
3022
  };
2797
3023
  }
@@ -2807,6 +3033,46 @@ var BaseCore = /** @class */ (function () {
2807
3033
  }
2808
3034
  return _pluginChain;
2809
3035
  }
3036
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
3037
+ if (thePlugins && thePlugins.length > 0) {
3038
+ var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
3039
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
3040
+ unloadCtx.onComplete(function () {
3041
+ var removed = false;
3042
+ var newConfigExtensions = [];
3043
+ arrForEach(_configExtensions, function (plugin, idx) {
3044
+ if (!_isPluginPresent(plugin, thePlugins)) {
3045
+ newConfigExtensions.push(plugin);
3046
+ }
3047
+ else {
3048
+ removed = true;
3049
+ }
3050
+ });
3051
+ _configExtensions = newConfigExtensions;
3052
+ var newChannelConfig = [];
3053
+ if (_channelConfig) {
3054
+ arrForEach(_channelConfig, function (queue, idx) {
3055
+ var newQueue = [];
3056
+ arrForEach(queue, function (channel) {
3057
+ if (!_isPluginPresent(channel, thePlugins)) {
3058
+ newQueue.push(channel);
3059
+ }
3060
+ else {
3061
+ removed = true;
3062
+ }
3063
+ });
3064
+ newChannelConfig.push(newQueue);
3065
+ });
3066
+ _channelConfig = newChannelConfig;
3067
+ }
3068
+ removeComplete && removeComplete(removed);
3069
+ });
3070
+ unloadCtx.processNext(unloadState);
3071
+ }
3072
+ else {
3073
+ removeComplete(false);
3074
+ }
3075
+ }
2810
3076
  function _flushInternalLogs() {
2811
3077
  var queue = _self.logger ? _self.logger.queue : [];
2812
3078
  if (queue) {
@@ -2841,6 +3107,25 @@ var BaseCore = /** @class */ (function () {
2841
3107
  setValue(_self.config, "createPerfMgr", _createPerfManager);
2842
3108
  }
2843
3109
  }
3110
+ function _initExtConfig(config) {
3111
+ var extConfig = getSetValue(config, strExtensionConfig);
3112
+ extConfig.NotificationManager = _notificationManager;
3113
+ }
3114
+ function _doUpdate(updateState) {
3115
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
3116
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3117
+ updateCtx.processNext(updateState);
3118
+ }
3119
+ }
3120
+ function _logOrThrowError(message) {
3121
+ var logger = _self.logger;
3122
+ if (logger) {
3123
+ _throwInternal(logger, 2 , 73 , message);
3124
+ }
3125
+ else {
3126
+ throwError(message);
3127
+ }
3128
+ }
2844
3129
  });
2845
3130
  }
2846
3131
  return BaseCore;
@@ -2950,6 +3235,8 @@ var AppInsightsCore = /** @class */ (function (_super) {
2950
3235
  var strOnPrefix = "on";
2951
3236
  var strAttachEvent = "attachEvent";
2952
3237
  var strAddEventHelper = "addEventListener";
3238
+ var strDetachEvent = "detachEvent";
3239
+ var strRemoveEventListener = "removeEventListener";
2953
3240
  var strEvents = "events";
2954
3241
  var strVisibilityChangeEvt = "visibilitychange";
2955
3242
  var strPageHide = "pagehide";
@@ -2966,12 +3253,12 @@ function _normalizeNamespace(name) {
2966
3253
  }
2967
3254
  return name;
2968
3255
  }
2969
- function _getEvtNamespace(eventName, namespaces) {
2970
- if (namespaces) {
3256
+ function _getEvtNamespace(eventName, evtNamespace) {
3257
+ if (evtNamespace) {
2971
3258
  var theNamespace_1 = "";
2972
- if (isArray(namespaces)) {
3259
+ if (isArray(evtNamespace)) {
2973
3260
  theNamespace_1 = "";
2974
- arrForEach(namespaces, function (name) {
3261
+ arrForEach(evtNamespace, function (name) {
2975
3262
  name = _normalizeNamespace(name);
2976
3263
  if (name) {
2977
3264
  if (name[0] !== ".") {
@@ -2982,7 +3269,7 @@ function _getEvtNamespace(eventName, namespaces) {
2982
3269
  });
2983
3270
  }
2984
3271
  else {
2985
- theNamespace_1 = _normalizeNamespace(namespaces);
3272
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
2986
3273
  }
2987
3274
  if (theNamespace_1) {
2988
3275
  if (theNamespace_1[0] !== ".") {
@@ -3006,6 +3293,16 @@ function _getRegisteredEvents(target, evtName, addDefault) {
3006
3293
  }
3007
3294
  return registeredEvents;
3008
3295
  }
3296
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
3297
+ if (obj && evtName && evtName.type) {
3298
+ if (obj[strRemoveEventListener]) {
3299
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3300
+ }
3301
+ else if (obj[strDetachEvent]) {
3302
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3303
+ }
3304
+ }
3305
+ }
3009
3306
  function _doAttach(obj, evtName, handlerRef, useCapture) {
3010
3307
  var result = false;
3011
3308
  if (obj && evtName && evtName.type && handlerRef) {
@@ -3020,6 +3317,34 @@ function _doAttach(obj, evtName, handlerRef, useCapture) {
3020
3317
  }
3021
3318
  return result;
3022
3319
  }
3320
+ function _doUnregister(target, events, evtName, unRegFn) {
3321
+ var idx = events.length;
3322
+ while (idx--) {
3323
+ var theEvent = events[idx];
3324
+ if (theEvent) {
3325
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3326
+ if (!unRegFn || unRegFn(theEvent)) {
3327
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3328
+ events.splice(idx, 1);
3329
+ }
3330
+ }
3331
+ }
3332
+ }
3333
+ }
3334
+ function _unregisterEvents(target, evtName, unRegFn) {
3335
+ if (evtName.type) {
3336
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
3337
+ }
3338
+ else {
3339
+ var eventCache = elmNodeData.get(target, strEvents, {});
3340
+ objForEachKey(eventCache, function (evtType, events) {
3341
+ _doUnregister(target, events, evtName, unRegFn);
3342
+ });
3343
+ if (objKeys(eventCache).length === 0) {
3344
+ elmNodeData.kill(target, strEvents);
3345
+ }
3346
+ }
3347
+ }
3023
3348
  function mergeEvtNamespace(theNamespace, namespaces) {
3024
3349
  var newNamespaces;
3025
3350
  if (namespaces) {
@@ -3057,6 +3382,27 @@ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3057
3382
  }
3058
3383
  return result;
3059
3384
  }
3385
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3386
+ if (useCapture === void 0) { useCapture = false; }
3387
+ if (target) {
3388
+ try {
3389
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3390
+ var found_1 = false;
3391
+ _unregisterEvents(target, evtName_1, function (regEvent) {
3392
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3393
+ found_1 = true;
3394
+ return true;
3395
+ }
3396
+ return false;
3397
+ });
3398
+ if (!found_1) {
3399
+ _doDetach(target, evtName_1, handlerRef, useCapture);
3400
+ }
3401
+ }
3402
+ catch (e) {
3403
+ }
3404
+ }
3405
+ }
3060
3406
  function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3061
3407
  if (useCapture === void 0) { useCapture = false; }
3062
3408
  return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
@@ -3497,7 +3843,7 @@ function dataSanitizeKey(logger, name) {
3497
3843
  name = strTrim(name.toString());
3498
3844
  if (name.length > 150 ) {
3499
3845
  nameTrunc = name.substring(0, 150 );
3500
- logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3846
+ _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3501
3847
  }
3502
3848
  }
3503
3849
  return nameTrunc || name;
@@ -3510,7 +3856,7 @@ function dataSanitizeString(logger, value, maxLength) {
3510
3856
  value = strTrim(value);
3511
3857
  if (value.toString().length > maxLength) {
3512
3858
  valueTrunc = value.toString().substring(0, maxLength);
3513
- logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3859
+ _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3514
3860
  }
3515
3861
  }
3516
3862
  return valueTrunc || value;
@@ -3523,7 +3869,7 @@ function dataSanitizeMessage(logger, message) {
3523
3869
  if (message) {
3524
3870
  if (message.length > 32768 ) {
3525
3871
  messageTrunc = message.substring(0, 32768 );
3526
- logger && logger.throwInternal(2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3872
+ _throwInternal(logger, 2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3527
3873
  }
3528
3874
  }
3529
3875
  return messageTrunc || message;
@@ -3534,7 +3880,7 @@ function dataSanitizeException(logger, exception) {
3534
3880
  var value = "" + exception;
3535
3881
  if (value.length > 32768 ) {
3536
3882
  exceptionTrunc = value.substring(0, 32768 );
3537
- logger && logger.throwInternal(2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3883
+ _throwInternal(logger, 2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3538
3884
  }
3539
3885
  }
3540
3886
  return exceptionTrunc || exception;
@@ -3548,7 +3894,7 @@ function dataSanitizeProperties(logger, properties) {
3548
3894
  value = getJSON().stringify(value);
3549
3895
  }
3550
3896
  catch (e) {
3551
- logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3897
+ _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3552
3898
  }
3553
3899
  }
3554
3900
  value = dataSanitizeString(logger, value, 8192 );
@@ -3579,7 +3925,7 @@ function dataSanitizeInput(logger, input, maxLength, _msgId) {
3579
3925
  input = strTrim(input);
3580
3926
  if (input.length > maxLength) {
3581
3927
  inputTrunc = input.substring(0, maxLength);
3582
- logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3928
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3583
3929
  }
3584
3930
  }
3585
3931
  return inputTrunc || input;
@@ -3717,8 +4063,12 @@ function utlDisableStorage() {
3717
4063
  _canUseLocalStorage = false;
3718
4064
  _canUseSessionStorage = false;
3719
4065
  }
3720
- function utlCanUseLocalStorage() {
3721
- if (_canUseLocalStorage === undefined) {
4066
+ function utlEnableStorage() {
4067
+ _canUseLocalStorage = utlCanUseLocalStorage(true);
4068
+ _canUseSessionStorage = utlCanUseSessionStorage(true);
4069
+ }
4070
+ function utlCanUseLocalStorage(reset) {
4071
+ if (reset || _canUseLocalStorage === undefined) {
3722
4072
  _canUseLocalStorage = !!_getVerifiedStorageObject(StorageType.LocalStorage);
3723
4073
  }
3724
4074
  return _canUseLocalStorage;
@@ -3731,7 +4081,7 @@ function utlGetLocalStorage(logger, name) {
3731
4081
  }
3732
4082
  catch (e) {
3733
4083
  _canUseLocalStorage = false;
3734
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
4084
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3735
4085
  }
3736
4086
  }
3737
4087
  return null;
@@ -3745,7 +4095,7 @@ function utlSetLocalStorage(logger, name, data) {
3745
4095
  }
3746
4096
  catch (e) {
3747
4097
  _canUseLocalStorage = false;
3748
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
4098
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3749
4099
  }
3750
4100
  }
3751
4101
  return false;
@@ -3759,13 +4109,13 @@ function utlRemoveStorage(logger, name) {
3759
4109
  }
3760
4110
  catch (e) {
3761
4111
  _canUseLocalStorage = false;
3762
- logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4112
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
3763
4113
  }
3764
4114
  }
3765
4115
  return false;
3766
4116
  }
3767
- function utlCanUseSessionStorage() {
3768
- if (_canUseSessionStorage === undefined) {
4117
+ function utlCanUseSessionStorage(reset) {
4118
+ if (reset || _canUseSessionStorage === undefined) {
3769
4119
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
3770
4120
  }
3771
4121
  return _canUseSessionStorage;
@@ -3787,7 +4137,7 @@ function utlGetSessionStorage(logger, name) {
3787
4137
  }
3788
4138
  catch (e) {
3789
4139
  _canUseSessionStorage = false;
3790
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
4140
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3791
4141
  }
3792
4142
  }
3793
4143
  return null;
@@ -3801,7 +4151,7 @@ function utlSetSessionStorage(logger, name, data) {
3801
4151
  }
3802
4152
  catch (e) {
3803
4153
  _canUseSessionStorage = false;
3804
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
4154
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3805
4155
  }
3806
4156
  }
3807
4157
  return false;
@@ -3815,7 +4165,7 @@ function utlRemoveSessionStorage(logger, name) {
3815
4165
  }
3816
4166
  catch (e) {
3817
4167
  _canUseSessionStorage = false;
3818
- logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4168
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
3819
4169
  }
3820
4170
  }
3821
4171
  return false;
@@ -5550,6 +5900,33 @@ var PageViewPerformanceManager = /** @class */ (function () {
5550
5900
  return PageViewPerformanceManager;
5551
5901
  }());
5552
5902
 
5903
+ var Timing = /** @class */ (function () {
5904
+ function Timing(logger, name) {
5905
+ var _self = this;
5906
+ var _events = {};
5907
+ _self.start = function (name) {
5908
+ if (typeof _events[name] !== "undefined") {
5909
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
5910
+ }
5911
+ _events[name] = +new Date;
5912
+ };
5913
+ _self.stop = function (name, url, properties, measurements) {
5914
+ var start = _events[name];
5915
+ if (isNaN(start)) {
5916
+ _throwInternal(logger, LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
5917
+ }
5918
+ else {
5919
+ var end = +new Date;
5920
+ var duration = dateTimeUtilsDuration(start, end);
5921
+ _self.action(name, url, duration, properties, measurements);
5922
+ }
5923
+ delete _events[name];
5924
+ _events[name] = undefined;
5925
+ };
5926
+ }
5927
+ return Timing;
5928
+ }());
5929
+
5553
5930
  var durationProperty = "duration";
5554
5931
  var strEvent = "event";
5555
5932
  function _dispatchEvent(target, evnt) {
@@ -5567,47 +5944,78 @@ function _getReason(error) {
5567
5944
  }
5568
5945
  return error || "";
5569
5946
  }
5570
- var ApplicationInsights = /** @class */ (function (_super) {
5571
- __extendsFn(ApplicationInsights, _super);
5572
- function ApplicationInsights() {
5947
+ var MinMilliSeconds = 60000;
5948
+ function _configMilliseconds(value, defValue) {
5949
+ value = value || defValue;
5950
+ if (value < MinMilliSeconds) {
5951
+ value = MinMilliSeconds;
5952
+ }
5953
+ return value;
5954
+ }
5955
+ function _getDefaultConfig(config) {
5956
+ if (!config) {
5957
+ config = {};
5958
+ }
5959
+ config.sessionRenewalMs = _configMilliseconds(config.sessionRenewalMs, 30 * 60 * 1000);
5960
+ config.sessionExpirationMs = _configMilliseconds(config.sessionExpirationMs, 24 * 60 * 60 * 1000);
5961
+ config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
5962
+ config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
5963
+ config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
5964
+ config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
5965
+ if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
5966
+ config.samplingPercentage = 100;
5967
+ }
5968
+ config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
5969
+ config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
5970
+ config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
5971
+ config.namePrefix = config.namePrefix || "";
5972
+ config.enableDebug = stringToBoolOrDefault(config.enableDebug);
5973
+ config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
5974
+ config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
5975
+ return config;
5976
+ }
5977
+ function _updateStorageUsage(extConfig) {
5978
+ if (!isUndefined(extConfig.isStorageUseDisabled)) {
5979
+ if (extConfig.isStorageUseDisabled) {
5980
+ utlDisableStorage();
5981
+ }
5982
+ else {
5983
+ utlEnableStorage();
5984
+ }
5985
+ }
5986
+ }
5987
+ var AnalyticsPlugin = /** @class */ (function (_super) {
5988
+ __extendsFn(AnalyticsPlugin, _super);
5989
+ function AnalyticsPlugin() {
5573
5990
  var _this = _super.call(this) || this;
5574
5991
  _this.identifier = AnalyticsPluginIdentifier;
5575
5992
  _this.priority = 180;
5576
5993
  _this.autoRoutePVDelay = 500;
5577
5994
  var _eventTracking;
5578
5995
  var _pageTracking;
5579
- var _properties;
5996
+ var _pageViewManager;
5997
+ var _pageViewPerformanceManager;
5998
+ var _pageVisitTimeManager;
5999
+ var _preInitTelemetryInitializers;
6000
+ var _isBrowserLinkTrackingEnabled;
6001
+ var _browserLinkInitializerAdded;
6002
+ var _enableAutoRouteTracking;
6003
+ var _historyListenerAdded;
6004
+ var _disableExceptionTracking;
6005
+ var _autoExceptionInstrumented;
6006
+ var _enableUnhandledPromiseRejectionTracking;
6007
+ var _autoUnhandledPromiseInstrumented;
5580
6008
  var _prevUri;
5581
6009
  var _currUri;
5582
- dynamicProto(ApplicationInsights, _this, function (_self, _base) {
5583
- var location = getLocation(true);
5584
- _prevUri = location && location.href || "";
6010
+ var _evtNamespace;
6011
+ dynamicProto(AnalyticsPlugin, _this, function (_self, _base) {
6012
+ var _addHook = _base._addHook;
6013
+ _initDefaults();
5585
6014
  _self.getCookieMgr = function () {
5586
6015
  return safeGetCookieMgr(_self.core);
5587
6016
  };
5588
6017
  _self.processTelemetry = function (env, itemCtx) {
5589
- doPerf(_self.core, function () { return _self.identifier + ":processTelemetry"; }, function () {
5590
- var doNotSendItem = false;
5591
- var telemetryInitializersCount = _self._telemetryInitializers.length;
5592
- itemCtx = _self._getTelCtx(itemCtx);
5593
- for (var i = 0; i < telemetryInitializersCount; ++i) {
5594
- var telemetryInitializer = _self._telemetryInitializers[i];
5595
- if (telemetryInitializer) {
5596
- try {
5597
- if (telemetryInitializer.apply(null, [env]) === false) {
5598
- doNotSendItem = true;
5599
- break;
5600
- }
5601
- }
5602
- catch (e) {
5603
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
5604
- }
5605
- }
5606
- }
5607
- if (!doNotSendItem) {
5608
- _self.processNext(env, itemCtx);
5609
- }
5610
- }, function () { return ({ item: env }); }, !(env.sync));
6018
+ _self.processNext(env, itemCtx);
5611
6019
  };
5612
6020
  _self.trackEvent = function (event, customProperties) {
5613
6021
  try {
@@ -5615,7 +6023,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5615
6023
  _self.core.track(telemetryItem);
5616
6024
  }
5617
6025
  catch (e) {
5618
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6026
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5619
6027
  }
5620
6028
  };
5621
6029
  _self.startTrackEvent = function (name) {
@@ -5623,7 +6031,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5623
6031
  _eventTracking.start(name);
5624
6032
  }
5625
6033
  catch (e) {
5626
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6034
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackEventFailed, "startTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5627
6035
  }
5628
6036
  };
5629
6037
  _self.stopTrackEvent = function (name, properties, measurements) {
@@ -5631,7 +6039,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5631
6039
  _eventTracking.stop(name, undefined, properties);
5632
6040
  }
5633
6041
  catch (e) {
5634
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6042
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackEventFailed, "stopTrackEvent failed, event will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5635
6043
  }
5636
6044
  };
5637
6045
  _self.trackTrace = function (trace, customProperties) {
@@ -5640,7 +6048,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5640
6048
  _self.core.track(telemetryItem);
5641
6049
  }
5642
6050
  catch (e) {
5643
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6051
+ _throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TrackTraceFailed, "trackTrace failed, trace will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5644
6052
  }
5645
6053
  };
5646
6054
  _self.trackMetric = function (metric, customProperties) {
@@ -5649,19 +6057,19 @@ var ApplicationInsights = /** @class */ (function (_super) {
5649
6057
  _self.core.track(telemetryItem);
5650
6058
  }
5651
6059
  catch (e) {
5652
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6060
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackMetricFailed, "trackMetric failed, metric will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5653
6061
  }
5654
6062
  };
5655
6063
  _self.trackPageView = function (pageView, customProperties) {
5656
6064
  try {
5657
6065
  var inPv = pageView || {};
5658
- _self._pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
6066
+ _pageViewManager.trackPageView(inPv, __assignFn(__assignFn(__assignFn({}, inPv.properties), inPv.measurements), customProperties));
5659
6067
  if (_self.config.autoTrackPageVisitTime) {
5660
- _self._pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
6068
+ _pageVisitTimeManager.trackPreviousPageVisit(inPv.name, inPv.uri);
5661
6069
  }
5662
6070
  }
5663
6071
  catch (e) {
5664
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6072
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageView failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5665
6073
  }
5666
6074
  };
5667
6075
  _self.sendPageViewInternal = function (pageView, properties, systemProperties) {
@@ -5677,12 +6085,13 @@ var ApplicationInsights = /** @class */ (function (_super) {
5677
6085
  _self.core.track(telemetryItem);
5678
6086
  };
5679
6087
  _self.trackPageViewPerformance = function (pageViewPerformance, customProperties) {
6088
+ var inPvp = pageViewPerformance || {};
5680
6089
  try {
5681
- _self._pageViewPerformanceManager.populatePageViewPerformanceEvent(pageViewPerformance);
5682
- _self.sendPageViewPerformanceInternal(pageViewPerformance, customProperties);
6090
+ _pageViewPerformanceManager.populatePageViewPerformanceEvent(inPvp);
6091
+ _self.sendPageViewPerformanceInternal(inPvp, customProperties);
5683
6092
  }
5684
6093
  catch (e) {
5685
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6094
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackPVFailed, "trackPageViewPerformance failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5686
6095
  }
5687
6096
  };
5688
6097
  _self.startTrackPage = function (name) {
@@ -5694,7 +6103,7 @@ var ApplicationInsights = /** @class */ (function (_super) {
5694
6103
  _pageTracking.start(name);
5695
6104
  }
5696
6105
  catch (e) {
5697
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6106
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StartTrackFailed, "startTrackPage failed, page view may not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5698
6107
  }
5699
6108
  };
5700
6109
  _self.stopTrackPage = function (name, url, properties, measurement) {
@@ -5709,11 +6118,11 @@ var ApplicationInsights = /** @class */ (function (_super) {
5709
6118
  }
5710
6119
  _pageTracking.stop(name, url, properties, measurement);
5711
6120
  if (_self.config.autoTrackPageVisitTime) {
5712
- _self._pageVisitTimeManager.trackPreviousPageVisit(name, url);
6121
+ _pageVisitTimeManager.trackPreviousPageVisit(name, url);
5713
6122
  }
5714
6123
  }
5715
6124
  catch (e) {
5716
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6125
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.StopTrackFailed, "stopTrackPage failed, page view will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5717
6126
  }
5718
6127
  };
5719
6128
  _self.sendExceptionInternal = function (exception, customProperties, systemProperties) {
@@ -5723,11 +6132,14 @@ var ApplicationInsights = /** @class */ (function (_super) {
5723
6132
  _self.core.track(telemetryItem);
5724
6133
  };
5725
6134
  _self.trackException = function (exception, customProperties) {
6135
+ if (exception && !exception.exception && exception.error) {
6136
+ exception.exception = exception.error;
6137
+ }
5726
6138
  try {
5727
6139
  _self.sendExceptionInternal(exception, customProperties);
5728
6140
  }
5729
6141
  catch (e) {
5730
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6142
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TrackExceptionFailed, "trackException failed, exception will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5731
6143
  }
5732
6144
  };
5733
6145
  _self._onerror = function (exception) {
@@ -5761,158 +6173,97 @@ var ApplicationInsights = /** @class */ (function (_super) {
5761
6173
  }
5762
6174
  catch (e) {
5763
6175
  var errorString = error ? (error.name + ", " + error.message) : "null";
5764
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
6176
+ _throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.ExceptionWhileLoggingError, "_onError threw exception while logging error, error will not be collected: "
5765
6177
  + getExceptionName(e), { exception: dumpObj(e), errorString: errorString });
5766
6178
  }
5767
6179
  };
5768
6180
  _self.addTelemetryInitializer = function (telemetryInitializer) {
5769
- _self._telemetryInitializers.push(telemetryInitializer);
6181
+ if (_self.core) {
6182
+ return _self.core.addTelemetryInitializer(telemetryInitializer);
6183
+ }
6184
+ if (!_preInitTelemetryInitializers) {
6185
+ _preInitTelemetryInitializers = [];
6186
+ }
6187
+ _preInitTelemetryInitializers.push(telemetryInitializer);
5770
6188
  };
5771
6189
  _self.initialize = function (config, core, extensions, pluginChain) {
5772
6190
  if (_self.isInitialized()) {
5773
6191
  return;
5774
6192
  }
5775
6193
  if (isNullOrUndefined(core)) {
5776
- throw Error("Error initializing");
6194
+ throwError("Error initializing");
5777
6195
  }
5778
6196
  _base.initialize(config, core, extensions, pluginChain);
5779
- _self.setInitialized(false);
5780
- var ctx = _self._getTelCtx();
5781
- var identifier = _self.identifier;
5782
- _self.config = ctx.getExtCfg(identifier);
5783
- var defaults = ApplicationInsights.getDefaultConfig(config);
5784
- if (defaults !== undefined) {
5785
- objForEachKey(defaults, function (field, value) {
5786
- _self.config[field] = ctx.getConfig(identifier, field, value);
5787
- if (_self.config[field] === undefined) {
5788
- _self.config[field] = value;
5789
- }
5790
- });
5791
- }
5792
- if (_self.config.isStorageUseDisabled) {
5793
- utlDisableStorage();
5794
- }
5795
- var configGetters = {
5796
- instrumentationKey: function () { return config.instrumentationKey; },
5797
- accountId: function () { return _self.config.accountId || config.accountId; },
5798
- sessionRenewalMs: function () { return _self.config.sessionRenewalMs || config.sessionRenewalMs; },
5799
- sessionExpirationMs: function () { return _self.config.sessionExpirationMs || config.sessionExpirationMs; },
5800
- sampleRate: function () { return _self.config.samplingPercentage || config.samplingPercentage; },
5801
- sdkExtension: function () { return _self.config.sdkExtension || config.sdkExtension; },
5802
- isBrowserLinkTrackingEnabled: function () { return _self.config.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled; },
5803
- appId: function () { return _self.config.appId || config.appId; }
5804
- };
5805
- _self._pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
5806
- _self._pageViewManager = new PageViewManager(_this, _self.config.overridePageViewDuration, _self.core, _self._pageViewPerformanceManager);
5807
- _self._pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
5808
- _self._telemetryInitializers = _self._telemetryInitializers || [];
5809
- _addDefaultTelemetryInitializers(configGetters);
5810
- _eventTracking = new Timing(_self.diagLog(), "trackEvent");
5811
- _eventTracking.action =
5812
- function (name, url, duration, properties) {
5813
- if (!properties) {
6197
+ try {
6198
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("AnalyticsPlugin"), core.evtNamespace && core.evtNamespace());
6199
+ if (_preInitTelemetryInitializers) {
6200
+ arrForEach(_preInitTelemetryInitializers, function (initializer) {
6201
+ core.addTelemetryInitializer(initializer);
6202
+ });
6203
+ _preInitTelemetryInitializers = null;
6204
+ }
6205
+ var extConfig = _populateDefaults(config);
6206
+ _updateStorageUsage(extConfig);
6207
+ _pageViewPerformanceManager = new PageViewPerformanceManager(_self.core);
6208
+ _pageViewManager = new PageViewManager(_this, extConfig.overridePageViewDuration, _self.core, _pageViewPerformanceManager);
6209
+ _pageVisitTimeManager = new PageVisitTimeManager(_self.diagLog(), function (pageName, pageUrl, pageVisitTime) { return trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
6210
+ _updateBrowserLinkTracking(extConfig, config);
6211
+ _eventTracking = new Timing(_self.diagLog(), "trackEvent");
6212
+ _eventTracking.action =
6213
+ function (name, url, duration, properties) {
6214
+ if (!properties) {
6215
+ properties = {};
6216
+ }
6217
+ properties[durationProperty] = duration.toString();
6218
+ _self.trackEvent({ name: name, properties: properties });
6219
+ };
6220
+ _pageTracking = new Timing(_self.diagLog(), "trackPageView");
6221
+ _pageTracking.action = function (name, url, duration, properties, measurements) {
6222
+ if (isNullOrUndefined(properties)) {
5814
6223
  properties = {};
5815
6224
  }
5816
6225
  properties[durationProperty] = duration.toString();
5817
- _self.trackEvent({ name: name, properties: properties });
5818
- };
5819
- _pageTracking = new Timing(_self.diagLog(), "trackPageView");
5820
- _pageTracking.action = function (name, url, duration, properties, measurements) {
5821
- if (isNullOrUndefined(properties)) {
5822
- properties = {};
5823
- }
5824
- properties[durationProperty] = duration.toString();
5825
- var pageViewItem = {
5826
- name: name,
5827
- uri: url,
5828
- properties: properties,
5829
- measurements: measurements
5830
- };
5831
- _self.sendPageViewInternal(pageViewItem, properties);
5832
- };
5833
- var _window = getWindow();
5834
- var _history = getHistory();
5835
- var _location = getLocation(true);
5836
- var instance = _this;
5837
- if (_self.config.disableExceptionTracking === false &&
5838
- !_self.config.autoExceptionInstrumented && _window) {
5839
- var onerror_1 = "onerror";
5840
- var originalOnError_1 = _window[onerror_1];
5841
- _window.onerror = function (message, url, lineNumber, columnNumber, error) {
5842
- var evt = _window[strEvent];
5843
- var handled = originalOnError_1 && originalOnError_1(message, url, lineNumber, columnNumber, error);
5844
- if (handled !== true) {
5845
- instance._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, evt));
5846
- }
5847
- return handled;
5848
- };
5849
- _self.config.autoExceptionInstrumented = true;
5850
- }
5851
- if (_self.config.disableExceptionTracking === false &&
5852
- _self.config.enableUnhandledPromiseRejectionTracking === true &&
5853
- !_self.config.autoUnhandledPromiseInstrumented && _window) {
5854
- var onunhandledrejection_1 = "onunhandledrejection";
5855
- var originalOnUnhandledRejection_1 = _window[onunhandledrejection_1];
5856
- _window[onunhandledrejection_1] = function (error) {
5857
- var evt = _window[strEvent];
5858
- var handled = originalOnUnhandledRejection_1 && originalOnUnhandledRejection_1.call(_window, error);
5859
- if (handled !== true) {
5860
- instance._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, evt));
5861
- }
5862
- return handled;
6226
+ var pageViewItem = {
6227
+ name: name,
6228
+ uri: url,
6229
+ properties: properties,
6230
+ measurements: measurements
6231
+ };
6232
+ _self.sendPageViewInternal(pageViewItem, properties);
5863
6233
  };
5864
- _self.config.autoUnhandledPromiseInstrumented = true;
5865
- }
5866
- if (_self.config.enableAutoRouteTracking === true
5867
- && _history && isFunction(_history.pushState) && isFunction(_history.replaceState)
5868
- && _window
5869
- && typeof Event !== "undefined") {
5870
- var _self_1 = _this;
5871
- arrForEach(extensions, function (extension) {
5872
- if (extension.identifier === PropertiesPluginIdentifier) {
5873
- _properties = extension;
5874
- }
5875
- });
5876
- _history.pushState = (function (f) { return function pushState() {
5877
- var ret = f.apply(this, arguments);
5878
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "pushState"));
5879
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
5880
- return ret;
5881
- }; })(_history.pushState);
5882
- _history.replaceState = (function (f) { return function replaceState() {
5883
- var ret = f.apply(this, arguments);
5884
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "replaceState"));
5885
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
5886
- return ret;
5887
- }; })(_history.replaceState);
5888
- if (_window.addEventListener) {
5889
- _window.addEventListener(_self_1.config.namePrefix + "popstate", function () {
5890
- _dispatchEvent(_window, createDomEvent(_self_1.config.namePrefix + "locationchange"));
5891
- });
5892
- _window.addEventListener(_self_1.config.namePrefix + "locationchange", function () {
5893
- if (_properties && _properties.context && _properties.context.telemetryTrace) {
5894
- _properties.context.telemetryTrace.traceID = generateW3CId();
5895
- var traceLocationName = "_unknown_";
5896
- if (_location && _location.pathname) {
5897
- traceLocationName = _location.pathname + (_location.hash || "");
5898
- }
5899
- _properties.context.telemetryTrace.name = dataSanitizeString(_self_1.diagLog(), traceLocationName);
5900
- }
5901
- if (_currUri) {
5902
- _prevUri = _currUri;
5903
- _currUri = _location && _location.href || "";
5904
- }
5905
- else {
5906
- _currUri = _location && _location.href || "";
5907
- }
5908
- setTimeout((function (uri) {
5909
- _self_1.trackPageView({ refUri: uri, properties: { duration: 0 } });
5910
- }).bind(_this, _prevUri), _self_1.autoRoutePVDelay);
5911
- });
6234
+ if (hasWindow()) {
6235
+ _updateExceptionTracking(extConfig);
6236
+ _updateLocationChange(extConfig);
5912
6237
  }
5913
6238
  }
5914
- _self.setInitialized(true);
6239
+ catch (e) {
6240
+ _self.setInitialized(false);
6241
+ throw e;
6242
+ }
5915
6243
  };
6244
+ _self._doTeardown = function (unloadCtx, unloadState) {
6245
+ eventOff(window, null, null, _evtNamespace);
6246
+ _initDefaults();
6247
+ };
6248
+ function _populateDefaults(config) {
6249
+ var ctx = createProcessTelemetryContext(null, config, _self.core);
6250
+ var identifier = _self.identifier;
6251
+ var defaults = _getDefaultConfig(config);
6252
+ var extConfig = _self.config = ctx.getExtCfg(identifier);
6253
+ if (defaults !== undefined) {
6254
+ objForEachKey(defaults, function (field, value) {
6255
+ extConfig[field] = ctx.getConfig(identifier, field, value);
6256
+ if (extConfig[field] === undefined) {
6257
+ extConfig = value;
6258
+ }
6259
+ });
6260
+ }
6261
+ return extConfig;
6262
+ }
6263
+ function _updateBrowserLinkTracking(extConfig, config) {
6264
+ _isBrowserLinkTrackingEnabled = extConfig.isBrowserLinkTrackingEnabled || config.isBrowserLinkTrackingEnabled;
6265
+ _addDefaultTelemetryInitializers();
6266
+ }
5916
6267
  function trackPageVisitTime(pageName, pageUrl, pageVisitTime) {
5917
6268
  var properties = { PageName: pageName, PageUrl: pageUrl };
5918
6269
  _self.trackMetric({
@@ -5923,11 +6274,11 @@ var ApplicationInsights = /** @class */ (function (_super) {
5923
6274
  sampleCount: 1
5924
6275
  }, properties);
5925
6276
  }
5926
- function _addDefaultTelemetryInitializers(configGetters) {
5927
- if (!configGetters.isBrowserLinkTrackingEnabled()) {
6277
+ function _addDefaultTelemetryInitializers() {
6278
+ if (!_browserLinkInitializerAdded && _isBrowserLinkTrackingEnabled) {
5928
6279
  var browserLinkPaths_1 = ["/browserLinkSignalR/", "/__browserLink/"];
5929
6280
  var dropBrowserLinkRequests = function (envelope) {
5930
- if (envelope.baseType === RemoteDependencyData.dataType) {
6281
+ if (_isBrowserLinkTrackingEnabled && envelope.baseType === RemoteDependencyData.dataType) {
5931
6282
  var remoteData = envelope.baseData;
5932
6283
  if (remoteData) {
5933
6284
  for (var i = 0; i < browserLinkPaths_1.length; i++) {
@@ -5939,70 +6290,147 @@ var ApplicationInsights = /** @class */ (function (_super) {
5939
6290
  }
5940
6291
  return true;
5941
6292
  };
5942
- _addTelemetryInitializer(dropBrowserLinkRequests);
6293
+ _self.addTelemetryInitializer(dropBrowserLinkRequests);
6294
+ _browserLinkInitializerAdded = true;
5943
6295
  }
5944
6296
  }
5945
- function _addTelemetryInitializer(telemetryInitializer) {
5946
- _self._telemetryInitializers.push(telemetryInitializer);
5947
- }
5948
6297
  function _sendCORSException(exception, properties) {
5949
6298
  var telemetryItem = TelemetryItemCreator.create(exception, Exception.dataType, Exception.envelopeType, _self.diagLog(), properties);
5950
6299
  _self.core.track(telemetryItem);
5951
6300
  }
5952
- });
5953
- return _this;
5954
- }
5955
- ApplicationInsights.getDefaultConfig = function (config) {
5956
- if (!config) {
5957
- config = {};
5958
- }
5959
- config.sessionRenewalMs = 30 * 60 * 1000;
5960
- config.sessionExpirationMs = 24 * 60 * 60 * 1000;
5961
- config.disableExceptionTracking = stringToBoolOrDefault(config.disableExceptionTracking);
5962
- config.autoTrackPageVisitTime = stringToBoolOrDefault(config.autoTrackPageVisitTime);
5963
- config.overridePageViewDuration = stringToBoolOrDefault(config.overridePageViewDuration);
5964
- config.enableUnhandledPromiseRejectionTracking = stringToBoolOrDefault(config.enableUnhandledPromiseRejectionTracking);
5965
- if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
5966
- config.samplingPercentage = 100;
5967
- }
5968
- config.isStorageUseDisabled = stringToBoolOrDefault(config.isStorageUseDisabled);
5969
- config.isBrowserLinkTrackingEnabled = stringToBoolOrDefault(config.isBrowserLinkTrackingEnabled);
5970
- config.enableAutoRouteTracking = stringToBoolOrDefault(config.enableAutoRouteTracking);
5971
- config.namePrefix = config.namePrefix || "";
5972
- config.enableDebug = stringToBoolOrDefault(config.enableDebug);
5973
- config.disableFlushOnBeforeUnload = stringToBoolOrDefault(config.disableFlushOnBeforeUnload);
5974
- config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
5975
- return config;
5976
- };
5977
- ApplicationInsights.Version = "2.8.0-beta.2203-02";
5978
- return ApplicationInsights;
5979
- }(BaseTelemetryPlugin));
5980
- var Timing = /** @class */ (function () {
5981
- function Timing(logger, name) {
5982
- var _self = this;
5983
- var _events = {};
5984
- _self.start = function (name) {
5985
- if (typeof _events[name] !== "undefined") {
5986
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StartCalledMoreThanOnce, "start was called more than once for this event without calling stop.", { name: name, key: name }, true);
6301
+ function _updateExceptionTracking(extConfig) {
6302
+ var _window = getWindow();
6303
+ var locn = getLocation(true);
6304
+ _disableExceptionTracking = extConfig.disableExceptionTracking;
6305
+ if (!_disableExceptionTracking && !_autoExceptionInstrumented && !extConfig.autoExceptionInstrumented) {
6306
+ _addHook(InstrumentFunc(_window, "onerror", {
6307
+ ns: _evtNamespace,
6308
+ rsp: function (callDetails, message, url, lineNumber, columnNumber, error) {
6309
+ if (!_disableExceptionTracking && callDetails.rslt !== true) {
6310
+ _self._onerror(Exception.CreateAutoException(message, url, lineNumber, columnNumber, error, callDetails.evt));
6311
+ }
6312
+ }
6313
+ }));
6314
+ _autoExceptionInstrumented = true;
6315
+ }
6316
+ _addUnhandledPromiseRejectionTracking(extConfig, _window, locn);
5987
6317
  }
5988
- _events[name] = +new Date;
5989
- };
5990
- _self.stop = function (name, url, properties, measurements) {
5991
- var start = _events[name];
5992
- if (isNaN(start)) {
5993
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StopCalledWithoutStart, "stop was called without a corresponding start.", { name: name, key: name }, true);
6318
+ function _updateLocationChange(extConfig) {
6319
+ var win = getWindow();
6320
+ var locn = getLocation(true);
6321
+ _enableAutoRouteTracking = extConfig.enableAutoRouteTracking === true;
6322
+ if (win && _enableAutoRouteTracking && hasHistory()) {
6323
+ var _history = getHistory();
6324
+ if (isFunction(_history.pushState) && isFunction(_history.replaceState) && typeof Event !== strShimUndefined) {
6325
+ _addHistoryListener(extConfig, win, _history, locn);
6326
+ }
6327
+ }
5994
6328
  }
5995
- else {
5996
- var end = +new Date;
5997
- var duration = dateTimeUtilsDuration(start, end);
5998
- _self.action(name, url, duration, properties, measurements);
6329
+ function _addHistoryListener(extConfig, win, history, locn) {
6330
+ function _popstateHandler() {
6331
+ if (_enableAutoRouteTracking) {
6332
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6333
+ }
6334
+ }
6335
+ function _locationChangeHandler() {
6336
+ if (_currUri) {
6337
+ _prevUri = _currUri;
6338
+ _currUri = locn && locn.href || "";
6339
+ }
6340
+ else {
6341
+ _currUri = locn && locn.href || "";
6342
+ }
6343
+ if (_enableAutoRouteTracking) {
6344
+ var properties = _self.core.getPlugin(PropertiesPluginIdentifier);
6345
+ if (properties) {
6346
+ var context = properties.plugin.context;
6347
+ if (context && context.telemetryTrace) {
6348
+ context.telemetryTrace.traceID = generateW3CId();
6349
+ var traceLocationName = "_unknown_";
6350
+ if (locn && locn.pathname) {
6351
+ traceLocationName = locn.pathname + (locn.hash || "");
6352
+ }
6353
+ context.telemetryTrace.name = dataSanitizeString(_self.diagLog(), traceLocationName);
6354
+ }
6355
+ }
6356
+ setTimeout((function (uri) {
6357
+ _self.trackPageView({ refUri: uri, properties: { duration: 0 } });
6358
+ }).bind(this, _prevUri), _self.autoRoutePVDelay);
6359
+ }
6360
+ }
6361
+ if (!_historyListenerAdded) {
6362
+ _addHook(InstrumentFunc(history, "pushState", {
6363
+ ns: _evtNamespace,
6364
+ rsp: function () {
6365
+ if (_enableAutoRouteTracking) {
6366
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "pushState"));
6367
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6368
+ }
6369
+ }
6370
+ }));
6371
+ _addHook(InstrumentFunc(history, "replaceState", {
6372
+ ns: _evtNamespace,
6373
+ rsp: function () {
6374
+ if (_enableAutoRouteTracking) {
6375
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "replaceState"));
6376
+ _dispatchEvent(win, createDomEvent(extConfig.namePrefix + "locationchange"));
6377
+ }
6378
+ }
6379
+ }));
6380
+ eventOn(win, extConfig.namePrefix + "popstate", _popstateHandler, _evtNamespace);
6381
+ eventOn(win, extConfig.namePrefix + "locationchange", _locationChangeHandler, _evtNamespace);
6382
+ _historyListenerAdded = true;
6383
+ }
6384
+ }
6385
+ function _addUnhandledPromiseRejectionTracking(extConfig, _window, _location) {
6386
+ _enableUnhandledPromiseRejectionTracking = extConfig.enableUnhandledPromiseRejectionTracking === true;
6387
+ if (_enableUnhandledPromiseRejectionTracking && !_autoUnhandledPromiseInstrumented) {
6388
+ _addHook(InstrumentFunc(_window, "onunhandledrejection", {
6389
+ ns: _evtNamespace,
6390
+ rsp: function (callDetails, error) {
6391
+ if (_enableUnhandledPromiseRejectionTracking && callDetails.rslt !== true) {
6392
+ _self._onerror(Exception.CreateAutoException(_getReason(error), _location ? _location.href : "", 0, 0, error, callDetails.evt));
6393
+ }
6394
+ }
6395
+ }));
6396
+ _autoUnhandledPromiseInstrumented = true;
6397
+ extConfig.autoUnhandledPromiseInstrumented = _autoUnhandledPromiseInstrumented;
6398
+ }
5999
6399
  }
6000
- delete _events[name];
6001
- _events[name] = undefined;
6002
- };
6400
+ function _throwInternal(severity, msgId, msg, properties, isUserAct) {
6401
+ _self.diagLog().throwInternal(severity, msgId, msg, properties, isUserAct);
6402
+ }
6403
+ function _initDefaults() {
6404
+ _eventTracking = null;
6405
+ _pageTracking = null;
6406
+ _pageViewManager = null;
6407
+ _pageViewPerformanceManager = null;
6408
+ _pageVisitTimeManager = null;
6409
+ _preInitTelemetryInitializers = null;
6410
+ _isBrowserLinkTrackingEnabled = false;
6411
+ _browserLinkInitializerAdded = false;
6412
+ _enableAutoRouteTracking = false;
6413
+ _historyListenerAdded = false;
6414
+ _disableExceptionTracking = false;
6415
+ _autoExceptionInstrumented = false;
6416
+ _enableUnhandledPromiseRejectionTracking = false;
6417
+ _autoUnhandledPromiseInstrumented = false;
6418
+ var location = getLocation(true);
6419
+ _prevUri = location && location.href || "";
6420
+ _currUri = null;
6421
+ _evtNamespace = null;
6422
+ }
6423
+ objDefineAccessors(_self, "_pageViewManager", function () { return _pageViewManager; });
6424
+ objDefineAccessors(_self, "_pageViewPerformanceManager", function () { return _pageViewPerformanceManager; });
6425
+ objDefineAccessors(_self, "_pageVisitTimeManager", function () { return _pageVisitTimeManager; });
6426
+ objDefineAccessors(_self, "_evtNamespace", function () { return "." + _evtNamespace; });
6427
+ });
6428
+ return _this;
6003
6429
  }
6004
- return Timing;
6005
- }());
6430
+ AnalyticsPlugin.Version = "2.8.0-beta.2203-05";
6431
+ AnalyticsPlugin.getDefaultConfig = _getDefaultConfig;
6432
+ return AnalyticsPlugin;
6433
+ }(BaseTelemetryPlugin));
6006
6434
 
6007
6435
  var BaseSendBuffer = /** @class */ (function () {
6008
6436
  function BaseSendBuffer(logger, config) {
@@ -6281,7 +6709,7 @@ function EnvelopeCreatorInit(logger, telemetryItem) {
6281
6709
  }
6282
6710
  }
6283
6711
  var EnvelopeCreator = {
6284
- Version: "2.8.0-beta.2203-02"
6712
+ Version: "2.8.0-beta.2203-05"
6285
6713
  };
6286
6714
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
6287
6715
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -6576,65 +7004,81 @@ var Serializer = /** @class */ (function () {
6576
7004
  return Serializer;
6577
7005
  }());
6578
7006
 
6579
- var OfflineListener = /** @class */ (function () {
6580
- function OfflineListener() {
6581
- var _window = getWindow();
6582
- var _document = getDocument();
6583
- var isListening = false;
6584
- var _onlineStatus = true;
6585
- dynamicProto(OfflineListener, this, function (_self) {
6586
- try {
6587
- if (_window) {
6588
- if (attachEvent(_window, "online", _setOnline)) {
6589
- attachEvent(_window, "offline", _setOffline);
6590
- isListening = true;
6591
- }
6592
- }
6593
- if (_document) {
6594
- var target = _document.body || _document;
6595
- if (!isUndefined(target.ononline)) {
6596
- target.ononline = _setOnline;
6597
- target.onoffline = _setOffline;
6598
- isListening = true;
6599
- }
6600
- }
6601
- if (isListening) {
6602
- var _navigator = getNavigator();
6603
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6604
- _onlineStatus = _navigator.onLine;
6605
- }
7007
+ function _disableEvents(target, evtNamespace) {
7008
+ eventOff(target, null, null, evtNamespace);
7009
+ }
7010
+ function createOfflineListener(parentEvtNamespace) {
7011
+ var _document = getDocument();
7012
+ var _navigator = getNavigator();
7013
+ var _isListening = false;
7014
+ var _onlineStatus = true;
7015
+ var _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
7016
+ try {
7017
+ if (_enableEvents(getWindow())) {
7018
+ _isListening = true;
7019
+ }
7020
+ if (_document) {
7021
+ var target = _document.body || _document;
7022
+ if (target.ononline) {
7023
+ if (_enableEvents(target)) {
7024
+ _isListening = true;
6606
7025
  }
6607
7026
  }
6608
- catch (e) {
6609
- isListening = false;
7027
+ }
7028
+ if (_isListening) {
7029
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
7030
+ _onlineStatus = _navigator.onLine;
6610
7031
  }
6611
- _self.isListening = isListening;
6612
- _self.isOnline = function () {
6613
- var result = true;
6614
- var _navigator = getNavigator();
6615
- if (isListening) {
6616
- result = _onlineStatus;
6617
- }
6618
- else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
6619
- result = _navigator.onLine;
6620
- }
6621
- return result;
6622
- };
6623
- _self.isOffline = function () {
6624
- return !_self.isOnline();
6625
- };
6626
- function _setOnline() {
6627
- _onlineStatus = true;
7032
+ }
7033
+ }
7034
+ catch (e) {
7035
+ _isListening = false;
7036
+ }
7037
+ function _enableEvents(target) {
7038
+ var enabled = false;
7039
+ if (target) {
7040
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
7041
+ if (enabled) {
7042
+ eventOn(target, "offline", _setOffline, _evtNamespace);
6628
7043
  }
6629
- function _setOffline() {
6630
- _onlineStatus = false;
7044
+ }
7045
+ return enabled;
7046
+ }
7047
+ function _setOnline() {
7048
+ _onlineStatus = true;
7049
+ }
7050
+ function _setOffline() {
7051
+ _onlineStatus = false;
7052
+ }
7053
+ function _isOnline() {
7054
+ var result = true;
7055
+ if (_isListening) {
7056
+ result = _onlineStatus;
7057
+ }
7058
+ else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
7059
+ result = _navigator.onLine;
7060
+ }
7061
+ return result;
7062
+ }
7063
+ function _unload() {
7064
+ var win = getWindow();
7065
+ if (win && _isListening) {
7066
+ _disableEvents(win, _evtNamespace);
7067
+ if (_document) {
7068
+ var target = _document.body || _document;
7069
+ if (!isUndefined(target.ononline)) {
7070
+ _disableEvents(target, _evtNamespace);
7071
+ }
6631
7072
  }
6632
- });
7073
+ _isListening = false;
7074
+ }
6633
7075
  }
6634
- OfflineListener.Offline = new OfflineListener;
6635
- return OfflineListener;
6636
- }());
6637
- var Offline = OfflineListener.Offline;
7076
+ return {
7077
+ isOnline: _isOnline,
7078
+ isListening: function () { return _isListening; },
7079
+ unload: _unload
7080
+ };
7081
+ }
6638
7082
 
6639
7083
  var MIN_INPUT_LENGTH = 8;
6640
7084
  var HashCodeScoreGenerator = /** @class */ (function () {
@@ -6762,22 +7206,22 @@ var Sender = /** @class */ (function (_super) {
6762
7206
  var _this = _super.call(this) || this;
6763
7207
  _this.priority = 1001;
6764
7208
  _this.identifier = BreezeChannelIdentifier;
7209
+ _this._senderConfig = _getDefaultAppInsightsChannelConfig();
6765
7210
  var _consecutiveErrors;
6766
7211
  var _retryAt;
6767
7212
  var _lastSend;
6768
- var _paused = false;
7213
+ var _paused;
6769
7214
  var _timeoutHandle;
6770
7215
  var _serializer;
6771
7216
  var _stamp_specific_redirects;
6772
- var _headers = {};
7217
+ var _headers;
6773
7218
  var _syncFetchPayload = 0;
6774
7219
  var _fallbackSender;
6775
7220
  var _syncUnloadSender;
6776
- _this._senderConfig = _getDefaultAppInsightsChannelConfig();
7221
+ var _offlineListener;
7222
+ var _evtNamespace;
6777
7223
  dynamicProto(Sender, _this, function (_self, _base) {
6778
- function _notImplemented() {
6779
- throwError("Method not implemented.");
6780
- }
7224
+ _initDefaults();
6781
7225
  _self.pause = function () {
6782
7226
  _clearScheduledTimer();
6783
7227
  _paused = true;
@@ -6800,7 +7244,7 @@ var Sender = /** @class */ (function (_super) {
6800
7244
  _self.triggerSend(isAsync, null, sendReason || 1 );
6801
7245
  }
6802
7246
  catch (e) {
6803
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
7247
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
6804
7248
  }
6805
7249
  }
6806
7250
  };
@@ -6811,7 +7255,7 @@ var Sender = /** @class */ (function (_super) {
6811
7255
  _self.triggerSend(true, _doUnloadSend, 2 );
6812
7256
  }
6813
7257
  catch (e) {
6814
- _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) });
7258
+ _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) });
6815
7259
  }
6816
7260
  }
6817
7261
  else {
@@ -6819,7 +7263,6 @@ var Sender = /** @class */ (function (_super) {
6819
7263
  }
6820
7264
  }
6821
7265
  };
6822
- _self.teardown = _notImplemented;
6823
7266
  _self.addHeader = function (name, value) {
6824
7267
  _headers[name] = value;
6825
7268
  };
@@ -6834,6 +7277,8 @@ var Sender = /** @class */ (function (_super) {
6834
7277
  _self._sender = null;
6835
7278
  _stamp_specific_redirects = 0;
6836
7279
  var diagLog = _self.diagLog();
7280
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
7281
+ _offlineListener = createOfflineListener(_evtNamespace);
6837
7282
  var defaultConfig = _getDefaultAppInsightsChannelConfig();
6838
7283
  objForEachKey(defaultConfig, function (field, value) {
6839
7284
  _self._senderConfig[field] = function () { return ctx.getConfig(identifier, field, value()); };
@@ -6842,7 +7287,7 @@ var Sender = /** @class */ (function (_super) {
6842
7287
  ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
6843
7288
  _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
6844
7289
  if (!_validateInstrumentationKey(config)) {
6845
- diagLog.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
7290
+ _throwInternal(diagLog, LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
6846
7291
  }
6847
7292
  if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
6848
7293
  arrForEach(_self._senderConfig.customHeaders(), function (customHeader) {
@@ -6888,22 +7333,22 @@ var Sender = /** @class */ (function (_super) {
6888
7333
  return;
6889
7334
  }
6890
7335
  if (!telemetryItem) {
6891
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
7336
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
6892
7337
  return;
6893
7338
  }
6894
7339
  if (telemetryItem.baseData && !telemetryItem.baseType) {
6895
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
7340
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
6896
7341
  return;
6897
7342
  }
6898
7343
  if (!telemetryItem.baseType) {
6899
7344
  telemetryItem.baseType = "EventData";
6900
7345
  }
6901
7346
  if (!_self._sender) {
6902
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
7347
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
6903
7348
  return;
6904
7349
  }
6905
7350
  if (!_isSampledIn(telemetryItem)) {
6906
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
7351
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
6907
7352
  return;
6908
7353
  }
6909
7354
  else {
@@ -6913,7 +7358,7 @@ var Sender = /** @class */ (function (_super) {
6913
7358
  var defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
6914
7359
  var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, itemCtx.diagLog(), convertUndefined);
6915
7360
  if (!aiEnvelope_1) {
6916
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
7361
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
6917
7362
  return;
6918
7363
  }
6919
7364
  var doNotSendItem_1 = false;
@@ -6926,7 +7371,7 @@ var Sender = /** @class */ (function (_super) {
6926
7371
  }
6927
7372
  }
6928
7373
  catch (e) {
6929
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
7374
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
6930
7375
  }
6931
7376
  });
6932
7377
  delete telemetryItem.tags[ProcessLegacy];
@@ -6944,7 +7389,7 @@ var Sender = /** @class */ (function (_super) {
6944
7389
  _setupTimer();
6945
7390
  }
6946
7391
  catch (e) {
6947
- 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) });
7392
+ _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) });
6948
7393
  }
6949
7394
  _self.processNext(telemetryItem, itemCtx);
6950
7395
  };
@@ -6979,13 +7424,18 @@ var Sender = /** @class */ (function (_super) {
6979
7424
  catch (e) {
6980
7425
  var ieVer = getIEVersion();
6981
7426
  if (!ieVer || ieVer > 9) {
6982
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
7427
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
6983
7428
  }
6984
7429
  }
6985
7430
  }
6986
7431
  };
7432
+ _self._doTeardown = function (unloadCtx, unloadState) {
7433
+ _self.onunloadFlush();
7434
+ _offlineListener.unload();
7435
+ _initDefaults();
7436
+ };
6987
7437
  _self._onError = function (payload, message, event) {
6988
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
7438
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
6989
7439
  _self._buffer.clearSent(payload);
6990
7440
  };
6991
7441
  _self._onPartialSuccess = function (payload, results) {
@@ -7010,7 +7460,7 @@ var Sender = /** @class */ (function (_super) {
7010
7460
  }
7011
7461
  if (retry.length > 0) {
7012
7462
  _resendPayload(retry);
7013
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
7463
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
7014
7464
  "Delivered: " + payload.length + ", Failed: " + failed.length +
7015
7465
  ". Will retry to send " + retry.length + " our of " + results.itemsReceived + " items");
7016
7466
  }
@@ -7055,18 +7505,18 @@ var Sender = /** @class */ (function (_super) {
7055
7505
  }
7056
7506
  if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
7057
7507
  _resendPayload(payload);
7058
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7508
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7059
7509
  "Response code " + status + ". Will retry to send " + payload.length + " items.");
7060
7510
  }
7061
7511
  else {
7062
7512
  _self._onError(payload, errorMessage);
7063
7513
  }
7064
7514
  }
7065
- else if (Offline.isOffline()) {
7515
+ else if (_offlineListener && !_offlineListener.isOnline()) {
7066
7516
  if (!_self._senderConfig.isRetryDisabled()) {
7067
7517
  var offlineBackOffMultiplier = 10;
7068
7518
  _resendPayload(payload, offlineBackOffMultiplier);
7069
- _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."));
7519
+ _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."));
7070
7520
  }
7071
7521
  }
7072
7522
  else {
@@ -7133,8 +7583,8 @@ var Sender = /** @class */ (function (_super) {
7133
7583
  }
7134
7584
  }
7135
7585
  if (droppedPayload.length > 0) {
7136
- _fallbackSender(droppedPayload, true);
7137
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
7586
+ _fallbackSender && _fallbackSender(droppedPayload, true);
7587
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
7138
7588
  }
7139
7589
  }
7140
7590
  }
@@ -7175,7 +7625,7 @@ var Sender = /** @class */ (function (_super) {
7175
7625
  }
7176
7626
  else {
7177
7627
  _fallbackSender && _fallbackSender(payload, true);
7178
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
7628
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
7179
7629
  }
7180
7630
  }
7181
7631
  }
@@ -7266,7 +7716,7 @@ var Sender = /** @class */ (function (_super) {
7266
7716
  }
7267
7717
  }
7268
7718
  catch (e) {
7269
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
7719
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
7270
7720
  response: response
7271
7721
  });
7272
7722
  }
@@ -7337,7 +7787,7 @@ var Sender = /** @class */ (function (_super) {
7337
7787
  xdr.onerror = function (event) { return _self._onError(payload, _formatErrorMessageXdr(xdr), event); };
7338
7788
  var hostingProtocol = _window && _window.location && _window.location.protocol || "";
7339
7789
  if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
7340
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7790
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
7341
7791
  "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
7342
7792
  buffer.clear();
7343
7793
  return;
@@ -7368,7 +7818,7 @@ var Sender = /** @class */ (function (_super) {
7368
7818
  manager.eventsSendRequest(sendRequest, isAsync);
7369
7819
  }
7370
7820
  catch (e) {
7371
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
7821
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
7372
7822
  }
7373
7823
  }
7374
7824
  }
@@ -7381,6 +7831,25 @@ var Sender = /** @class */ (function (_super) {
7381
7831
  var regexp = new RegExp(UUID_Regex);
7382
7832
  return regexp.test(config.instrumentationKey);
7383
7833
  }
7834
+ function _initDefaults() {
7835
+ _self._sender = null;
7836
+ _self._buffer = null;
7837
+ _self._appId = null;
7838
+ _self._sample = null;
7839
+ _headers = {};
7840
+ _offlineListener = null;
7841
+ _consecutiveErrors = 0;
7842
+ _retryAt = null;
7843
+ _lastSend = null;
7844
+ _paused = false;
7845
+ _timeoutHandle = null;
7846
+ _serializer = null;
7847
+ _stamp_specific_redirects = 0;
7848
+ _syncFetchPayload = 0;
7849
+ _fallbackSender = null;
7850
+ _syncUnloadSender = null;
7851
+ _evtNamespace = null;
7852
+ }
7384
7853
  });
7385
7854
  return _this;
7386
7855
  }
@@ -7550,7 +8019,7 @@ var Device = /** @class */ (function () {
7550
8019
  return Device;
7551
8020
  }());
7552
8021
 
7553
- var Version = "2.8.0-beta.2203-02";
8022
+ var Version = "2.8.0-beta.2203-05";
7554
8023
  var Internal = /** @class */ (function () {
7555
8024
  function Internal(config) {
7556
8025
  this.sdkVersion = (config.sdkExtension && config.sdkExtension() ? config.sdkExtension() + "_" : "") + "javascript:" + Version;
@@ -8973,7 +9442,7 @@ var Initialization = /** @class */ (function () {
8973
9442
  config.endpointUrl = ingest ? "".concat(ingest, "/v2/track") : config.endpointUrl;
8974
9443
  config.instrumentationKey = cs.instrumentationkey || config.instrumentationKey;
8975
9444
  }
8976
- _self.appInsights = new ApplicationInsights();
9445
+ _self.appInsights = new AnalyticsPlugin();
8977
9446
  _self.properties = new PropertiesPlugin$1();
8978
9447
  _self.dependencies = new AjaxMonitor();
8979
9448
  _self.core = new AppInsightsCore();