@microsoft/applicationinsights-core-js 2.7.5-nightly.2203-01 → 2.8.0-beta.2203-01

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +860 -457
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +1193 -267
  7. package/dist/applicationinsights-core-js.api.md +54 -14
  8. package/dist/applicationinsights-core-js.d.ts +133 -45
  9. package/dist/applicationinsights-core-js.js +860 -457
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +133 -45
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +237 -82
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +45 -19
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +155 -87
  21. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +2 -27
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  26. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  27. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  28. package/dist-esm/JavaScriptSDK/EnvUtils.js +6 -6
  29. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/HelperFuncs.js +51 -11
  31. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
  33. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/NotificationManager.js +34 -36
  35. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  37. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +289 -119
  38. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  39. package/dist-esm/JavaScriptSDK/RandomHelper.js +29 -4
  40. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +2 -2
  42. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  43. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +82 -0
  44. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
  45. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  46. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
  49. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  50. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
  62. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
  63. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  66. package/dist-esm/applicationinsights-core-js.js +4 -4
  67. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  68. package/package.json +2 -2
  69. package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
  70. package/src/JavaScriptSDK/BaseCore.ts +330 -100
  71. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +69 -32
  72. package/src/JavaScriptSDK/ChannelController.ts +175 -103
  73. package/src/JavaScriptSDK/CoreUtils.ts +1 -28
  74. package/src/JavaScriptSDK/EnvUtils.ts +5 -5
  75. package/src/JavaScriptSDK/HelperFuncs.ts +57 -14
  76. package/src/JavaScriptSDK/InstrumentHooks.ts +3 -1
  77. package/src/JavaScriptSDK/NotificationManager.ts +32 -31
  78. package/src/JavaScriptSDK/PerfManager.ts +1 -1
  79. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +350 -133
  80. package/src/JavaScriptSDK/RandomHelper.ts +34 -3
  81. package/src/JavaScriptSDK/TelemetryHelpers.ts +4 -6
  82. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +119 -0
  83. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +17 -1
  84. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +7 -3
  85. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +5 -0
  86. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +23 -5
  87. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
  88. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +1 -1
  89. package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
  90. package/types/JavaScriptSDK/BaseCore.d.ts +30 -1
  91. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +13 -11
  92. package/types/JavaScriptSDK/ChannelController.d.ts +12 -17
  93. package/types/JavaScriptSDK/CoreUtils.d.ts +0 -6
  94. package/types/JavaScriptSDK/HelperFuncs.d.ts +14 -5
  95. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +49 -3
  96. package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
  97. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -3
  98. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +23 -0
  99. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +15 -0
  100. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +7 -3
  101. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +4 -0
  102. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +18 -3
  103. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
  104. package/types/applicationinsights-core-js.d.ts +5 -4
  105. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
  106. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
  107. package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
  108. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
@@ -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,22 +12,24 @@ 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
15
  import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
17
- import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
16
+ import { createProcessTelemetryContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
18
17
  import { initializePlugins, sortPlugins } from "./TelemetryHelpers";
19
- import { _InternalMessageId, LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
18
+ import { LoggingSeverity } 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, proxyFunctions } from "./HelperFuncs";
25
24
  import { strExtensionConfig, strIKey } from "./Constants";
26
- import { DiagnosticLogger } from "./DiagnosticLogger";
25
+ import { DiagnosticLogger, _InternalLogMessage } from "./DiagnosticLogger";
27
26
  import { getDebugListener } from "./DbgExtensionUtils";
27
+ import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
28
+ import { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues, IChannelController, _IInternalChannels } from "./ChannelController";
29
+ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
30
+ import { TelemetryInitializerPlugin } from "./TelemetryInitializerPlugin";
28
31
 
29
- const validationError = "Extensions must provide callback to initialize";
30
-
32
+ const strValidationError = "Plugins must provide initialize method";
31
33
  const strNotificationManager = "_notificationManager";
32
34
 
33
35
  /**
@@ -39,6 +41,45 @@ function _createPerfManager (core: IAppInsightsCore, notificationMgr: INotificat
39
41
  return new PerfManager(notificationMgr);
40
42
  }
41
43
 
44
+ function _validateExtensions(logger: IDiagnosticLogger, channelPriority: number, allExtensions: IPlugin[]): { all: IPlugin[]; core: ITelemetryPlugin[] } {
45
+ // Concat all available extensions
46
+ let coreExtensions: ITelemetryPlugin[] = [];
47
+
48
+ // Check if any two extensions have the same priority, then warn to console
49
+ // And extract the local extensions from the
50
+ let extPriorities = {};
51
+
52
+ // Extension validation
53
+ arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
54
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
55
+ throwError(strValidationError);
56
+ }
57
+
58
+ const extPriority = ext.priority;
59
+ const identifier = ext.identifier;
60
+
61
+ if (ext && extPriority) {
62
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
63
+ logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
64
+ } else {
65
+ // set a value
66
+ extPriorities[extPriority] = identifier;
67
+ }
68
+ }
69
+
70
+ // Split extensions to core and channelController
71
+ if (!extPriority || extPriority < channelPriority) {
72
+ // Add to core extension that will be managed by BaseCore
73
+ coreExtensions.push(ext);
74
+ }
75
+ });
76
+
77
+ return {
78
+ all: allExtensions,
79
+ core: coreExtensions
80
+ };
81
+ }
82
+
42
83
  export class BaseCore implements IAppInsightsCore {
43
84
  public static defaultConfig: IConfiguration;
44
85
  public config: IConfiguration;
@@ -48,20 +89,33 @@ export class BaseCore implements IAppInsightsCore {
48
89
  public isInitialized: () => boolean;
49
90
 
50
91
  constructor() {
51
- let _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
+ let _isInitialized: boolean;
52
94
  let _eventQueue: ITelemetryItem[];
53
- let _channelController: ChannelController;
54
95
  let _notificationManager: INotificationManager;
55
96
  let _perfManager: IPerfManager;
97
+ let _cfgPerfManager: IPerfManager;
56
98
  let _cookieManager: ICookieMgr;
57
-
99
+ let _pluginChain: ITelemetryPluginChain;
100
+ let _configExtensions: IPlugin[];
101
+ let _coreExtensions: ITelemetryPlugin[];
102
+ let _channelControl: IChannelController;
103
+ let _channelConfig: IChannelControls[][];
104
+ let _channelQueue: _IInternalChannels[];
105
+ let _telemetryInitializerPlugin: TelemetryInitializerPlugin;
106
+ let _internalLogsEventName: string;
107
+ let _debugListener: INotificationListener;
108
+
109
+ /**
110
+ * Internal log poller
111
+ */
112
+ let _internalLogPoller: number = 0;
113
+
58
114
  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 = [];
115
+
116
+ // Set the default values (also called during teardown)
117
+ _initDefaults();
118
+
65
119
  _self.isInitialized = () => _isInitialized;
66
120
 
67
121
  _self.initialize = (config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void => {
@@ -69,7 +123,7 @@ export class BaseCore implements IAppInsightsCore {
69
123
  if (_self.isInitialized()) {
70
124
  throwError("Core should not be initialized more than once");
71
125
  }
72
-
126
+
73
127
  if (!config || isNullOrUndefined(config.instrumentationKey)) {
74
128
  throwError("Please provide instrumentation key");
75
129
  }
@@ -80,14 +134,8 @@ export class BaseCore implements IAppInsightsCore {
80
134
  _self[strNotificationManager] = notificationManager;
81
135
  _self.config = config || {};
82
136
 
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
- }
137
+ _initDebugListener(config);
138
+ _initPerfManager(config);
91
139
 
92
140
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
93
141
 
@@ -99,63 +147,13 @@ export class BaseCore implements IAppInsightsCore {
99
147
  _self.logger = logger;
100
148
  }
101
149
 
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
150
  // 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
-
151
+ _configExtensions = [];
152
+ _configExtensions.push(...extensions, ...config.extensions);
153
+ _channelConfig = (config||{}).channels;
154
+
155
+ _initPluginChain(config);
156
+
159
157
  if (_self.getTransmissionControls().length === 0) {
160
158
  throwError("No channels available");
161
159
  }
@@ -165,7 +163,12 @@ export class BaseCore implements IAppInsightsCore {
165
163
  };
166
164
 
167
165
  _self.getTransmissionControls = (): IChannelControls[][] => {
168
- return _channelController.getChannelControls();
166
+ let controls: IChannelControls[][] = [];
167
+ arrForEach(_channelQueue, (channels) => {
168
+ controls.push(channels.queue);
169
+ });
170
+
171
+ return objFreeze(controls);
169
172
  };
170
173
 
171
174
  _self.track = (telemetryItem: ITelemetryItem) => {
@@ -188,16 +191,7 @@ export class BaseCore implements IAppInsightsCore {
188
191
  };
189
192
 
190
193
  _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);
194
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
201
195
  };
202
196
 
203
197
  _self.getNotifyMgr = (): INotificationManager => {
@@ -217,6 +211,28 @@ export class BaseCore implements IAppInsightsCore {
217
211
 
218
212
  return _notificationManager;
219
213
  };
214
+
215
+ /**
216
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
217
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
218
+ * called.
219
+ * @param {INotificationListener} listener - An INotificationListener object.
220
+ */
221
+ _self.addNotificationListener = (listener: INotificationListener): void => {
222
+ if (_notificationManager) {
223
+ _notificationManager.addNotificationListener(listener);
224
+ }
225
+ };
226
+
227
+ /**
228
+ * Removes all instances of the listener.
229
+ * @param {INotificationListener} listener - INotificationListener to remove.
230
+ */
231
+ _self.removeNotificationListener = (listener: INotificationListener): void => {
232
+ if (_notificationManager) {
233
+ _notificationManager.removeNotificationListener(listener);
234
+ }
235
+ }
220
236
 
221
237
  _self.getCookieMgr = (): ICookieMgr => {
222
238
  if (!_cookieManager) {
@@ -231,13 +247,13 @@ export class BaseCore implements IAppInsightsCore {
231
247
  };
232
248
 
233
249
  _self.getPerfMgr = (): IPerfManager => {
234
- if (!_perfManager) {
250
+ if (!_perfManager && !_cfgPerfManager) {
235
251
  if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
236
- _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
252
+ _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
237
253
  }
238
254
  }
239
255
 
240
- return _perfManager || getGblPerfMgr();
256
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
241
257
  };
242
258
 
243
259
  _self.setPerfMgr = (perfMgr: IPerfManager) => {
@@ -249,14 +265,182 @@ export class BaseCore implements IAppInsightsCore {
249
265
  };
250
266
 
251
267
  _self.releaseQueue = () => {
252
- if (_eventQueue.length > 0) {
253
- arrForEach(_eventQueue, (event: ITelemetryItem) => {
268
+ if (_isInitialized && _eventQueue.length > 0) {
269
+ let eventQueue = _eventQueue;
270
+ _eventQueue = [];
271
+
272
+ arrForEach(eventQueue, (event: ITelemetryItem) => {
254
273
  _self.getProcessTelContext().processNext(event);
255
274
  });
256
-
257
- _eventQueue = [];
258
275
  }
259
276
  };
277
+
278
+ /**
279
+ * Periodically check logger.queue for log messages to be flushed
280
+ */
281
+ _self.pollInternalLogs = (eventName?: string): number => {
282
+ _internalLogsEventName = eventName;
283
+
284
+ let interval = _self.config.diagnosticLogInterval;
285
+ if (!interval || !(interval > 0)) {
286
+ interval = 10000;
287
+ }
288
+ if(_internalLogPoller) {
289
+ clearInterval(_internalLogPoller);
290
+ }
291
+ _internalLogPoller = setInterval(() => {
292
+ _flushInternalLogs();
293
+ }, interval) as any;
294
+
295
+ return _internalLogPoller;
296
+ }
297
+
298
+ /**
299
+ * Stop polling log messages from logger.queue
300
+ */
301
+ _self.stopPollingInternalLogs = (): void => {
302
+ if(_internalLogPoller) {
303
+ clearInterval(_internalLogPoller);
304
+ _internalLogPoller = 0;
305
+ _flushInternalLogs();
306
+ }
307
+ }
308
+
309
+ // Add addTelemetryInitializer
310
+ proxyFunctions(_self, () => _telemetryInitializerPlugin, [ "addTelemetryInitializer" ]);
311
+
312
+ _self.getPlugin = _getPlugin;
313
+
314
+ function _initDefaults() {
315
+ _isInitialized = false;
316
+
317
+ // Use a default logger so initialization errors are not dropped on the floor with full logging
318
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
319
+ _self.config = null;
320
+ _self._extensions = [];
321
+
322
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
323
+ _eventQueue = [];
324
+ _notificationManager = null;
325
+ _perfManager = null;
326
+ _cfgPerfManager = null;
327
+ _cookieManager = null;
328
+ _pluginChain = null;
329
+ _coreExtensions = null;
330
+ _configExtensions = null;
331
+ _channelControl = null;
332
+ _channelConfig = null;
333
+ _channelQueue = null;
334
+ _internalLogsEventName = null;
335
+ }
336
+
337
+ // Initialize or Re-initialize the plugins
338
+ function _initPluginChain(config: IConfiguration) {
339
+ // Extension validation
340
+ let theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
341
+
342
+ _coreExtensions = theExtensions.core;
343
+ _pluginChain = null;
344
+
345
+ // Sort the complete set of extensions by priority
346
+ let allExtensions = theExtensions.all;
347
+
348
+ // Initialize the Channel Queues and the channel plugins first
349
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
350
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
351
+
352
+ // Add on "channelController" as the last "plugin"
353
+ allExtensions.push(_channelControl);
354
+ _coreExtensions.push(_channelControl);
355
+
356
+ // Required to allow plugins to call core.getPlugin() during their own initialization
357
+ _self._extensions = sortPlugins(allExtensions);
358
+
359
+ // Initialize the controls
360
+ _channelControl.initialize(config, _self, allExtensions);
361
+
362
+ initializePlugins(_self.getProcessTelContext(), allExtensions);
363
+
364
+ // Now reset the extensions to just those being managed by Basecore
365
+ _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
366
+ }
367
+
368
+ function _getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
369
+ let theExt: ILoadedPlugin<T> = null;
370
+ let thePlugin: IPlugin = null;
371
+
372
+ arrForEach(_self._extensions, (ext: any) => {
373
+ if (ext.identifier === pluginIdentifier) {
374
+ thePlugin = ext;
375
+ return -1;
376
+ }
377
+ });
378
+
379
+ if (thePlugin) {
380
+ theExt = {
381
+ plugin: thePlugin as T
382
+ }
383
+ }
384
+
385
+ return theExt;
386
+ }
387
+
388
+ function _getPluginChain() {
389
+ if (!_pluginChain) {
390
+ // copy the collection of extensions
391
+ let extensions = (_coreExtensions || []).slice();
392
+
393
+ extensions.push(_telemetryInitializerPlugin);
394
+
395
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
396
+ }
397
+
398
+ return _pluginChain;
399
+ }
400
+
401
+ function _flushInternalLogs() {
402
+ let queue: _InternalLogMessage[] = _self.logger ? _self.logger.queue : [];
403
+ if (queue) {
404
+ arrForEach(queue, (logMessage: _InternalLogMessage) => {
405
+ const item: ITelemetryItem = {
406
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
407
+ iKey: _self.config.instrumentationKey,
408
+ time: toISOString(new Date()),
409
+ baseType: _InternalLogMessage.dataType,
410
+ baseData: { message: logMessage.message }
411
+ };
412
+ _self.track(item);
413
+ });
414
+
415
+ queue.length = 0;
416
+ }
417
+ }
418
+
419
+ function _initDebugListener(config: IConfiguration) {
420
+
421
+ if (config.disableDbgExt === true && _debugListener) {
422
+ // Remove any previously loaded debug listener
423
+ _notificationManager.removeNotificationListener(_debugListener);
424
+ _debugListener = null;
425
+ }
426
+
427
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
428
+ _debugListener = getDebugListener(config);
429
+ _notificationManager.addNotificationListener(_debugListener);
430
+ }
431
+ }
432
+
433
+ function _initPerfManager(config: IConfiguration) {
434
+ if (!config.enablePerfMgr && _cfgPerfManager) {
435
+ // Remove any existing config based performance manager
436
+ _cfgPerfManager = null;
437
+ }
438
+
439
+ if (config.enablePerfMgr) {
440
+ // Set the performance manager creation function if not defined
441
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
442
+ }
443
+ }
260
444
  });
261
445
  }
262
446
 
@@ -283,6 +467,24 @@ export class BaseCore implements IAppInsightsCore {
283
467
  return null;
284
468
  }
285
469
 
470
+ /**
471
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
472
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
473
+ * called.
474
+ * @param {INotificationListener} listener - An INotificationListener object.
475
+ */
476
+ public addNotificationListener(listener: INotificationListener): void {
477
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
478
+ }
479
+
480
+ /**
481
+ * Removes all instances of the listener.
482
+ * @param {INotificationListener} listener - INotificationListener to remove.
483
+ */
484
+ public removeNotificationListener(listener: INotificationListener): void {
485
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
486
+ }
487
+
286
488
  /**
287
489
  * Get the current cookie manager for this instance
288
490
  */
@@ -313,6 +515,34 @@ export class BaseCore implements IAppInsightsCore {
313
515
  return 0;
314
516
  }
315
517
 
518
+ /**
519
+ * Periodically check logger.queue for
520
+ */
521
+ public pollInternalLogs(eventName?: string): number {
522
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
523
+ return 0;
524
+ }
525
+
526
+ /**
527
+ * Periodically check logger.queue for
528
+ */
529
+ public stopPollingInternalLogs(): void {
530
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
531
+ }
532
+
533
+ /**
534
+ * Add a telemetry processor to decorate or drop telemetry events.
535
+ * @param telemetryInitializer - The Telemetry Initializer function
536
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
537
+ */
538
+ public addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void {
539
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
540
+ }
541
+
542
+ public getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
543
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
544
+ return null;
545
+ }
316
546
  protected releaseQueue() {
317
547
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
318
548
  }