@microsoft/applicationinsights-core-js 2.7.5-nightly.2203-01 → 2.7.5-nightly.2204-03

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 (160) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1999 -793
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +15679 -8835
  7. package/dist/applicationinsights-core-js.api.md +425 -48
  8. package/dist/applicationinsights-core-js.d.ts +784 -123
  9. package/dist/applicationinsights-core-js.js +1999 -793
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +784 -123
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +496 -99
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +120 -21
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +202 -87
  21. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js +4 -4
  24. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js +7 -148
  26. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  27. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
  28. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
  29. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  30. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +25 -12
  31. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/EnvUtils.js +13 -12
  33. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/EventHelpers.js +477 -0
  35. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
  36. package/dist-esm/JavaScriptSDK/HelperFuncs.js +89 -86
  37. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
  39. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  40. package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
  41. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
  42. package/dist-esm/JavaScriptSDK/NotificationManager.js +37 -42
  43. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  44. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  45. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +430 -119
  46. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  47. package/dist-esm/JavaScriptSDK/RandomHelper.js +30 -4
  48. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  49. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +60 -14
  50. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  51. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +81 -0
  52. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
  53. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +33 -0
  54. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  55. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  57. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  58. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  60. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  61. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +8 -0
  62. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +1 -0
  63. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
  64. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  75. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
  77. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
  78. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  79. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  80. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  81. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  82. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  83. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  84. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +8 -0
  85. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +1 -0
  86. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +6 -0
  87. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -0
  88. package/dist-esm/applicationinsights-core-js.js +12 -7
  89. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  90. package/package.json +2 -2
  91. package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
  92. package/src/JavaScriptSDK/BaseCore.ts +696 -120
  93. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +205 -31
  94. package/src/JavaScriptSDK/ChannelController.ts +242 -103
  95. package/src/JavaScriptSDK/CookieMgr.ts +7 -5
  96. package/src/JavaScriptSDK/CoreUtils.ts +8 -172
  97. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  98. package/src/JavaScriptSDK/DiagnosticLogger.ts +27 -12
  99. package/src/JavaScriptSDK/EnvUtils.ts +13 -12
  100. package/src/JavaScriptSDK/EventHelpers.ts +550 -0
  101. package/src/JavaScriptSDK/HelperFuncs.ts +123 -97
  102. package/src/JavaScriptSDK/InstrumentHooks.ts +4 -2
  103. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  104. package/src/JavaScriptSDK/NotificationManager.ts +34 -37
  105. package/src/JavaScriptSDK/PerfManager.ts +4 -7
  106. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +543 -134
  107. package/src/JavaScriptSDK/RandomHelper.ts +35 -3
  108. package/src/JavaScriptSDK/TelemetryHelpers.ts +83 -21
  109. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +111 -0
  110. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +46 -0
  111. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
  112. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  113. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  114. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +27 -0
  115. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +82 -2
  116. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +16 -5
  117. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +16 -6
  118. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +94 -14
  119. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
  120. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +28 -10
  121. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  122. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  123. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +34 -0
  124. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +17 -0
  125. package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
  126. package/types/JavaScriptSDK/BaseCore.d.ts +81 -3
  127. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +53 -10
  128. package/types/JavaScriptSDK/ChannelController.d.ts +16 -17
  129. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -48
  130. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  131. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +10 -0
  132. package/types/JavaScriptSDK/EventHelpers.d.ts +154 -0
  133. package/types/JavaScriptSDK/HelperFuncs.d.ts +33 -32
  134. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  135. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  136. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +69 -6
  137. package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
  138. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +23 -3
  139. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +16 -0
  140. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  141. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
  142. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  143. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
  144. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +20 -0
  145. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +72 -1
  146. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +16 -5
  147. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +9 -0
  148. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +82 -11
  149. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
  150. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +25 -8
  151. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  152. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  153. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +22 -0
  154. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +13 -0
  155. package/types/applicationinsights-core-js.d.ts +18 -9
  156. package/types/tsdoc-metadata.json +1 -1
  157. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
  158. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
  159. package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
  160. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.7.5-nightly.2203-01
2
+ * Application Insights JavaScript SDK - Core, 2.7.5-nightly.2204-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -8,18 +8,24 @@
8
8
  import { __spreadArrayFn as __spreadArray } from "@microsoft/applicationinsights-shims";
9
9
  import { objCreateFn } from "@microsoft/applicationinsights-shims";
10
10
  import dynamicProto from "@microsoft/dynamicproto-js";
11
- import { ChannelController } from "./ChannelController";
12
- import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
13
- import { initializePlugins, sortPlugins } from "./TelemetryHelpers";
14
- import { LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
11
+ import { createProcessTelemetryContext, createProcessTelemetryUnloadContext, createProcessTelemetryUpdateContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
12
+ import { initializePlugins, sortPlugins, _getPluginState } from "./TelemetryHelpers";
15
13
  import { getGblPerfMgr, PerfManager } from "./PerfManager";
16
14
  import { createCookieMgr } from "./CookieMgr";
17
- import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction } from "./HelperFuncs";
15
+ import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction, objFreeze, proxyFunctionAs, proxyFunctions } from "./HelperFuncs";
18
16
  import { strExtensionConfig, strIKey } from "./Constants";
19
- import { DiagnosticLogger } from "./DiagnosticLogger";
17
+ import { DiagnosticLogger, _InternalLogMessage, _throwInternal } from "./DiagnosticLogger";
20
18
  import { getDebugListener } from "./DbgExtensionUtils";
21
- var validationError = "Extensions must provide callback to initialize";
19
+ import { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues } from "./ChannelController";
20
+ import { TelemetryInitializerPlugin } from "./TelemetryInitializerPlugin";
21
+ import { createUniqueNamespace } from "./DataCacheHelper";
22
+ import { createUnloadHandlerContainer } from "./UnloadHandlerContainer";
23
+ import { strAddNotificationListener, strDisabled, strEventsDiscarded, strEventsSendRequest, strEventsSent, strRemoveNotificationListener, strTeardown } from "./InternalConstants";
24
+ var strValidationError = "Plugins must provide initialize method";
22
25
  var strNotificationManager = "_notificationManager";
26
+ var strSdkUnloadingError = "SDK is still unloading...";
27
+ var strSdkNotInitialized = "SDK is not initialized";
28
+ // const strPluginUnloadFailed = "Failed to unload plugin";
23
29
  /**
24
30
  * Helper to create the default performance manager
25
31
  * @param core
@@ -28,22 +34,92 @@ var strNotificationManager = "_notificationManager";
28
34
  function _createPerfManager(core, notificationMgr) {
29
35
  return new PerfManager(notificationMgr);
30
36
  }
37
+ function _validateExtensions(logger, channelPriority, allExtensions) {
38
+ // Concat all available extensions
39
+ var coreExtensions = [];
40
+ // Check if any two extensions have the same priority, then warn to console
41
+ // And extract the local extensions from the
42
+ var extPriorities = {};
43
+ // Extension validation
44
+ arrForEach(allExtensions, function (ext) {
45
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
46
+ throwError(strValidationError);
47
+ }
48
+ var extPriority = ext.priority;
49
+ var identifier = ext.identifier;
50
+ if (ext && extPriority) {
51
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
52
+ logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
53
+ }
54
+ else {
55
+ // set a value
56
+ extPriorities[extPriority] = identifier;
57
+ }
58
+ }
59
+ // Split extensions to core and channelController
60
+ if (!extPriority || extPriority < channelPriority) {
61
+ // Add to core extension that will be managed by BaseCore
62
+ coreExtensions.push(ext);
63
+ }
64
+ });
65
+ return {
66
+ all: allExtensions,
67
+ core: coreExtensions
68
+ };
69
+ }
70
+ function _isPluginPresent(thePlugin, plugins) {
71
+ var exists = false;
72
+ arrForEach(plugins, function (plugin) {
73
+ if (plugin === thePlugin) {
74
+ exists = true;
75
+ return -1;
76
+ }
77
+ });
78
+ return exists;
79
+ }
80
+ function _createDummyNotificationManager() {
81
+ var _a;
82
+ return objCreateFn((_a = {},
83
+ _a[strAddNotificationListener] = function (listener) { },
84
+ _a[strRemoveNotificationListener] = function (listener) { },
85
+ _a[strEventsSent] = function (events) { },
86
+ _a[strEventsDiscarded] = function (events, reason) { },
87
+ _a[strEventsSendRequest] = function (sendReason, isAsync) { },
88
+ _a));
89
+ }
31
90
  var BaseCore = /** @class */ (function () {
32
91
  function BaseCore() {
33
- var _isInitialized = false;
92
+ // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
93
+ var _isInitialized;
34
94
  var _eventQueue;
35
- var _channelController;
36
95
  var _notificationManager;
37
96
  var _perfManager;
97
+ var _cfgPerfManager;
38
98
  var _cookieManager;
99
+ var _pluginChain;
100
+ var _configExtensions;
101
+ var _coreExtensions;
102
+ var _channelControl;
103
+ var _channelConfig;
104
+ var _channelQueue;
105
+ var _isUnloading;
106
+ var _telemetryInitializerPlugin;
107
+ var _internalLogsEventName;
108
+ var _evtNamespace;
109
+ var _unloadHandlers;
110
+ var _debugListener;
111
+ /**
112
+ * Internal log poller
113
+ */
114
+ var _internalLogPoller = 0;
39
115
  dynamicProto(BaseCore, this, function (_self) {
40
- _self._extensions = new Array();
41
- _channelController = new ChannelController();
42
- // Use a default logger so initialization errors are not dropped on the floor with full logging
43
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
44
- _eventQueue = [];
116
+ // Set the default values (also called during teardown)
117
+ _initDefaults();
45
118
  _self.isInitialized = function () { return _isInitialized; };
46
119
  _self.initialize = function (config, extensions, logger, notificationManager) {
120
+ if (_isUnloading) {
121
+ throwError(strSdkUnloadingError);
122
+ }
47
123
  // Make sure core is only initialized once
48
124
  if (_self.isInitialized()) {
49
125
  throwError("Core should not be initialized more than once");
@@ -55,76 +131,33 @@ var BaseCore = /** @class */ (function () {
55
131
  // For backward compatibility only
56
132
  _self[strNotificationManager] = notificationManager;
57
133
  _self.config = config || {};
58
- if (notificationManager && _self.config.disableDbgExt !== true) {
59
- notificationManager.addNotificationListener(getDebugListener(config));
60
- }
61
- if (_self.config.enablePerfMgr) {
62
- // Set the performance manager creation function if not defined
63
- setValue(_self.config, "createPerfMgr", _createPerfManager);
64
- }
134
+ _initDebugListener(config);
135
+ _initPerfManager(config);
65
136
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
66
137
  // add notification to the extensions in the config so other plugins can access it
67
- var extConfig = getSetValue(config, strExtensionConfig);
68
- extConfig.NotificationManager = notificationManager;
138
+ _initExtConfig(config);
69
139
  if (logger) {
70
140
  _self.logger = logger;
71
141
  }
72
- // Concat all available extensions
73
- var allExtensions = [];
74
- allExtensions.push.apply(allExtensions, __spreadArray(__spreadArray([], extensions, false), config.extensions, false));
75
- allExtensions = sortPlugins(allExtensions);
76
- var coreExtensions = [];
77
- var channelExtensions = [];
78
- // Check if any two extensions have the same priority, then warn to console
79
- // And extract the local extensions from the
80
- var extPriorities = {};
81
142
  // Extension validation
82
- arrForEach(allExtensions, function (ext) {
83
- if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
84
- throwError(validationError);
85
- }
86
- var extPriority = ext.priority;
87
- var identifier = ext.identifier;
88
- if (ext && extPriority) {
89
- if (!isNullOrUndefined(extPriorities[extPriority])) {
90
- logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
91
- }
92
- else {
93
- // set a value
94
- extPriorities[extPriority] = identifier;
95
- }
96
- }
97
- // Split extensions to core and channelController
98
- if (!extPriority || extPriority < _channelController.priority) {
99
- // Add to core extension that will be managed by BaseCore
100
- coreExtensions.push(ext);
101
- }
102
- else {
103
- // Add all other extensions to be managed by the channel controller
104
- channelExtensions.push(ext);
105
- }
106
- });
107
- // Validation complete
108
- // Add the channelController to the complete extension collection and
109
- // to the end of the core extensions
110
- allExtensions.push(_channelController);
111
- coreExtensions.push(_channelController);
112
- // Sort the complete set of extensions by priority
113
- allExtensions = sortPlugins(allExtensions);
114
- _self._extensions = allExtensions;
115
- // initialize channel controller first, this will initialize all channel plugins
116
- initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);
117
- initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);
118
- // Now reset the extensions to just those being managed by Basecore
119
- _self._extensions = coreExtensions;
120
- if (_self.getTransmissionControls().length === 0) {
143
+ _configExtensions = [];
144
+ _configExtensions.push.apply(_configExtensions, __spreadArray(__spreadArray([], extensions, false), config.extensions, false));
145
+ _channelConfig = (config || {}).channels;
146
+ _initPluginChain(config, null);
147
+ if (!_channelQueue || _channelQueue.length === 0) {
121
148
  throwError("No channels available");
122
149
  }
123
150
  _isInitialized = true;
124
151
  _self.releaseQueue();
125
152
  };
126
153
  _self.getTransmissionControls = function () {
127
- return _channelController.getChannelControls();
154
+ var controls = [];
155
+ if (_channelQueue) {
156
+ arrForEach(_channelQueue, function (channels) {
157
+ controls.push(channels.queue);
158
+ });
159
+ }
160
+ return objFreeze(controls);
128
161
  };
129
162
  _self.track = function (telemetryItem) {
130
163
  // setup default iKey if not passed in
@@ -133,40 +166,45 @@ var BaseCore = /** @class */ (function () {
133
166
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
134
167
  // Common Schema 4.0
135
168
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
136
- if (_self.isInitialized()) {
169
+ if (!_isUnloading && _self.isInitialized()) {
137
170
  // Process the telemetry plugin chain
138
- _self.getProcessTelContext().processNext(telemetryItem);
171
+ _createTelCtx().processNext(telemetryItem);
139
172
  }
140
173
  else {
141
174
  // Queue events until all extensions are initialized
142
175
  _eventQueue.push(telemetryItem);
143
176
  }
144
177
  };
145
- _self.getProcessTelContext = function () {
146
- var extensions = _self._extensions;
147
- var thePlugins = extensions;
148
- // invoke any common telemetry processors before sending through pipeline
149
- if (!extensions || extensions.length === 0) {
150
- // Pass to Channel controller so data is sent to correct channel queues
151
- thePlugins = [_channelController];
152
- }
153
- return new ProcessTelemetryContext(thePlugins, _self.config, _self);
154
- };
178
+ _self.getProcessTelContext = _createTelCtx;
155
179
  _self.getNotifyMgr = function () {
156
180
  if (!_notificationManager) {
157
181
  // Create Dummy notification manager
158
- _notificationManager = objCreateFn({
159
- addNotificationListener: function (listener) { },
160
- removeNotificationListener: function (listener) { },
161
- eventsSent: function (events) { },
162
- eventsDiscarded: function (events, reason) { },
163
- eventsSendRequest: function (sendReason, isAsync) { }
164
- });
182
+ _notificationManager = _createDummyNotificationManager();
165
183
  // For backward compatibility only
166
184
  _self[strNotificationManager] = _notificationManager;
167
185
  }
168
186
  return _notificationManager;
169
187
  };
188
+ /**
189
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
190
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
191
+ * called.
192
+ * @param {INotificationListener} listener - An INotificationListener object.
193
+ */
194
+ _self[strAddNotificationListener] = function (listener) {
195
+ if (_notificationManager) {
196
+ _notificationManager[strAddNotificationListener](listener);
197
+ }
198
+ };
199
+ /**
200
+ * Removes all instances of the listener.
201
+ * @param {INotificationListener} listener - INotificationListener to remove.
202
+ */
203
+ _self[strRemoveNotificationListener] = function (listener) {
204
+ if (_notificationManager) {
205
+ _notificationManager[strRemoveNotificationListener](listener);
206
+ }
207
+ };
170
208
  _self.getCookieMgr = function () {
171
209
  if (!_cookieManager) {
172
210
  _cookieManager = createCookieMgr(_self.config, _self.logger);
@@ -177,12 +215,12 @@ var BaseCore = /** @class */ (function () {
177
215
  _cookieManager = cookieMgr;
178
216
  };
179
217
  _self.getPerfMgr = function () {
180
- if (!_perfManager) {
218
+ if (!_perfManager && !_cfgPerfManager) {
181
219
  if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
182
- _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
220
+ _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
183
221
  }
184
222
  }
185
- return _perfManager || getGblPerfMgr();
223
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
186
224
  };
187
225
  _self.setPerfMgr = function (perfMgr) {
188
226
  _perfManager = perfMgr;
@@ -191,13 +229,360 @@ var BaseCore = /** @class */ (function () {
191
229
  return _eventQueue.length;
192
230
  };
193
231
  _self.releaseQueue = function () {
194
- if (_eventQueue.length > 0) {
195
- arrForEach(_eventQueue, function (event) {
196
- _self.getProcessTelContext().processNext(event);
197
- });
232
+ if (_isInitialized && _eventQueue.length > 0) {
233
+ var eventQueue = _eventQueue;
198
234
  _eventQueue = [];
235
+ arrForEach(eventQueue, function (event) {
236
+ _createTelCtx().processNext(event);
237
+ });
238
+ }
239
+ };
240
+ /**
241
+ * Periodically check logger.queue for log messages to be flushed
242
+ */
243
+ _self.pollInternalLogs = function (eventName) {
244
+ _internalLogsEventName = eventName || null;
245
+ var interval = _self.config.diagnosticLogInterval;
246
+ if (!interval || !(interval > 0)) {
247
+ interval = 10000;
248
+ }
249
+ if (_internalLogPoller) {
250
+ clearInterval(_internalLogPoller);
199
251
  }
252
+ _internalLogPoller = setInterval(function () {
253
+ _flushInternalLogs();
254
+ }, interval);
255
+ return _internalLogPoller;
200
256
  };
257
+ /**
258
+ * Stop polling log messages from logger.queue
259
+ */
260
+ _self.stopPollingInternalLogs = function () {
261
+ if (_internalLogPoller) {
262
+ clearInterval(_internalLogPoller);
263
+ _internalLogPoller = 0;
264
+ _flushInternalLogs();
265
+ }
266
+ };
267
+ // Add addTelemetryInitializer
268
+ proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
269
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
270
+ if (isAsync === void 0) { isAsync = true; }
271
+ if (!_isInitialized) {
272
+ // The SDK is not initialized
273
+ throwError(strSdkNotInitialized);
274
+ }
275
+ // Check if the SDK still unloading so throw
276
+ if (_isUnloading) {
277
+ // The SDK is already unloading
278
+ throwError(strSdkUnloadingError);
279
+ }
280
+ var unloadState = {
281
+ reason: 50 /* SdkUnload */,
282
+ isAsync: isAsync,
283
+ flushComplete: false
284
+ };
285
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
286
+ processUnloadCtx.onComplete(function () {
287
+ _initDefaults();
288
+ unloadComplete && unloadComplete(unloadState);
289
+ }, _self);
290
+ function _doUnload(flushComplete) {
291
+ unloadState.flushComplete = flushComplete;
292
+ _isUnloading = true;
293
+ // Run all of the unload handlers first (before unloading the plugins)
294
+ _unloadHandlers.run(processUnloadCtx, unloadState);
295
+ // Stop polling the internal logs
296
+ _self.stopPollingInternalLogs();
297
+ // Start unloading the components, from this point onwards the SDK should be considered to be in an unstable state
298
+ processUnloadCtx.processNext(unloadState);
299
+ }
300
+ if (!_flushChannels(isAsync, _doUnload, 6 /* SdkUnload */, cbTimeout)) {
301
+ _doUnload(false);
302
+ }
303
+ };
304
+ _self.getPlugin = _getPlugin;
305
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
306
+ if (!plugin) {
307
+ addCb && addCb(false);
308
+ _logOrThrowError(strValidationError);
309
+ return;
310
+ }
311
+ var existingPlugin = _getPlugin(plugin.identifier);
312
+ if (existingPlugin && !replaceExisting) {
313
+ addCb && addCb(false);
314
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
315
+ return;
316
+ }
317
+ var updateState = {
318
+ reason: 16 /* PluginAdded */
319
+ };
320
+ function _addPlugin(removed) {
321
+ _configExtensions.push(plugin);
322
+ updateState.added = [plugin];
323
+ // Re-Initialize the plugin chain
324
+ _initPluginChain(_self.config, updateState);
325
+ addCb && addCb(true);
326
+ }
327
+ if (existingPlugin) {
328
+ var removedPlugins_1 = [existingPlugin.plugin];
329
+ var unloadState = {
330
+ reason: 2 /* PluginReplace */,
331
+ isAsync: !!isAsync
332
+ };
333
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
334
+ if (!removed) {
335
+ // Previous plugin was successfully removed or was not installed
336
+ addCb && addCb(false);
337
+ }
338
+ else {
339
+ updateState.removed = removedPlugins_1;
340
+ updateState.reason |= 32 /* PluginRemoved */;
341
+ _addPlugin(true);
342
+ }
343
+ });
344
+ }
345
+ else {
346
+ _addPlugin(false);
347
+ }
348
+ };
349
+ _self.evtNamespace = function () {
350
+ return _evtNamespace;
351
+ };
352
+ _self.flush = _flushChannels;
353
+ // Create the addUnloadCb
354
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
355
+ function _initDefaults() {
356
+ _isInitialized = false;
357
+ // Use a default logger so initialization errors are not dropped on the floor with full logging
358
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 /* CRITICAL */ });
359
+ _self.config = {};
360
+ _self._extensions = [];
361
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
362
+ _eventQueue = [];
363
+ _notificationManager = null;
364
+ _perfManager = null;
365
+ _cfgPerfManager = null;
366
+ _cookieManager = null;
367
+ _pluginChain = null;
368
+ _coreExtensions = null;
369
+ _configExtensions = [];
370
+ _channelControl = null;
371
+ _channelConfig = null;
372
+ _channelQueue = null;
373
+ _isUnloading = false;
374
+ _internalLogsEventName = null;
375
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
376
+ _unloadHandlers = createUnloadHandlerContainer();
377
+ }
378
+ function _createTelCtx() {
379
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
380
+ }
381
+ // Initialize or Re-initialize the plugins
382
+ function _initPluginChain(config, updateState) {
383
+ // Extension validation
384
+ var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
385
+ _coreExtensions = theExtensions.core;
386
+ _pluginChain = null;
387
+ // Sort the complete set of extensions by priority
388
+ var allExtensions = theExtensions.all;
389
+ // Initialize the Channel Queues and the channel plugins first
390
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
391
+ if (_channelControl) {
392
+ // During add / remove of a plugin this may get called again, so don't re-add if already present
393
+ // But we also want the controller as the last, so remove if already present
394
+ // And reusing the existing instance, just in case an installed plugin has a reference and
395
+ // is using it.
396
+ var idx = allExtensions.indexOf(_channelControl);
397
+ if (idx !== -1) {
398
+ allExtensions.splice(idx, 1);
399
+ }
400
+ idx = _coreExtensions.indexOf(_channelControl);
401
+ if (idx !== -1) {
402
+ _coreExtensions.splice(idx, 1);
403
+ }
404
+ _channelControl._setQueue(_channelQueue);
405
+ }
406
+ else {
407
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
408
+ }
409
+ // Add on "channelController" as the last "plugin"
410
+ allExtensions.push(_channelControl);
411
+ _coreExtensions.push(_channelControl);
412
+ // Required to allow plugins to call core.getPlugin() during their own initialization
413
+ _self._extensions = sortPlugins(allExtensions);
414
+ // Initialize the controls
415
+ _channelControl.initialize(config, _self, allExtensions);
416
+ initializePlugins(_createTelCtx(), allExtensions);
417
+ // Now reset the extensions to just those being managed by Basecore
418
+ _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
419
+ if (updateState) {
420
+ _doUpdate(updateState);
421
+ }
422
+ }
423
+ function _getPlugin(pluginIdentifier) {
424
+ var theExt = null;
425
+ var thePlugin = null;
426
+ arrForEach(_self._extensions, function (ext) {
427
+ if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
428
+ thePlugin = ext;
429
+ return -1;
430
+ }
431
+ });
432
+ if (!thePlugin && _channelControl) {
433
+ // Check the channel Controller
434
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
435
+ }
436
+ if (thePlugin) {
437
+ theExt = {
438
+ plugin: thePlugin,
439
+ setEnabled: function (enabled) {
440
+ _getPluginState(thePlugin)[strDisabled] = !enabled;
441
+ },
442
+ isEnabled: function () {
443
+ var pluginState = _getPluginState(thePlugin);
444
+ return !pluginState[strTeardown] && !pluginState[strDisabled];
445
+ },
446
+ remove: function (isAsync, removeCb) {
447
+ if (isAsync === void 0) { isAsync = true; }
448
+ var pluginsToRemove = [thePlugin];
449
+ var unloadState = {
450
+ reason: 1 /* PluginUnload */,
451
+ isAsync: isAsync
452
+ };
453
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
454
+ if (removed) {
455
+ // Re-Initialize the plugin chain
456
+ _initPluginChain(_self.config, {
457
+ reason: 32 /* PluginRemoved */,
458
+ removed: pluginsToRemove
459
+ });
460
+ }
461
+ removeCb && removeCb(removed);
462
+ });
463
+ }
464
+ };
465
+ }
466
+ return theExt;
467
+ }
468
+ function _getPluginChain() {
469
+ if (!_pluginChain) {
470
+ // copy the collection of extensions
471
+ var extensions = (_coreExtensions || []).slice();
472
+ // During add / remove this may get called again, so don't readd if already present
473
+ if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
474
+ extensions.push(_telemetryInitializerPlugin);
475
+ }
476
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
477
+ }
478
+ return _pluginChain;
479
+ }
480
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
481
+ if (thePlugins && thePlugins.length > 0) {
482
+ var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
483
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
484
+ unloadCtx.onComplete(function () {
485
+ var removed = false;
486
+ // Remove the listed config extensions
487
+ var newConfigExtensions = [];
488
+ arrForEach(_configExtensions, function (plugin, idx) {
489
+ if (!_isPluginPresent(plugin, thePlugins)) {
490
+ newConfigExtensions.push(plugin);
491
+ }
492
+ else {
493
+ removed = true;
494
+ }
495
+ });
496
+ _configExtensions = newConfigExtensions;
497
+ // Re-Create the channel config
498
+ var newChannelConfig = [];
499
+ if (_channelConfig) {
500
+ arrForEach(_channelConfig, function (queue, idx) {
501
+ var newQueue = [];
502
+ arrForEach(queue, function (channel) {
503
+ if (!_isPluginPresent(channel, thePlugins)) {
504
+ newQueue.push(channel);
505
+ }
506
+ else {
507
+ removed = true;
508
+ }
509
+ });
510
+ newChannelConfig.push(newQueue);
511
+ });
512
+ _channelConfig = newChannelConfig;
513
+ }
514
+ removeComplete && removeComplete(removed);
515
+ });
516
+ unloadCtx.processNext(unloadState);
517
+ }
518
+ else {
519
+ removeComplete(false);
520
+ }
521
+ }
522
+ function _flushInternalLogs() {
523
+ var queue = _self.logger ? _self.logger.queue : [];
524
+ if (queue) {
525
+ arrForEach(queue, function (logMessage) {
526
+ var item = {
527
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
528
+ iKey: _self.config.instrumentationKey,
529
+ time: toISOString(new Date()),
530
+ baseType: _InternalLogMessage.dataType,
531
+ baseData: { message: logMessage.message }
532
+ };
533
+ _self.track(item);
534
+ });
535
+ queue.length = 0;
536
+ }
537
+ }
538
+ function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
539
+ if (_channelControl) {
540
+ return _channelControl.flush(isAsync, callBack, sendReason || 6 /* SdkUnload */, cbTimeout);
541
+ }
542
+ callBack && callBack(false);
543
+ return true;
544
+ }
545
+ function _initDebugListener(config) {
546
+ if (config.disableDbgExt === true && _debugListener) {
547
+ // Remove any previously loaded debug listener
548
+ _notificationManager[strRemoveNotificationListener](_debugListener);
549
+ _debugListener = null;
550
+ }
551
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
552
+ _debugListener = getDebugListener(config);
553
+ _notificationManager[strAddNotificationListener](_debugListener);
554
+ }
555
+ }
556
+ function _initPerfManager(config) {
557
+ if (!config.enablePerfMgr && _cfgPerfManager) {
558
+ // Remove any existing config based performance manager
559
+ _cfgPerfManager = null;
560
+ }
561
+ if (config.enablePerfMgr) {
562
+ // Set the performance manager creation function if not defined
563
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
564
+ }
565
+ }
566
+ function _initExtConfig(config) {
567
+ var extConfig = getSetValue(config, strExtensionConfig);
568
+ extConfig.NotificationManager = _notificationManager;
569
+ }
570
+ function _doUpdate(updateState) {
571
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
572
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
573
+ updateCtx.processNext(updateState);
574
+ }
575
+ }
576
+ function _logOrThrowError(message) {
577
+ var logger = _self.logger;
578
+ if (logger) {
579
+ // there should always be a logger
580
+ _throwInternal(logger, 2 /* WARNING */, 73 /* PluginException */, message);
581
+ }
582
+ else {
583
+ throwError(message);
584
+ }
585
+ }
201
586
  });
202
587
  }
203
588
  // Removed Stub for BaseCore.prototype.initialize.
@@ -205,12 +590,24 @@ var BaseCore = /** @class */ (function () {
205
590
  // Removed Stub for BaseCore.prototype.track.
206
591
  // Removed Stub for BaseCore.prototype.getProcessTelContext.
207
592
  // Removed Stub for BaseCore.prototype.getNotifyMgr.
593
+ // Removed Stub for BaseCore.prototype.addNotificationListener.
594
+ // Removed Stub for BaseCore.prototype.removeNotificationListener.
208
595
  // Removed Stub for BaseCore.prototype.getCookieMgr.
209
596
  // Removed Stub for BaseCore.prototype.setCookieMgr.
210
597
  // Removed Stub for BaseCore.prototype.getPerfMgr.
211
598
  // Removed Stub for BaseCore.prototype.setPerfMgr.
212
599
  // Removed Stub for BaseCore.prototype.eventCnt.
600
+ // Removed Stub for BaseCore.prototype.pollInternalLogs.
601
+ // Removed Stub for BaseCore.prototype.stopPollingInternalLogs.
602
+ // Removed Stub for BaseCore.prototype.addTelemetryInitializer.
603
+ // Removed Stub for BaseCore.prototype.unload.
604
+ // Removed Stub for BaseCore.prototype.getPlugin.
605
+ // Removed Stub for BaseCore.prototype.addPlugin.
606
+ // Removed Stub for BaseCore.prototype.evtNamespace.
607
+ // Removed Stub for BaseCore.prototype.addUnloadCb.
608
+ // Removed Stub for BaseCore.prototype.flush.
213
609
  // Removed Stub for BaseCore.prototype.releaseQueue.
610
+ // Removed Stub for BaseCore.prototype._updateHook.
214
611
  return BaseCore;
215
612
  }());
216
613
  export { BaseCore };