@microsoft/applicationinsights-core-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-04

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 +16363 -9167
  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
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { objCreateFn } from "@microsoft/applicationinsights-shims";
6
6
  import dynamicProto from "@microsoft/dynamicproto-js";
7
- import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore"
7
+ import { IAppInsightsCore, ILoadedPlugin } from "../JavaScriptSDK.Interfaces/IAppInsightsCore"
8
8
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
9
9
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
10
10
  import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
@@ -12,23 +12,36 @@ import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
12
12
  import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
13
13
  import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
14
14
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
15
- import { ChannelController } from "./ChannelController";
16
- import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
17
- import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
18
- import { initializePlugins, sortPlugins } from "./TelemetryHelpers";
19
- import { _InternalMessageId, LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
15
+ import { IProcessTelemetryContext, IProcessTelemetryUpdateContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
16
+ import { createProcessTelemetryContext, createProcessTelemetryUnloadContext, createProcessTelemetryUpdateContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
17
+ import { initializePlugins, sortPlugins, _getPluginState } from "./TelemetryHelpers";
18
+ import { eLoggingSeverity, _eInternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
20
19
  import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
21
20
  import { getGblPerfMgr, PerfManager } from "./PerfManager";
22
21
  import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
23
22
  import { createCookieMgr } from "./CookieMgr";
24
- import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction } from "./HelperFuncs";
23
+ import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction, objFreeze, proxyFunctionAs, proxyFunctions } from "./HelperFuncs";
25
24
  import { strExtensionConfig, strIKey } from "./Constants";
26
- import { DiagnosticLogger } from "./DiagnosticLogger";
25
+ import { DiagnosticLogger, _InternalLogMessage, _throwInternal } from "./DiagnosticLogger";
27
26
  import { getDebugListener } from "./DbgExtensionUtils";
28
-
29
- const validationError = "Extensions must provide callback to initialize";
30
-
27
+ import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
28
+ import { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues, IChannelController, IInternalChannelController, _IInternalChannels } from "./ChannelController";
29
+ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
30
+ import { TelemetryInitializerPlugin } from "./TelemetryInitializerPlugin";
31
+ import { createUniqueNamespace } from "./DataCacheHelper";
32
+ import { createUnloadHandlerContainer, IUnloadHandlerContainer, UnloadHandler } from "./UnloadHandlerContainer";
33
+ import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
34
+ import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
35
+ import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
36
+ import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
37
+ import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
38
+ import { strAddNotificationListener, strDisabled, strEventsDiscarded, strEventsSendRequest, strEventsSent, strRemoveNotificationListener, strTeardown } from "./InternalConstants";
39
+
40
+ const strValidationError = "Plugins must provide initialize method";
31
41
  const strNotificationManager = "_notificationManager";
42
+ const strSdkUnloadingError = "SDK is still unloading...";
43
+ const strSdkNotInitialized = "SDK is not initialized";
44
+ // const strPluginUnloadFailed = "Failed to unload plugin";
32
45
 
33
46
  /**
34
47
  * Helper to create the default performance manager
@@ -39,6 +52,68 @@ function _createPerfManager (core: IAppInsightsCore, notificationMgr: INotificat
39
52
  return new PerfManager(notificationMgr);
40
53
  }
41
54
 
55
+ function _validateExtensions(logger: IDiagnosticLogger, channelPriority: number, allExtensions: IPlugin[]): { all: IPlugin[]; core: ITelemetryPlugin[] } {
56
+ // Concat all available extensions
57
+ let coreExtensions: ITelemetryPlugin[] = [];
58
+
59
+ // Check if any two extensions have the same priority, then warn to console
60
+ // And extract the local extensions from the
61
+ let extPriorities = {};
62
+
63
+ // Extension validation
64
+ arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
65
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
66
+ throwError(strValidationError);
67
+ }
68
+
69
+ const extPriority = ext.priority;
70
+ const identifier = ext.identifier;
71
+
72
+ if (ext && extPriority) {
73
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
74
+ logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
75
+ } else {
76
+ // set a value
77
+ extPriorities[extPriority] = identifier;
78
+ }
79
+ }
80
+
81
+ // Split extensions to core and channelController
82
+ if (!extPriority || extPriority < channelPriority) {
83
+ // Add to core extension that will be managed by BaseCore
84
+ coreExtensions.push(ext);
85
+ }
86
+ });
87
+
88
+ return {
89
+ all: allExtensions,
90
+ core: coreExtensions
91
+ };
92
+ }
93
+
94
+ function _isPluginPresent(thePlugin: IPlugin, plugins: IPlugin[]) {
95
+ let exists = false;
96
+
97
+ arrForEach(plugins, (plugin) => {
98
+ if (plugin === thePlugin) {
99
+ exists = true;
100
+ return -1;
101
+ }
102
+ });
103
+
104
+ return exists;
105
+ }
106
+
107
+ function _createDummyNotificationManager(): INotificationManager {
108
+ return objCreateFn({
109
+ [strAddNotificationListener]: (listener: INotificationListener) => { },
110
+ [strRemoveNotificationListener]: (listener: INotificationListener) => { },
111
+ [strEventsSent]: (events: ITelemetryItem[]) => { },
112
+ [strEventsDiscarded]: (events: ITelemetryItem[], reason: number) => { },
113
+ [strEventsSendRequest]: (sendReason: number, isAsync: boolean) => { }
114
+ });
115
+ }
116
+
42
117
  export class BaseCore implements IAppInsightsCore {
43
118
  public static defaultConfig: IConfiguration;
44
119
  public config: IConfiguration;
@@ -48,28 +123,48 @@ export class BaseCore implements IAppInsightsCore {
48
123
  public isInitialized: () => boolean;
49
124
 
50
125
  constructor() {
51
- let _isInitialized = false;
126
+ // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
127
+ let _isInitialized: boolean;
52
128
  let _eventQueue: ITelemetryItem[];
53
- let _channelController: ChannelController;
54
- let _notificationManager: INotificationManager;
55
- let _perfManager: IPerfManager;
56
- let _cookieManager: ICookieMgr;
57
-
129
+ let _notificationManager: INotificationManager | null | undefined;
130
+ let _perfManager: IPerfManager | null;
131
+ let _cfgPerfManager: IPerfManager | null;
132
+ let _cookieManager: ICookieMgr | null;
133
+ let _pluginChain: ITelemetryPluginChain | null;
134
+ let _configExtensions: IPlugin[];
135
+ let _coreExtensions: ITelemetryPlugin[] | null;
136
+ let _channelControl: IChannelController | null;
137
+ let _channelConfig: IChannelControls[][] | null | undefined;
138
+ let _channelQueue: _IInternalChannels[] | null;
139
+ let _isUnloading: boolean;
140
+ let _telemetryInitializerPlugin: TelemetryInitializerPlugin;
141
+ let _internalLogsEventName: string | null;
142
+ let _evtNamespace: string;
143
+ let _unloadHandlers: IUnloadHandlerContainer;
144
+ let _debugListener: INotificationListener | null;
145
+
146
+ /**
147
+ * Internal log poller
148
+ */
149
+ let _internalLogPoller: number = 0;
150
+
58
151
  dynamicProto(BaseCore, this, (_self) => {
59
- _self._extensions = new Array<IPlugin>();
60
- _channelController = new ChannelController();
61
- // Use a default logger so initialization errors are not dropped on the floor with full logging
62
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
63
-
64
- _eventQueue = [];
152
+
153
+ // Set the default values (also called during teardown)
154
+ _initDefaults();
155
+
65
156
  _self.isInitialized = () => _isInitialized;
66
157
 
67
158
  _self.initialize = (config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void => {
159
+ if (_isUnloading) {
160
+ throwError(strSdkUnloadingError);
161
+ }
162
+
68
163
  // Make sure core is only initialized once
69
164
  if (_self.isInitialized()) {
70
165
  throwError("Core should not be initialized more than once");
71
166
  }
72
-
167
+
73
168
  if (!config || isNullOrUndefined(config.instrumentationKey)) {
74
169
  throwError("Please provide instrumentation key");
75
170
  }
@@ -80,83 +175,26 @@ export class BaseCore implements IAppInsightsCore {
80
175
  _self[strNotificationManager] = notificationManager;
81
176
  _self.config = config || {};
82
177
 
83
- if (notificationManager && _self.config.disableDbgExt !== true) {
84
- notificationManager.addNotificationListener(getDebugListener(config));
85
- }
86
-
87
- if (_self.config.enablePerfMgr) {
88
- // Set the performance manager creation function if not defined
89
- setValue(_self.config, "createPerfMgr", _createPerfManager);
90
- }
178
+ _initDebugListener(config);
179
+ _initPerfManager(config);
91
180
 
92
181
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
93
182
 
94
183
  // add notification to the extensions in the config so other plugins can access it
95
- let extConfig = getSetValue(config, strExtensionConfig);
96
- extConfig.NotificationManager = notificationManager;
184
+ _initExtConfig(config);
97
185
 
98
186
  if (logger) {
99
187
  _self.logger = logger;
100
188
  }
101
189
 
102
- // Concat all available extensions
103
- let allExtensions = [];
104
- allExtensions.push(...extensions, ...config.extensions);
105
- allExtensions = sortPlugins(allExtensions);
106
-
107
- let coreExtensions: any[] = [];
108
- let channelExtensions: any[] = [];
109
-
110
- // Check if any two extensions have the same priority, then warn to console
111
- // And extract the local extensions from the
112
- const extPriorities = {};
113
-
114
190
  // Extension validation
115
- arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
116
- if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
117
- throwError(validationError);
118
- }
119
-
120
- const extPriority = ext.priority;
121
- const identifier = ext.identifier;
122
-
123
- if (ext && extPriority) {
124
- if (!isNullOrUndefined(extPriorities[extPriority])) {
125
- logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
126
- } else {
127
- // set a value
128
- extPriorities[extPriority] = identifier;
129
- }
130
- }
131
-
132
- // Split extensions to core and channelController
133
- if (!extPriority || extPriority < _channelController.priority) {
134
- // Add to core extension that will be managed by BaseCore
135
- coreExtensions.push(ext);
136
- } else {
137
- // Add all other extensions to be managed by the channel controller
138
- channelExtensions.push(ext);
139
- }
140
- });
141
- // Validation complete
142
-
143
- // Add the channelController to the complete extension collection and
144
- // to the end of the core extensions
145
- allExtensions.push(_channelController);
146
- coreExtensions.push(_channelController);
147
-
148
- // Sort the complete set of extensions by priority
149
- allExtensions = sortPlugins(allExtensions);
150
- _self._extensions = allExtensions;
151
-
152
- // initialize channel controller first, this will initialize all channel plugins
153
- initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);
154
- initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);
155
-
156
- // Now reset the extensions to just those being managed by Basecore
157
- _self._extensions = coreExtensions;
158
-
159
- if (_self.getTransmissionControls().length === 0) {
191
+ _configExtensions = [];
192
+ _configExtensions.push(...extensions, ...config.extensions);
193
+ _channelConfig = (config||{}).channels;
194
+
195
+ _initPluginChain(config, null);
196
+
197
+ if (!_channelQueue || _channelQueue.length === 0) {
160
198
  throwError("No channels available");
161
199
  }
162
200
 
@@ -165,7 +203,14 @@ export class BaseCore implements IAppInsightsCore {
165
203
  };
166
204
 
167
205
  _self.getTransmissionControls = (): IChannelControls[][] => {
168
- return _channelController.getChannelControls();
206
+ let controls: IChannelControls[][] = [];
207
+ if (_channelQueue) {
208
+ arrForEach(_channelQueue, (channels) => {
209
+ controls.push(channels.queue);
210
+ });
211
+ }
212
+
213
+ return objFreeze(controls);
169
214
  };
170
215
 
171
216
  _self.track = (telemetryItem: ITelemetryItem) => {
@@ -178,38 +223,21 @@ export class BaseCore implements IAppInsightsCore {
178
223
  // Common Schema 4.0
179
224
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
180
225
 
181
- if (_self.isInitialized()) {
226
+ if (!_isUnloading && _self.isInitialized()) {
182
227
  // Process the telemetry plugin chain
183
- _self.getProcessTelContext().processNext(telemetryItem);
228
+ _createTelCtx().processNext(telemetryItem);
184
229
  } else {
185
230
  // Queue events until all extensions are initialized
186
231
  _eventQueue.push(telemetryItem);
187
232
  }
188
233
  };
189
234
 
190
- _self.getProcessTelContext = (): IProcessTelemetryContext => {
191
- let extensions = _self._extensions;
192
- let thePlugins: IPlugin[] = extensions;
193
-
194
- // invoke any common telemetry processors before sending through pipeline
195
- if (!extensions || extensions.length === 0) {
196
- // Pass to Channel controller so data is sent to correct channel queues
197
- thePlugins = [_channelController];
198
- }
199
-
200
- return new ProcessTelemetryContext(thePlugins, _self.config, _self);
201
- };
235
+ _self.getProcessTelContext = _createTelCtx;
202
236
 
203
237
  _self.getNotifyMgr = (): INotificationManager => {
204
238
  if (!_notificationManager) {
205
239
  // Create Dummy notification manager
206
- _notificationManager = objCreateFn({
207
- addNotificationListener: (listener: INotificationListener) => { },
208
- removeNotificationListener: (listener: INotificationListener) => { },
209
- eventsSent: (events: ITelemetryItem[]) => { },
210
- eventsDiscarded: (events: ITelemetryItem[], reason: number) => { },
211
- eventsSendRequest: (sendReason: number, isAsync: boolean) => { }
212
- });
240
+ _notificationManager = _createDummyNotificationManager();
213
241
 
214
242
  // For backward compatibility only
215
243
  _self[strNotificationManager] = _notificationManager;
@@ -217,6 +245,28 @@ export class BaseCore implements IAppInsightsCore {
217
245
 
218
246
  return _notificationManager;
219
247
  };
248
+
249
+ /**
250
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
251
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
252
+ * called.
253
+ * @param {INotificationListener} listener - An INotificationListener object.
254
+ */
255
+ _self[strAddNotificationListener] = (listener: INotificationListener): void => {
256
+ if (_notificationManager) {
257
+ _notificationManager[strAddNotificationListener](listener);
258
+ }
259
+ };
260
+
261
+ /**
262
+ * Removes all instances of the listener.
263
+ * @param {INotificationListener} listener - INotificationListener to remove.
264
+ */
265
+ _self[strRemoveNotificationListener] = (listener: INotificationListener): void => {
266
+ if (_notificationManager) {
267
+ _notificationManager[strRemoveNotificationListener](listener);
268
+ }
269
+ }
220
270
 
221
271
  _self.getCookieMgr = (): ICookieMgr => {
222
272
  if (!_cookieManager) {
@@ -231,13 +281,13 @@ export class BaseCore implements IAppInsightsCore {
231
281
  };
232
282
 
233
283
  _self.getPerfMgr = (): IPerfManager => {
234
- if (!_perfManager) {
284
+ if (!_perfManager && !_cfgPerfManager) {
235
285
  if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
236
- _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
286
+ _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
237
287
  }
238
288
  }
239
289
 
240
- return _perfManager || getGblPerfMgr();
290
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
241
291
  };
242
292
 
243
293
  _self.setPerfMgr = (perfMgr: IPerfManager) => {
@@ -249,14 +299,428 @@ export class BaseCore implements IAppInsightsCore {
249
299
  };
250
300
 
251
301
  _self.releaseQueue = () => {
252
- if (_eventQueue.length > 0) {
253
- arrForEach(_eventQueue, (event: ITelemetryItem) => {
254
- _self.getProcessTelContext().processNext(event);
302
+ if (_isInitialized && _eventQueue.length > 0) {
303
+ let eventQueue = _eventQueue;
304
+ _eventQueue = [];
305
+
306
+ arrForEach(eventQueue, (event: ITelemetryItem) => {
307
+ _createTelCtx().processNext(event);
255
308
  });
309
+ }
310
+ };
256
311
 
257
- _eventQueue = [];
312
+ /**
313
+ * Periodically check logger.queue for log messages to be flushed
314
+ */
315
+ _self.pollInternalLogs = (eventName?: string): number => {
316
+ _internalLogsEventName = eventName || null;
317
+
318
+ let interval = _self.config.diagnosticLogInterval;
319
+ if (!interval || !(interval > 0)) {
320
+ interval = 10000;
321
+ }
322
+ if(_internalLogPoller) {
323
+ clearInterval(_internalLogPoller);
324
+ }
325
+ _internalLogPoller = setInterval(() => {
326
+ _flushInternalLogs();
327
+ }, interval) as any;
328
+
329
+ return _internalLogPoller;
330
+ }
331
+
332
+ /**
333
+ * Stop polling log messages from logger.queue
334
+ */
335
+ _self.stopPollingInternalLogs = (): void => {
336
+ if(_internalLogPoller) {
337
+ clearInterval(_internalLogPoller);
338
+ _internalLogPoller = 0;
339
+ _flushInternalLogs();
340
+ }
341
+ }
342
+
343
+ // Add addTelemetryInitializer
344
+ proxyFunctions(_self, () => _telemetryInitializerPlugin, [ "addTelemetryInitializer" ]);
345
+
346
+ _self.unload = (isAsync: boolean = true, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void => {
347
+ if (!_isInitialized) {
348
+ // The SDK is not initialized
349
+ throwError(strSdkNotInitialized);
350
+ }
351
+
352
+ // Check if the SDK still unloading so throw
353
+ if (_isUnloading) {
354
+ // The SDK is already unloading
355
+ throwError(strSdkUnloadingError);
356
+ }
357
+
358
+ let unloadState: ITelemetryUnloadState = {
359
+ reason: TelemetryUnloadReason.SdkUnload,
360
+ isAsync: isAsync,
361
+ flushComplete: false
362
+ }
363
+
364
+ let processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
365
+ processUnloadCtx.onComplete(() => {
366
+ _initDefaults();
367
+ unloadComplete && unloadComplete(unloadState);
368
+ }, _self);
369
+
370
+ function _doUnload(flushComplete: boolean) {
371
+ unloadState.flushComplete = flushComplete;
372
+ _isUnloading = true;
373
+
374
+ // Run all of the unload handlers first (before unloading the plugins)
375
+ _unloadHandlers.run(processUnloadCtx, unloadState);
376
+
377
+ // Stop polling the internal logs
378
+ _self.stopPollingInternalLogs();
379
+
380
+ // Start unloading the components, from this point onwards the SDK should be considered to be in an unstable state
381
+ processUnloadCtx.processNext(unloadState);
382
+ }
383
+
384
+ if (!_flushChannels(isAsync, _doUnload, SendRequestReason.SdkUnload, cbTimeout)) {
385
+ _doUnload(false);
258
386
  }
259
387
  };
388
+
389
+ _self.getPlugin = _getPlugin;
390
+
391
+ _self.addPlugin = <T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, isAsync?: boolean, addCb?: (added?: boolean) => void): void => {
392
+ if (!plugin) {
393
+ addCb && addCb(false);
394
+ _logOrThrowError(strValidationError);
395
+ return;
396
+ }
397
+
398
+ let existingPlugin = _getPlugin(plugin.identifier);
399
+ if (existingPlugin && !replaceExisting) {
400
+ addCb && addCb(false);
401
+
402
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
403
+ return;
404
+ }
405
+
406
+ let updateState: ITelemetryUpdateState = {
407
+ reason: TelemetryUpdateReason.PluginAdded
408
+ };
409
+
410
+ function _addPlugin(removed: boolean) {
411
+ _configExtensions.push(plugin);
412
+ updateState.added = [plugin];
413
+
414
+ // Re-Initialize the plugin chain
415
+ _initPluginChain(_self.config, updateState);
416
+ addCb && addCb(true);
417
+ }
418
+
419
+ if (existingPlugin) {
420
+ let removedPlugins: IPlugin[] = [existingPlugin.plugin];
421
+ let unloadState: ITelemetryUnloadState = {
422
+ reason: TelemetryUnloadReason.PluginReplace,
423
+ isAsync: !!isAsync
424
+ };
425
+
426
+ _removePlugins(removedPlugins, unloadState, (removed) => {
427
+ if (!removed) {
428
+ // Previous plugin was successfully removed or was not installed
429
+ addCb && addCb(false);
430
+ } else {
431
+ updateState.removed = removedPlugins
432
+ updateState.reason |= TelemetryUpdateReason.PluginRemoved;
433
+ _addPlugin(true);
434
+ }
435
+ });
436
+ } else {
437
+ _addPlugin(false);
438
+ }
439
+ };
440
+
441
+ _self.evtNamespace = (): string => {
442
+ return _evtNamespace;
443
+ };
444
+
445
+ _self.flush = _flushChannels;
446
+
447
+ // Create the addUnloadCb
448
+ proxyFunctionAs(_self, "addUnloadCb", () => _unloadHandlers, "add");
449
+
450
+ function _initDefaults() {
451
+ _isInitialized = false;
452
+
453
+ // Use a default logger so initialization errors are not dropped on the floor with full logging
454
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: eLoggingSeverity.CRITICAL });
455
+ _self.config = {};
456
+ _self._extensions = [];
457
+
458
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
459
+ _eventQueue = [];
460
+ _notificationManager = null;
461
+ _perfManager = null;
462
+ _cfgPerfManager = null;
463
+ _cookieManager = null;
464
+ _pluginChain = null;
465
+ _coreExtensions = null;
466
+ _configExtensions = [];
467
+ _channelControl = null;
468
+ _channelConfig = null;
469
+ _channelQueue = null;
470
+ _isUnloading = false;
471
+ _internalLogsEventName = null;
472
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
473
+ _unloadHandlers = createUnloadHandlerContainer();
474
+ }
475
+
476
+ function _createTelCtx(): IProcessTelemetryContext {
477
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
478
+ }
479
+
480
+ // Initialize or Re-initialize the plugins
481
+ function _initPluginChain(config: IConfiguration, updateState: ITelemetryUpdateState | null) {
482
+ // Extension validation
483
+ let theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
484
+
485
+ _coreExtensions = theExtensions.core;
486
+ _pluginChain = null;
487
+
488
+ // Sort the complete set of extensions by priority
489
+ let allExtensions = theExtensions.all;
490
+
491
+ // Initialize the Channel Queues and the channel plugins first
492
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
493
+ if (_channelControl) {
494
+ // During add / remove of a plugin this may get called again, so don't re-add if already present
495
+ // But we also want the controller as the last, so remove if already present
496
+ // And reusing the existing instance, just in case an installed plugin has a reference and
497
+ // is using it.
498
+ let idx = allExtensions.indexOf(_channelControl);
499
+ if (idx !== -1) {
500
+ allExtensions.splice(idx, 1);
501
+ }
502
+
503
+ idx = _coreExtensions.indexOf(_channelControl);
504
+ if (idx !== -1) {
505
+ _coreExtensions.splice(idx, 1);
506
+ }
507
+
508
+ (_channelControl as IInternalChannelController)._setQueue(_channelQueue);
509
+ } else {
510
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
511
+ }
512
+
513
+ // Add on "channelController" as the last "plugin"
514
+ allExtensions.push(_channelControl);
515
+ _coreExtensions.push(_channelControl);
516
+
517
+ // Required to allow plugins to call core.getPlugin() during their own initialization
518
+ _self._extensions = sortPlugins(allExtensions);
519
+
520
+ // Initialize the controls
521
+ _channelControl.initialize(config, _self, allExtensions);
522
+
523
+ initializePlugins(_createTelCtx(), allExtensions);
524
+
525
+ // Now reset the extensions to just those being managed by Basecore
526
+ _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
527
+
528
+ if (updateState) {
529
+ _doUpdate(updateState);
530
+ }
531
+ }
532
+
533
+ function _getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
534
+ let theExt: ILoadedPlugin<T> = null;
535
+ let thePlugin: IPlugin = null;
536
+
537
+ arrForEach(_self._extensions, (ext: any) => {
538
+ if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
539
+ thePlugin = ext;
540
+ return -1;
541
+ }
542
+ });
543
+
544
+ if (!thePlugin && _channelControl) {
545
+ // Check the channel Controller
546
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
547
+ }
548
+
549
+ if (thePlugin) {
550
+ theExt = {
551
+ plugin: thePlugin as T,
552
+ setEnabled: (enabled: boolean) => {
553
+ _getPluginState(thePlugin)[strDisabled] = !enabled;
554
+ },
555
+ isEnabled: () => {
556
+ let pluginState = _getPluginState(thePlugin);
557
+ return !pluginState[strTeardown] && !pluginState[strDisabled];
558
+ },
559
+ remove: (isAsync: boolean = true, removeCb?: (removed?: boolean) => void): void => {
560
+ let pluginsToRemove: IPlugin[] = [thePlugin];
561
+ let unloadState: ITelemetryUnloadState = {
562
+ reason: TelemetryUnloadReason.PluginUnload,
563
+ isAsync: isAsync
564
+ };
565
+
566
+ _removePlugins(pluginsToRemove, unloadState, (removed) => {
567
+ if (removed) {
568
+ // Re-Initialize the plugin chain
569
+ _initPluginChain(_self.config, {
570
+ reason: TelemetryUpdateReason.PluginRemoved,
571
+ removed: pluginsToRemove
572
+ });
573
+ }
574
+
575
+ removeCb && removeCb(removed);
576
+ });
577
+ }
578
+ }
579
+ }
580
+
581
+ return theExt;
582
+ }
583
+
584
+ function _getPluginChain() {
585
+ if (!_pluginChain) {
586
+ // copy the collection of extensions
587
+ let extensions = (_coreExtensions || []).slice();
588
+
589
+ // During add / remove this may get called again, so don't readd if already present
590
+ if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
591
+ extensions.push(_telemetryInitializerPlugin);
592
+ }
593
+
594
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
595
+ }
596
+
597
+ return _pluginChain;
598
+ }
599
+
600
+ function _removePlugins(thePlugins: IPlugin[], unloadState: ITelemetryUnloadState, removeComplete: (removed: boolean) => void) {
601
+
602
+ if (thePlugins && thePlugins.length > 0) {
603
+ let unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
604
+ let unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
605
+
606
+ unloadCtx.onComplete(() => {
607
+ let removed = false;
608
+
609
+ // Remove the listed config extensions
610
+ let newConfigExtensions: IPlugin[] = [];
611
+ arrForEach(_configExtensions, (plugin, idx) => {
612
+ if (!_isPluginPresent(plugin, thePlugins)) {
613
+ newConfigExtensions.push(plugin);
614
+ } else {
615
+ removed = true;
616
+ }
617
+ });
618
+
619
+ _configExtensions = newConfigExtensions;
620
+
621
+ // Re-Create the channel config
622
+ let newChannelConfig: IChannelControls[][] = [];
623
+ if (_channelConfig) {
624
+ arrForEach(_channelConfig, (queue, idx) => {
625
+ let newQueue: IChannelControls[] = [];
626
+ arrForEach(queue, (channel) => {
627
+ if (!_isPluginPresent(channel, thePlugins)) {
628
+ newQueue.push(channel);
629
+ } else {
630
+ removed = true;
631
+ }
632
+ });
633
+
634
+ newChannelConfig.push(newQueue);
635
+ });
636
+
637
+ _channelConfig = newChannelConfig;
638
+ }
639
+
640
+ removeComplete && removeComplete(removed);
641
+ });
642
+
643
+ unloadCtx.processNext(unloadState);
644
+ } else {
645
+ removeComplete(false);
646
+ }
647
+ }
648
+
649
+ function _flushInternalLogs() {
650
+ let queue: _InternalLogMessage[] = _self.logger ? _self.logger.queue : [];
651
+ if (queue) {
652
+ arrForEach(queue, (logMessage: _InternalLogMessage) => {
653
+ const item: ITelemetryItem = {
654
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
655
+ iKey: _self.config.instrumentationKey,
656
+ time: toISOString(new Date()),
657
+ baseType: _InternalLogMessage.dataType,
658
+ baseData: { message: logMessage.message }
659
+ };
660
+ _self.track(item);
661
+ });
662
+
663
+ queue.length = 0;
664
+ }
665
+ }
666
+
667
+ function _flushChannels(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number) {
668
+ if (_channelControl) {
669
+ return _channelControl.flush(isAsync, callBack, sendReason || SendRequestReason.SdkUnload, cbTimeout);
670
+ }
671
+
672
+ callBack && callBack(false);
673
+ return true;
674
+ }
675
+
676
+ function _initDebugListener(config: IConfiguration) {
677
+
678
+ if (config.disableDbgExt === true && _debugListener) {
679
+ // Remove any previously loaded debug listener
680
+ _notificationManager[strRemoveNotificationListener](_debugListener);
681
+ _debugListener = null;
682
+ }
683
+
684
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
685
+ _debugListener = getDebugListener(config);
686
+ _notificationManager[strAddNotificationListener](_debugListener);
687
+ }
688
+ }
689
+
690
+ function _initPerfManager(config: IConfiguration) {
691
+ if (!config.enablePerfMgr && _cfgPerfManager) {
692
+ // Remove any existing config based performance manager
693
+ _cfgPerfManager = null;
694
+ }
695
+
696
+ if (config.enablePerfMgr) {
697
+ // Set the performance manager creation function if not defined
698
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
699
+ }
700
+ }
701
+
702
+ function _initExtConfig(config: IConfiguration) {
703
+ let extConfig = getSetValue(config, strExtensionConfig);
704
+ extConfig.NotificationManager = _notificationManager;
705
+ }
706
+
707
+ function _doUpdate(updateState: ITelemetryUpdateState): void {
708
+ let updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
709
+
710
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
711
+ updateCtx.processNext(updateState);
712
+ }
713
+ }
714
+
715
+ function _logOrThrowError(message: string) {
716
+ let logger = _self.logger;
717
+ if (logger) {
718
+ // there should always be a logger
719
+ _throwInternal(logger, eLoggingSeverity.WARNING, _eInternalMessageId.PluginException, message);
720
+ } else {
721
+ throwError(message);
722
+ }
723
+ }
260
724
  });
261
725
  }
262
726
 
@@ -283,6 +747,24 @@ export class BaseCore implements IAppInsightsCore {
283
747
  return null;
284
748
  }
285
749
 
750
+ /**
751
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
752
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
753
+ * called.
754
+ * @param {INotificationListener} listener - An INotificationListener object.
755
+ */
756
+ public addNotificationListener(listener: INotificationListener): void {
757
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
758
+ }
759
+
760
+ /**
761
+ * Removes all instances of the listener.
762
+ * @param {INotificationListener} listener - INotificationListener to remove.
763
+ */
764
+ public removeNotificationListener(listener: INotificationListener): void {
765
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
766
+ }
767
+
286
768
  /**
287
769
  * Get the current cookie manager for this instance
288
770
  */
@@ -313,7 +795,101 @@ export class BaseCore implements IAppInsightsCore {
313
795
  return 0;
314
796
  }
315
797
 
798
+ /**
799
+ * Periodically check logger.queue for
800
+ */
801
+ public pollInternalLogs(eventName?: string): number {
802
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
803
+ return 0;
804
+ }
805
+
806
+ /**
807
+ * Periodically check logger.queue for
808
+ */
809
+ public stopPollingInternalLogs(): void {
810
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
811
+ }
812
+
813
+ /**
814
+ * Add a telemetry processor to decorate or drop telemetry events.
815
+ * @param telemetryInitializer - The Telemetry Initializer function
816
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
817
+ */
818
+ public addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void {
819
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
820
+ }
821
+
822
+ /**
823
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
824
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
825
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
826
+ * approach is to create a new instance and initialize that instance.
827
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
828
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
829
+ * @param isAsync - Can the unload be performed asynchronously (default)
830
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
831
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
832
+ */
833
+ public unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void {
834
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
835
+ }
836
+
837
+ public getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
838
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
839
+ return null;
840
+ }
841
+
842
+ /**
843
+ * Add a new plugin to the installation
844
+ * @param plugin - The new plugin to add
845
+ * @param replaceExisting - should any existing plugin be replaced, default is false
846
+ * @param doAsync - Should the add be performed asynchronously
847
+ * @param addCb - [Optional] callback to call after the plugin has been added
848
+ */
849
+ public addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void {
850
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
851
+ }
852
+
853
+ /**
854
+ * Returns the unique event namespace that should be used
855
+ */
856
+ public evtNamespace(): string {
857
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
858
+ return null;
859
+ }
860
+
861
+ /**
862
+ * Add an unload handler that will be called when the SDK is being unloaded
863
+ * @param handler - the handler
864
+ */
865
+ public addUnloadCb(handler: UnloadHandler): void {
866
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
867
+ }
868
+
869
+ /**
870
+ * Flush and send any batched / cached data immediately
871
+ * @param async - send data asynchronously when true (defaults to true)
872
+ * @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.
873
+ * If the caller doesn't return true the caller should assume that it may never be called.
874
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
875
+ * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
876
+ */
877
+ public flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void {
878
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
879
+ }
880
+
316
881
  protected releaseQueue() {
317
882
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
318
883
  }
884
+
885
+ /**
886
+ * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
887
+ * @param updateCtx - The plugin update context
888
+ * @param updateState - The Update State
889
+ * @returns boolean - True means the extension class will call updateState otherwise the Core will
890
+ */
891
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean {
892
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
893
+ return false;
894
+ }
319
895
  }