@microsoft/applicationinsights-core-js 2.7.4-nightly.2202-07 → 2.8.0-beta.2202-06

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
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.7.4-nightly.2202-07
2
+ * Application Insights JavaScript SDK - Core, 2.8.0-beta.2202-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -8,17 +8,18 @@
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";
11
+ import { createProcessTelemetryContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
13
12
  import { initializePlugins, sortPlugins } from "./TelemetryHelpers";
14
13
  import { LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
15
14
  import { getGblPerfMgr, PerfManager } from "./PerfManager";
16
15
  import { createCookieMgr } from "./CookieMgr";
17
- import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction } from "./HelperFuncs";
16
+ import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction, objFreeze, proxyFunctions } from "./HelperFuncs";
18
17
  import { strExtensionConfig, strIKey } from "./Constants";
19
- import { DiagnosticLogger } from "./DiagnosticLogger";
18
+ import { DiagnosticLogger, _InternalLogMessage } from "./DiagnosticLogger";
20
19
  import { getDebugListener } from "./DbgExtensionUtils";
21
- var validationError = "Extensions must provide callback to initialize";
20
+ import { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues } from "./ChannelController";
21
+ import { TelemetryInitializerPlugin } from "./TelemetryInitializerPlugin";
22
+ var strValidationError = "Plugins must provide initialize method";
22
23
  var strNotificationManager = "_notificationManager";
23
24
  /**
24
25
  * Helper to create the default performance manager
@@ -28,20 +29,64 @@ var strNotificationManager = "_notificationManager";
28
29
  function _createPerfManager(core, notificationMgr) {
29
30
  return new PerfManager(notificationMgr);
30
31
  }
32
+ function _validateExtensions(logger, channelPriority, allExtensions) {
33
+ // Concat all available extensions
34
+ var coreExtensions = [];
35
+ // Check if any two extensions have the same priority, then warn to console
36
+ // And extract the local extensions from the
37
+ var extPriorities = {};
38
+ // Extension validation
39
+ arrForEach(allExtensions, function (ext) {
40
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
41
+ throwError(strValidationError);
42
+ }
43
+ var extPriority = ext.priority;
44
+ var identifier = ext.identifier;
45
+ if (ext && extPriority) {
46
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
47
+ logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
48
+ }
49
+ else {
50
+ // set a value
51
+ extPriorities[extPriority] = identifier;
52
+ }
53
+ }
54
+ // Split extensions to core and channelController
55
+ if (!extPriority || extPriority < channelPriority) {
56
+ // Add to core extension that will be managed by BaseCore
57
+ coreExtensions.push(ext);
58
+ }
59
+ });
60
+ return {
61
+ all: allExtensions,
62
+ core: coreExtensions
63
+ };
64
+ }
31
65
  var BaseCore = /** @class */ (function () {
32
66
  function BaseCore() {
33
- var _isInitialized = false;
67
+ // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
68
+ var _isInitialized;
34
69
  var _eventQueue;
35
- var _channelController;
36
70
  var _notificationManager;
37
71
  var _perfManager;
72
+ var _cfgPerfManager;
38
73
  var _cookieManager;
74
+ var _pluginChain;
75
+ var _configExtensions;
76
+ var _coreExtensions;
77
+ var _channelControl;
78
+ var _channelConfig;
79
+ var _channelQueue;
80
+ var _telemetryInitializerPlugin;
81
+ var _internalLogsEventName;
82
+ var _debugListener;
83
+ /**
84
+ * Internal log poller
85
+ */
86
+ var _internalLogPoller = 0;
39
87
  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 = [];
88
+ // Set the default values (also called during teardown)
89
+ _initDefaults();
45
90
  _self.isInitialized = function () { return _isInitialized; };
46
91
  _self.initialize = function (config, extensions, logger, notificationManager) {
47
92
  // Make sure core is only initialized once
@@ -55,13 +100,8 @@ var BaseCore = /** @class */ (function () {
55
100
  // For backward compatibility only
56
101
  _self[strNotificationManager] = notificationManager;
57
102
  _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
- }
103
+ _initDebugListener(config);
104
+ _initPerfManager(config);
65
105
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
66
106
  // add notification to the extensions in the config so other plugins can access it
67
107
  var extConfig = getSetValue(config, strExtensionConfig);
@@ -69,54 +109,11 @@ var BaseCore = /** @class */ (function () {
69
109
  if (logger) {
70
110
  _self.logger = logger;
71
111
  }
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
112
  // 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;
113
+ _configExtensions = [];
114
+ _configExtensions.push.apply(_configExtensions, __spreadArray(__spreadArray([], extensions, false), config.extensions, false));
115
+ _channelConfig = (config || {}).channels;
116
+ _initPluginChain(config);
120
117
  if (_self.getTransmissionControls().length === 0) {
121
118
  throwError("No channels available");
122
119
  }
@@ -124,7 +121,11 @@ var BaseCore = /** @class */ (function () {
124
121
  _self.releaseQueue();
125
122
  };
126
123
  _self.getTransmissionControls = function () {
127
- return _channelController.getChannelControls();
124
+ var controls = [];
125
+ arrForEach(_channelQueue, function (channels) {
126
+ controls.push(channels.queue);
127
+ });
128
+ return objFreeze(controls);
128
129
  };
129
130
  _self.track = function (telemetryItem) {
130
131
  // setup default iKey if not passed in
@@ -143,14 +144,7 @@ var BaseCore = /** @class */ (function () {
143
144
  }
144
145
  };
145
146
  _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);
147
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
154
148
  };
155
149
  _self.getNotifyMgr = function () {
156
150
  if (!_notificationManager) {
@@ -167,6 +161,26 @@ var BaseCore = /** @class */ (function () {
167
161
  }
168
162
  return _notificationManager;
169
163
  };
164
+ /**
165
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
166
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
167
+ * called.
168
+ * @param {INotificationListener} listener - An INotificationListener object.
169
+ */
170
+ _self.addNotificationListener = function (listener) {
171
+ if (_notificationManager) {
172
+ _notificationManager.addNotificationListener(listener);
173
+ }
174
+ };
175
+ /**
176
+ * Removes all instances of the listener.
177
+ * @param {INotificationListener} listener - INotificationListener to remove.
178
+ */
179
+ _self.removeNotificationListener = function (listener) {
180
+ if (_notificationManager) {
181
+ _notificationManager.removeNotificationListener(listener);
182
+ }
183
+ };
170
184
  _self.getCookieMgr = function () {
171
185
  if (!_cookieManager) {
172
186
  _cookieManager = createCookieMgr(_self.config, _self.logger);
@@ -177,12 +191,12 @@ var BaseCore = /** @class */ (function () {
177
191
  _cookieManager = cookieMgr;
178
192
  };
179
193
  _self.getPerfMgr = function () {
180
- if (!_perfManager) {
194
+ if (!_perfManager && !_cfgPerfManager) {
181
195
  if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
182
- _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
196
+ _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
183
197
  }
184
198
  }
185
- return _perfManager || getGblPerfMgr();
199
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
186
200
  };
187
201
  _self.setPerfMgr = function (perfMgr) {
188
202
  _perfManager = perfMgr;
@@ -191,13 +205,148 @@ var BaseCore = /** @class */ (function () {
191
205
  return _eventQueue.length;
192
206
  };
193
207
  _self.releaseQueue = function () {
194
- if (_eventQueue.length > 0) {
195
- arrForEach(_eventQueue, function (event) {
208
+ if (_isInitialized && _eventQueue.length > 0) {
209
+ var eventQueue = _eventQueue;
210
+ _eventQueue = [];
211
+ arrForEach(eventQueue, function (event) {
196
212
  _self.getProcessTelContext().processNext(event);
197
213
  });
198
- _eventQueue = [];
199
214
  }
200
215
  };
216
+ /**
217
+ * Periodically check logger.queue for log messages to be flushed
218
+ */
219
+ _self.pollInternalLogs = function (eventName) {
220
+ _internalLogsEventName = eventName;
221
+ var interval = _self.config.diagnosticLogInterval;
222
+ if (!interval || !(interval > 0)) {
223
+ interval = 10000;
224
+ }
225
+ if (_internalLogPoller) {
226
+ clearInterval(_internalLogPoller);
227
+ }
228
+ _internalLogPoller = setInterval(function () {
229
+ _flushInternalLogs();
230
+ }, interval);
231
+ return _internalLogPoller;
232
+ };
233
+ /**
234
+ * Stop polling log messages from logger.queue
235
+ */
236
+ _self.stopPollingInternalLogs = function () {
237
+ if (_internalLogPoller) {
238
+ clearInterval(_internalLogPoller);
239
+ _internalLogPoller = 0;
240
+ _flushInternalLogs();
241
+ }
242
+ };
243
+ // Add addTelemetryInitializer
244
+ proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
245
+ _self.getPlugin = _getPlugin;
246
+ function _initDefaults() {
247
+ _isInitialized = false;
248
+ // Use a default logger so initialization errors are not dropped on the floor with full logging
249
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
250
+ _self.config = null;
251
+ _self._extensions = [];
252
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
253
+ _eventQueue = [];
254
+ _notificationManager = null;
255
+ _perfManager = null;
256
+ _cfgPerfManager = null;
257
+ _cookieManager = null;
258
+ _pluginChain = null;
259
+ _coreExtensions = null;
260
+ _configExtensions = null;
261
+ _channelControl = null;
262
+ _channelConfig = null;
263
+ _channelQueue = null;
264
+ _internalLogsEventName = null;
265
+ }
266
+ // Initialize or Re-initialize the plugins
267
+ function _initPluginChain(config) {
268
+ // Extension validation
269
+ var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
270
+ _coreExtensions = theExtensions.core;
271
+ _pluginChain = null;
272
+ // Sort the complete set of extensions by priority
273
+ var allExtensions = theExtensions.all;
274
+ // Initialize the Channel Queues and the channel plugins first
275
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
276
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
277
+ // Add on "channelController" as the last "plugin"
278
+ allExtensions.push(_channelControl);
279
+ _coreExtensions.push(_channelControl);
280
+ // Required to allow plugins to call core.getPlugin() during their own initialization
281
+ _self._extensions = sortPlugins(allExtensions);
282
+ // Initialize the controls
283
+ _channelControl.initialize(config, _self, allExtensions);
284
+ initializePlugins(_self.getProcessTelContext(), allExtensions);
285
+ // Now reset the extensions to just those being managed by Basecore
286
+ _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
287
+ }
288
+ function _getPlugin(pluginIdentifier) {
289
+ var theExt = null;
290
+ var thePlugin = null;
291
+ arrForEach(_self._extensions, function (ext) {
292
+ if (ext.identifier === pluginIdentifier) {
293
+ thePlugin = ext;
294
+ return -1;
295
+ }
296
+ });
297
+ if (thePlugin) {
298
+ theExt = {
299
+ plugin: thePlugin
300
+ };
301
+ }
302
+ return theExt;
303
+ }
304
+ function _getPluginChain() {
305
+ if (!_pluginChain) {
306
+ // copy the collection of extensions
307
+ var extensions = (_coreExtensions || []).slice();
308
+ extensions.push(_telemetryInitializerPlugin);
309
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
310
+ }
311
+ return _pluginChain;
312
+ }
313
+ function _flushInternalLogs() {
314
+ var queue = _self.logger ? _self.logger.queue : [];
315
+ if (queue) {
316
+ arrForEach(queue, function (logMessage) {
317
+ var item = {
318
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
319
+ iKey: _self.config.instrumentationKey,
320
+ time: toISOString(new Date()),
321
+ baseType: _InternalLogMessage.dataType,
322
+ baseData: { message: logMessage.message }
323
+ };
324
+ _self.track(item);
325
+ });
326
+ queue.length = 0;
327
+ }
328
+ }
329
+ function _initDebugListener(config) {
330
+ if (config.disableDbgExt === true && _debugListener) {
331
+ // Remove any previously loaded debug listener
332
+ _notificationManager.removeNotificationListener(_debugListener);
333
+ _debugListener = null;
334
+ }
335
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
336
+ _debugListener = getDebugListener(config);
337
+ _notificationManager.addNotificationListener(_debugListener);
338
+ }
339
+ }
340
+ function _initPerfManager(config) {
341
+ if (!config.enablePerfMgr && _cfgPerfManager) {
342
+ // Remove any existing config based performance manager
343
+ _cfgPerfManager = null;
344
+ }
345
+ if (config.enablePerfMgr) {
346
+ // Set the performance manager creation function if not defined
347
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
348
+ }
349
+ }
201
350
  });
202
351
  }
203
352
  // Removed Stub for BaseCore.prototype.initialize.
@@ -205,11 +354,17 @@ var BaseCore = /** @class */ (function () {
205
354
  // Removed Stub for BaseCore.prototype.track.
206
355
  // Removed Stub for BaseCore.prototype.getProcessTelContext.
207
356
  // Removed Stub for BaseCore.prototype.getNotifyMgr.
357
+ // Removed Stub for BaseCore.prototype.addNotificationListener.
358
+ // Removed Stub for BaseCore.prototype.removeNotificationListener.
208
359
  // Removed Stub for BaseCore.prototype.getCookieMgr.
209
360
  // Removed Stub for BaseCore.prototype.setCookieMgr.
210
361
  // Removed Stub for BaseCore.prototype.getPerfMgr.
211
362
  // Removed Stub for BaseCore.prototype.setPerfMgr.
212
363
  // Removed Stub for BaseCore.prototype.eventCnt.
364
+ // Removed Stub for BaseCore.prototype.pollInternalLogs.
365
+ // Removed Stub for BaseCore.prototype.stopPollingInternalLogs.
366
+ // Removed Stub for BaseCore.prototype.addTelemetryInitializer.
367
+ // Removed Stub for BaseCore.prototype.getPlugin.
213
368
  // Removed Stub for BaseCore.prototype.releaseQueue.
214
369
  return BaseCore;
215
370
  }());
@@ -1 +1 @@
1
- {"version":3,"file":"BaseCore.js.map","sources":["BaseCore.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { __spreadArray } from \"tslib\";\r\nimport { objCreateFn } from \"@microsoft/applicationinsights-shims\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { ChannelController } from \"./ChannelController\";\r\nimport { ProcessTelemetryContext } from \"./ProcessTelemetryContext\";\r\nimport { initializePlugins, sortPlugins } from \"./TelemetryHelpers\";\r\nimport { LoggingSeverity } from \"../JavaScriptSDK.Enums/LoggingEnums\";\r\nimport { getGblPerfMgr, PerfManager } from \"./PerfManager\";\r\nimport { createCookieMgr } from \"./CookieMgr\";\r\nimport { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction } from \"./HelperFuncs\";\r\nimport { strExtensionConfig, strIKey } from \"./Constants\";\r\nimport { DiagnosticLogger } from \"./DiagnosticLogger\";\r\nimport { getDebugListener } from \"./DbgExtensionUtils\";\r\nvar validationError = \"Extensions must provide callback to initialize\";\r\nvar strNotificationManager = \"_notificationManager\";\r\n/**\r\n * Helper to create the default performance manager\r\n * @param core\r\n * @param notificationMgr\r\n */\r\nfunction _createPerfManager(core, notificationMgr) {\r\n return new PerfManager(notificationMgr);\r\n}\r\nvar BaseCore = /** @class */ (function () {\r\n function BaseCore() {\r\n var _isInitialized = false;\r\n var _eventQueue;\r\n var _channelController;\r\n var _notificationManager;\r\n var _perfManager;\r\n var _cookieManager;\r\n dynamicProto(BaseCore, this, function (_self) {\r\n _self._extensions = new Array();\r\n _channelController = new ChannelController();\r\n // Use a default logger so initialization errors are not dropped on the floor with full logging\r\n _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });\r\n _eventQueue = [];\r\n _self.isInitialized = function () { return _isInitialized; };\r\n _self.initialize = function (config, extensions, logger, notificationManager) {\r\n // Make sure core is only initialized once\r\n if (_self.isInitialized()) {\r\n throwError(\"Core should not be initialized more than once\");\r\n }\r\n if (!config || isNullOrUndefined(config.instrumentationKey)) {\r\n throwError(\"Please provide instrumentation key\");\r\n }\r\n _notificationManager = notificationManager;\r\n // For backward compatibility only\r\n _self[strNotificationManager] = notificationManager;\r\n _self.config = config || {};\r\n if (notificationManager && _self.config.disableDbgExt !== true) {\r\n notificationManager.addNotificationListener(getDebugListener(config));\r\n }\r\n if (_self.config.enablePerfMgr) {\r\n // Set the performance manager creation function if not defined\r\n setValue(_self.config, \"createPerfMgr\", _createPerfManager);\r\n }\r\n config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;\r\n // add notification to the extensions in the config so other plugins can access it\r\n var extConfig = getSetValue(config, strExtensionConfig);\r\n extConfig.NotificationManager = notificationManager;\r\n if (logger) {\r\n _self.logger = logger;\r\n }\r\n // Concat all available extensions\r\n var allExtensions = [];\r\n allExtensions.push.apply(allExtensions, __spreadArray(__spreadArray([], extensions, false), config.extensions, false));\r\n allExtensions = sortPlugins(allExtensions);\r\n var coreExtensions = [];\r\n var channelExtensions = [];\r\n // Check if any two extensions have the same priority, then warn to console\r\n // And extract the local extensions from the\r\n var extPriorities = {};\r\n // Extension validation\r\n arrForEach(allExtensions, function (ext) {\r\n if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {\r\n throwError(validationError);\r\n }\r\n var extPriority = ext.priority;\r\n var identifier = ext.identifier;\r\n if (ext && extPriority) {\r\n if (!isNullOrUndefined(extPriorities[extPriority])) {\r\n logger.warnToConsole(\"Two extensions have same priority #\" + extPriority + \" - \" + extPriorities[extPriority] + \", \" + identifier);\r\n }\r\n else {\r\n // set a value\r\n extPriorities[extPriority] = identifier;\r\n }\r\n }\r\n // Split extensions to core and channelController\r\n if (!extPriority || extPriority < _channelController.priority) {\r\n // Add to core extension that will be managed by BaseCore\r\n coreExtensions.push(ext);\r\n }\r\n else {\r\n // Add all other extensions to be managed by the channel controller\r\n channelExtensions.push(ext);\r\n }\r\n });\r\n // Validation complete\r\n // Add the channelController to the complete extension collection and\r\n // to the end of the core extensions\r\n allExtensions.push(_channelController);\r\n coreExtensions.push(_channelController);\r\n // Sort the complete set of extensions by priority\r\n allExtensions = sortPlugins(allExtensions);\r\n _self._extensions = allExtensions;\r\n // initialize channel controller first, this will initialize all channel plugins\r\n initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);\r\n initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);\r\n // Now reset the extensions to just those being managed by Basecore\r\n _self._extensions = coreExtensions;\r\n if (_self.getTransmissionControls().length === 0) {\r\n throwError(\"No channels available\");\r\n }\r\n _isInitialized = true;\r\n _self.releaseQueue();\r\n };\r\n _self.getTransmissionControls = function () {\r\n return _channelController.getChannelControls();\r\n };\r\n _self.track = function (telemetryItem) {\r\n // setup default iKey if not passed in\r\n setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);\r\n // add default timestamp if not passed in\r\n setValue(telemetryItem, \"time\", toISOString(new Date()), null, isNotTruthy);\r\n // Common Schema 4.0\r\n setValue(telemetryItem, \"ver\", \"4.0\", null, isNullOrUndefined);\r\n if (_self.isInitialized()) {\r\n // Process the telemetry plugin chain\r\n _self.getProcessTelContext().processNext(telemetryItem);\r\n }\r\n else {\r\n // Queue events until all extensions are initialized\r\n _eventQueue.push(telemetryItem);\r\n }\r\n };\r\n _self.getProcessTelContext = function () {\r\n var extensions = _self._extensions;\r\n var thePlugins = extensions;\r\n // invoke any common telemetry processors before sending through pipeline\r\n if (!extensions || extensions.length === 0) {\r\n // Pass to Channel controller so data is sent to correct channel queues\r\n thePlugins = [_channelController];\r\n }\r\n return new ProcessTelemetryContext(thePlugins, _self.config, _self);\r\n };\r\n _self.getNotifyMgr = function () {\r\n if (!_notificationManager) {\r\n // Create Dummy notification manager\r\n _notificationManager = objCreateFn({\r\n addNotificationListener: function (listener) { },\r\n removeNotificationListener: function (listener) { },\r\n eventsSent: function (events) { },\r\n eventsDiscarded: function (events, reason) { },\r\n eventsSendRequest: function (sendReason, isAsync) { }\r\n });\r\n // For backward compatibility only\r\n _self[strNotificationManager] = _notificationManager;\r\n }\r\n return _notificationManager;\r\n };\r\n _self.getCookieMgr = function () {\r\n if (!_cookieManager) {\r\n _cookieManager = createCookieMgr(_self.config, _self.logger);\r\n }\r\n return _cookieManager;\r\n };\r\n _self.setCookieMgr = function (cookieMgr) {\r\n _cookieManager = cookieMgr;\r\n };\r\n _self.getPerfMgr = function () {\r\n if (!_perfManager) {\r\n if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {\r\n _perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());\r\n }\r\n }\r\n return _perfManager || getGblPerfMgr();\r\n };\r\n _self.setPerfMgr = function (perfMgr) {\r\n _perfManager = perfMgr;\r\n };\r\n _self.eventCnt = function () {\r\n return _eventQueue.length;\r\n };\r\n _self.releaseQueue = function () {\r\n if (_eventQueue.length > 0) {\r\n arrForEach(_eventQueue, function (event) {\r\n _self.getProcessTelContext().processNext(event);\r\n });\r\n _eventQueue = [];\r\n }\r\n };\r\n });\r\n }\r\n BaseCore.prototype.initialize = function (config, extensions, logger, notificationManager) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getTransmissionControls = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.track = function (telemetryItem) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getProcessTelContext = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.getNotifyMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Get the current cookie manager for this instance\r\n */\r\n BaseCore.prototype.getCookieMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Set the current cookie manager for this instance\r\n * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created\r\n */\r\n BaseCore.prototype.setCookieMgr = function (cookieMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getPerfMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.setPerfMgr = function (perfMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.eventCnt = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n BaseCore.prototype.releaseQueue = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return BaseCore;\r\n}());\r\nexport { BaseCore };\r\n//# sourceMappingURL=BaseCore.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA,wFAAsC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;oDA6CM;AACN;AACA;AACA;AACA"}
1
+ {"version":3,"file":"BaseCore.js.map","sources":["BaseCore.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { __spreadArray } from \"tslib\";\r\nimport { objCreateFn } from \"@microsoft/applicationinsights-shims\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { createProcessTelemetryContext, createTelemetryProxyChain } from \"./ProcessTelemetryContext\";\r\nimport { initializePlugins, sortPlugins } from \"./TelemetryHelpers\";\r\nimport { LoggingSeverity } from \"../JavaScriptSDK.Enums/LoggingEnums\";\r\nimport { getGblPerfMgr, PerfManager } from \"./PerfManager\";\r\nimport { createCookieMgr } from \"./CookieMgr\";\r\nimport { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction, objFreeze, proxyFunctions } from \"./HelperFuncs\";\r\nimport { strExtensionConfig, strIKey } from \"./Constants\";\r\nimport { DiagnosticLogger, _InternalLogMessage } from \"./DiagnosticLogger\";\r\nimport { getDebugListener } from \"./DbgExtensionUtils\";\r\nimport { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues } from \"./ChannelController\";\r\nimport { TelemetryInitializerPlugin } from \"./TelemetryInitializerPlugin\";\r\nvar strValidationError = \"Plugins must provide initialize method\";\r\nvar strNotificationManager = \"_notificationManager\";\r\n/**\r\n * Helper to create the default performance manager\r\n * @param core\r\n * @param notificationMgr\r\n */\r\nfunction _createPerfManager(core, notificationMgr) {\r\n return new PerfManager(notificationMgr);\r\n}\r\nfunction _validateExtensions(logger, channelPriority, allExtensions) {\r\n // Concat all available extensions\r\n var coreExtensions = [];\r\n // Check if any two extensions have the same priority, then warn to console\r\n // And extract the local extensions from the\r\n var extPriorities = {};\r\n // Extension validation\r\n arrForEach(allExtensions, function (ext) {\r\n if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {\r\n throwError(strValidationError);\r\n }\r\n var extPriority = ext.priority;\r\n var identifier = ext.identifier;\r\n if (ext && extPriority) {\r\n if (!isNullOrUndefined(extPriorities[extPriority])) {\r\n logger.warnToConsole(\"Two extensions have same priority #\" + extPriority + \" - \" + extPriorities[extPriority] + \", \" + identifier);\r\n }\r\n else {\r\n // set a value\r\n extPriorities[extPriority] = identifier;\r\n }\r\n }\r\n // Split extensions to core and channelController\r\n if (!extPriority || extPriority < channelPriority) {\r\n // Add to core extension that will be managed by BaseCore\r\n coreExtensions.push(ext);\r\n }\r\n });\r\n return {\r\n all: allExtensions,\r\n core: coreExtensions\r\n };\r\n}\r\nvar BaseCore = /** @class */ (function () {\r\n function BaseCore() {\r\n // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()\r\n var _isInitialized;\r\n var _eventQueue;\r\n var _notificationManager;\r\n var _perfManager;\r\n var _cfgPerfManager;\r\n var _cookieManager;\r\n var _pluginChain;\r\n var _configExtensions;\r\n var _coreExtensions;\r\n var _channelControl;\r\n var _channelConfig;\r\n var _channelQueue;\r\n var _telemetryInitializerPlugin;\r\n var _internalLogsEventName;\r\n var _debugListener;\r\n /**\r\n * Internal log poller\r\n */\r\n var _internalLogPoller = 0;\r\n dynamicProto(BaseCore, this, function (_self) {\r\n // Set the default values (also called during teardown)\r\n _initDefaults();\r\n _self.isInitialized = function () { return _isInitialized; };\r\n _self.initialize = function (config, extensions, logger, notificationManager) {\r\n // Make sure core is only initialized once\r\n if (_self.isInitialized()) {\r\n throwError(\"Core should not be initialized more than once\");\r\n }\r\n if (!config || isNullOrUndefined(config.instrumentationKey)) {\r\n throwError(\"Please provide instrumentation key\");\r\n }\r\n _notificationManager = notificationManager;\r\n // For backward compatibility only\r\n _self[strNotificationManager] = notificationManager;\r\n _self.config = config || {};\r\n _initDebugListener(config);\r\n _initPerfManager(config);\r\n config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;\r\n // add notification to the extensions in the config so other plugins can access it\r\n var extConfig = getSetValue(config, strExtensionConfig);\r\n extConfig.NotificationManager = notificationManager;\r\n if (logger) {\r\n _self.logger = logger;\r\n }\r\n // Extension validation\r\n _configExtensions = [];\r\n _configExtensions.push.apply(_configExtensions, __spreadArray(__spreadArray([], extensions, false), config.extensions, false));\r\n _channelConfig = (config || {}).channels;\r\n _initPluginChain(config);\r\n if (_self.getTransmissionControls().length === 0) {\r\n throwError(\"No channels available\");\r\n }\r\n _isInitialized = true;\r\n _self.releaseQueue();\r\n };\r\n _self.getTransmissionControls = function () {\r\n var controls = [];\r\n arrForEach(_channelQueue, function (channels) {\r\n controls.push(channels.queue);\r\n });\r\n return objFreeze(controls);\r\n };\r\n _self.track = function (telemetryItem) {\r\n // setup default iKey if not passed in\r\n setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);\r\n // add default timestamp if not passed in\r\n setValue(telemetryItem, \"time\", toISOString(new Date()), null, isNotTruthy);\r\n // Common Schema 4.0\r\n setValue(telemetryItem, \"ver\", \"4.0\", null, isNullOrUndefined);\r\n if (_self.isInitialized()) {\r\n // Process the telemetry plugin chain\r\n _self.getProcessTelContext().processNext(telemetryItem);\r\n }\r\n else {\r\n // Queue events until all extensions are initialized\r\n _eventQueue.push(telemetryItem);\r\n }\r\n };\r\n _self.getProcessTelContext = function () {\r\n return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);\r\n };\r\n _self.getNotifyMgr = function () {\r\n if (!_notificationManager) {\r\n // Create Dummy notification manager\r\n _notificationManager = objCreateFn({\r\n addNotificationListener: function (listener) { },\r\n removeNotificationListener: function (listener) { },\r\n eventsSent: function (events) { },\r\n eventsDiscarded: function (events, reason) { },\r\n eventsSendRequest: function (sendReason, isAsync) { }\r\n });\r\n // For backward compatibility only\r\n _self[strNotificationManager] = _notificationManager;\r\n }\r\n return _notificationManager;\r\n };\r\n /**\r\n * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.\r\n * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be\r\n * called.\r\n * @param {INotificationListener} listener - An INotificationListener object.\r\n */\r\n _self.addNotificationListener = function (listener) {\r\n if (_notificationManager) {\r\n _notificationManager.addNotificationListener(listener);\r\n }\r\n };\r\n /**\r\n * Removes all instances of the listener.\r\n * @param {INotificationListener} listener - INotificationListener to remove.\r\n */\r\n _self.removeNotificationListener = function (listener) {\r\n if (_notificationManager) {\r\n _notificationManager.removeNotificationListener(listener);\r\n }\r\n };\r\n _self.getCookieMgr = function () {\r\n if (!_cookieManager) {\r\n _cookieManager = createCookieMgr(_self.config, _self.logger);\r\n }\r\n return _cookieManager;\r\n };\r\n _self.setCookieMgr = function (cookieMgr) {\r\n _cookieManager = cookieMgr;\r\n };\r\n _self.getPerfMgr = function () {\r\n if (!_perfManager && !_cfgPerfManager) {\r\n if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {\r\n _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());\r\n }\r\n }\r\n return _perfManager || _cfgPerfManager || getGblPerfMgr();\r\n };\r\n _self.setPerfMgr = function (perfMgr) {\r\n _perfManager = perfMgr;\r\n };\r\n _self.eventCnt = function () {\r\n return _eventQueue.length;\r\n };\r\n _self.releaseQueue = function () {\r\n if (_isInitialized && _eventQueue.length > 0) {\r\n var eventQueue = _eventQueue;\r\n _eventQueue = [];\r\n arrForEach(eventQueue, function (event) {\r\n _self.getProcessTelContext().processNext(event);\r\n });\r\n }\r\n };\r\n /**\r\n * Periodically check logger.queue for log messages to be flushed\r\n */\r\n _self.pollInternalLogs = function (eventName) {\r\n _internalLogsEventName = eventName;\r\n var interval = _self.config.diagnosticLogInterval;\r\n if (!interval || !(interval > 0)) {\r\n interval = 10000;\r\n }\r\n if (_internalLogPoller) {\r\n clearInterval(_internalLogPoller);\r\n }\r\n _internalLogPoller = setInterval(function () {\r\n _flushInternalLogs();\r\n }, interval);\r\n return _internalLogPoller;\r\n };\r\n /**\r\n * Stop polling log messages from logger.queue\r\n */\r\n _self.stopPollingInternalLogs = function () {\r\n if (_internalLogPoller) {\r\n clearInterval(_internalLogPoller);\r\n _internalLogPoller = 0;\r\n _flushInternalLogs();\r\n }\r\n };\r\n // Add addTelemetryInitializer\r\n proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, [\"addTelemetryInitializer\"]);\r\n _self.getPlugin = _getPlugin;\r\n function _initDefaults() {\r\n _isInitialized = false;\r\n // Use a default logger so initialization errors are not dropped on the floor with full logging\r\n _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });\r\n _self.config = null;\r\n _self._extensions = [];\r\n _telemetryInitializerPlugin = new TelemetryInitializerPlugin();\r\n _eventQueue = [];\r\n _notificationManager = null;\r\n _perfManager = null;\r\n _cfgPerfManager = null;\r\n _cookieManager = null;\r\n _pluginChain = null;\r\n _coreExtensions = null;\r\n _configExtensions = null;\r\n _channelControl = null;\r\n _channelConfig = null;\r\n _channelQueue = null;\r\n _internalLogsEventName = null;\r\n }\r\n // Initialize or Re-initialize the plugins\r\n function _initPluginChain(config) {\r\n // Extension validation\r\n var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);\r\n _coreExtensions = theExtensions.core;\r\n _pluginChain = null;\r\n // Sort the complete set of extensions by priority\r\n var allExtensions = theExtensions.all;\r\n // Initialize the Channel Queues and the channel plugins first\r\n _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));\r\n _channelControl = createChannelControllerPlugin(_channelQueue, _self);\r\n // Add on \"channelController\" as the last \"plugin\"\r\n allExtensions.push(_channelControl);\r\n _coreExtensions.push(_channelControl);\r\n // Required to allow plugins to call core.getPlugin() during their own initialization\r\n _self._extensions = sortPlugins(allExtensions);\r\n // Initialize the controls\r\n _channelControl.initialize(config, _self, allExtensions);\r\n initializePlugins(_self.getProcessTelContext(), allExtensions);\r\n // Now reset the extensions to just those being managed by Basecore\r\n _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();\r\n }\r\n function _getPlugin(pluginIdentifier) {\r\n var theExt = null;\r\n var thePlugin = null;\r\n arrForEach(_self._extensions, function (ext) {\r\n if (ext.identifier === pluginIdentifier) {\r\n thePlugin = ext;\r\n return -1;\r\n }\r\n });\r\n if (thePlugin) {\r\n theExt = {\r\n plugin: thePlugin\r\n };\r\n }\r\n return theExt;\r\n }\r\n function _getPluginChain() {\r\n if (!_pluginChain) {\r\n // copy the collection of extensions\r\n var extensions = (_coreExtensions || []).slice();\r\n extensions.push(_telemetryInitializerPlugin);\r\n _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);\r\n }\r\n return _pluginChain;\r\n }\r\n function _flushInternalLogs() {\r\n var queue = _self.logger ? _self.logger.queue : [];\r\n if (queue) {\r\n arrForEach(queue, function (logMessage) {\r\n var item = {\r\n name: _internalLogsEventName ? _internalLogsEventName : \"InternalMessageId: \" + logMessage.messageId,\r\n iKey: _self.config.instrumentationKey,\r\n time: toISOString(new Date()),\r\n baseType: _InternalLogMessage.dataType,\r\n baseData: { message: logMessage.message }\r\n };\r\n _self.track(item);\r\n });\r\n queue.length = 0;\r\n }\r\n }\r\n function _initDebugListener(config) {\r\n if (config.disableDbgExt === true && _debugListener) {\r\n // Remove any previously loaded debug listener\r\n _notificationManager.removeNotificationListener(_debugListener);\r\n _debugListener = null;\r\n }\r\n if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {\r\n _debugListener = getDebugListener(config);\r\n _notificationManager.addNotificationListener(_debugListener);\r\n }\r\n }\r\n function _initPerfManager(config) {\r\n if (!config.enablePerfMgr && _cfgPerfManager) {\r\n // Remove any existing config based performance manager\r\n _cfgPerfManager = null;\r\n }\r\n if (config.enablePerfMgr) {\r\n // Set the performance manager creation function if not defined\r\n setValue(_self.config, \"createPerfMgr\", _createPerfManager);\r\n }\r\n }\r\n });\r\n }\r\n BaseCore.prototype.initialize = function (config, extensions, logger, notificationManager) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getTransmissionControls = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.track = function (telemetryItem) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getProcessTelContext = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.getNotifyMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.\r\n * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be\r\n * called.\r\n * @param {INotificationListener} listener - An INotificationListener object.\r\n */\r\n BaseCore.prototype.addNotificationListener = function (listener) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Removes all instances of the listener.\r\n * @param {INotificationListener} listener - INotificationListener to remove.\r\n */\r\n BaseCore.prototype.removeNotificationListener = function (listener) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Get the current cookie manager for this instance\r\n */\r\n BaseCore.prototype.getCookieMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Set the current cookie manager for this instance\r\n * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created\r\n */\r\n BaseCore.prototype.setCookieMgr = function (cookieMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getPerfMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.setPerfMgr = function (perfMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.eventCnt = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n /**\r\n * Periodically check logger.queue for\r\n */\r\n BaseCore.prototype.pollInternalLogs = function (eventName) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n /**\r\n * Periodically check logger.queue for\r\n */\r\n BaseCore.prototype.stopPollingInternalLogs = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add a telemetry processor to decorate or drop telemetry events.\r\n * @param telemetryInitializer - The Telemetry Initializer function\r\n * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed\r\n */\r\n BaseCore.prototype.addTelemetryInitializer = function (telemetryInitializer) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getPlugin = function (pluginIdentifier) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.releaseQueue = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return BaseCore;\r\n}());\r\nexport { BaseCore };\r\n//# sourceMappingURL=BaseCore.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA,wFAAsC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;oDAsFM;AACN;AACA;AACA;AACA"}
@@ -1,12 +1,13 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.7.4-nightly.2202-07
2
+ * Application Insights JavaScript SDK - Core, 2.8.0-beta.2202-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
6
6
 
7
7
  "use strict";
8
- import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
9
- import { isFunction, isNullOrUndefined, setValue } from "./HelperFuncs";
8
+ import dynamicProto from "@microsoft/dynamicproto-js";
9
+ import { createProcessTelemetryContext } from "./ProcessTelemetryContext";
10
+ import { isArray, isFunction, isNullOrUndefined, setValue } from "./HelperFuncs";
10
11
  import { strExtensionConfig } from "./Constants";
11
12
  var strGetPlugin = "getPlugin";
12
13
  /**
@@ -16,13 +17,32 @@ var strGetPlugin = "getPlugin";
16
17
  */
17
18
  var BaseTelemetryPlugin = /** @class */ (function () {
18
19
  function BaseTelemetryPlugin() {
19
- var _self = this;
20
- var _isinitialized = false;
21
- var _rootCtx = null; // Used as the root context, holding the current config and initialized core
22
- var _nextPlugin = null; // Used for backward compatibility where plugins don't call the main pipeline
23
- _self.core = null;
20
+ var _self = this; // Setting _self here as it's used outside of the dynamicProto as well
21
+ // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
22
+ var _isinitialized;
23
+ var _rootCtx; // Used as the root context, holding the current config and initialized core
24
+ var _nextPlugin; // Used for backward compatibility where plugins don't call the main pipeline
25
+ var _hooks;
26
+ _initDefaults();
27
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
28
+ _self.initialize = function (config, core, extensions, pluginChain) {
29
+ _setDefaults(config, core, pluginChain);
30
+ _isinitialized = true;
31
+ };
32
+ _self._addHook = function (hooks) {
33
+ if (hooks) {
34
+ if (isArray(hooks)) {
35
+ _hooks = _hooks.concat(hooks);
36
+ }
37
+ else {
38
+ _hooks.push(hooks);
39
+ }
40
+ }
41
+ };
42
+ });
43
+ // These are added after the dynamicProto so that are not moved to the prototype
24
44
  _self.diagLog = function (itemCtx) {
25
- return _self._getTelCtx(itemCtx).diagLog();
45
+ return _getTelCtx(itemCtx).diagLog();
26
46
  };
27
47
  _self.isInitialized = function () {
28
48
  return _isinitialized;
@@ -48,11 +68,12 @@ var BaseTelemetryPlugin = /** @class */ (function () {
48
68
  _nextPlugin.processTelemetry(env, null);
49
69
  }
50
70
  };
51
- _self._getTelCtx = function (currentCtx) {
71
+ _self._getTelCtx = _getTelCtx;
72
+ function _getTelCtx(currentCtx) {
52
73
  if (currentCtx === void 0) { currentCtx = null; }
53
74
  var itemCtx = currentCtx;
54
75
  if (!itemCtx) {
55
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
76
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
56
77
  // tslint:disable-next-line: prefer-conditional-expression
57
78
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
58
79
  // Looks like a chain object
@@ -63,8 +84,8 @@ var BaseTelemetryPlugin = /** @class */ (function () {
63
84
  }
64
85
  }
65
86
  return itemCtx;
66
- };
67
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
87
+ }
88
+ function _setDefaults(config, core, pluginChain) {
68
89
  if (config) {
69
90
  // Make sure the extensionConfig exists
70
91
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
@@ -80,13 +101,18 @@ var BaseTelemetryPlugin = /** @class */ (function () {
80
101
  }
81
102
  // Support legacy plugins where core was defined as a property
82
103
  _self.core = core;
83
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
84
- _isinitialized = true;
85
- };
104
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
105
+ }
106
+ function _initDefaults() {
107
+ _isinitialized = false;
108
+ _self.core = null;
109
+ _rootCtx = null;
110
+ _nextPlugin = null;
111
+ _hooks = [];
112
+ }
86
113
  }
87
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
88
- this._baseTelInit(config, core, extensions, pluginChain);
89
- };
114
+ // Removed Stub for BaseTelemetryPlugin.prototype.initialize.
115
+ // Removed Stub for BaseTelemetryPlugin.prototype._addHook.
90
116
  return BaseTelemetryPlugin;
91
117
  }());
92
118
  export { BaseTelemetryPlugin };
@@ -1 +1 @@
1
- {"version":3,"file":"BaseTelemetryPlugin.js.map","sources":["BaseTelemetryPlugin.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { ProcessTelemetryContext } from \"./ProcessTelemetryContext\";\r\nimport { isFunction, isNullOrUndefined, setValue } from \"./HelperFuncs\";\r\nimport { strExtensionConfig } from \"./Constants\";\r\nvar strGetPlugin = \"getPlugin\";\r\n/**\r\n * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins\r\n * can avoid implementation the same set of boiler plate code as well as provide a base\r\n * implementation so that new default implementations can be added without breaking all plugins.\r\n */\r\nvar BaseTelemetryPlugin = /** @class */ (function () {\r\n function BaseTelemetryPlugin() {\r\n var _self = this;\r\n var _isinitialized = false;\r\n var _rootCtx = null; // Used as the root context, holding the current config and initialized core\r\n var _nextPlugin = null; // Used for backward compatibility where plugins don't call the main pipeline\r\n _self.core = null;\r\n _self.diagLog = function (itemCtx) {\r\n return _self._getTelCtx(itemCtx).diagLog();\r\n };\r\n _self.isInitialized = function () {\r\n return _isinitialized;\r\n };\r\n _self.setInitialized = function (isInitialized) {\r\n _isinitialized = isInitialized;\r\n };\r\n // _self.getNextPlugin = () => DO NOT IMPLEMENT\r\n // Sub-classes of this base class *should* not be relying on this value and instead\r\n // should use processNext() function. If you require access to the plugin use the\r\n // IProcessTelemetryContext.getNext().getPlugin() while in the pipeline, Note getNext() may return null.\r\n _self.setNextPlugin = function (next) {\r\n _nextPlugin = next;\r\n };\r\n _self.processNext = function (env, itemCtx) {\r\n if (itemCtx) {\r\n // Normal core execution sequence\r\n itemCtx.processNext(env);\r\n }\r\n else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {\r\n // Looks like backward compatibility or out of band processing. And as it looks\r\n // like a ITelemetryPlugin or ITelemetryPluginChain, just call processTelemetry\r\n _nextPlugin.processTelemetry(env, null);\r\n }\r\n };\r\n _self._getTelCtx = function (currentCtx) {\r\n if (currentCtx === void 0) { currentCtx = null; }\r\n var itemCtx = currentCtx;\r\n if (!itemCtx) {\r\n var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);\r\n // tslint:disable-next-line: prefer-conditional-expression\r\n if (_nextPlugin && _nextPlugin[strGetPlugin]) {\r\n // Looks like a chain object\r\n itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);\r\n }\r\n else {\r\n itemCtx = rootCtx.createNew(null, _nextPlugin);\r\n }\r\n }\r\n return itemCtx;\r\n };\r\n _self._baseTelInit = function (config, core, extensions, pluginChain) {\r\n if (config) {\r\n // Make sure the extensionConfig exists\r\n setValue(config, strExtensionConfig, [], null, isNullOrUndefined);\r\n }\r\n if (!pluginChain && core) {\r\n // Get the first plugin from the core\r\n pluginChain = core.getProcessTelContext().getNext();\r\n }\r\n var nextPlugin = _nextPlugin;\r\n if (_nextPlugin && _nextPlugin[strGetPlugin]) {\r\n // If it looks like a proxy/chain then get the plugin\r\n nextPlugin = _nextPlugin[strGetPlugin]();\r\n }\r\n // Support legacy plugins where core was defined as a property\r\n _self.core = core;\r\n _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);\r\n _isinitialized = true;\r\n };\r\n }\r\n BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {\r\n this._baseTelInit(config, core, extensions, pluginChain);\r\n };\r\n return BaseTelemetryPlugin;\r\n}());\r\nexport { BaseTelemetryPlugin };\r\n//# sourceMappingURL=BaseTelemetryPlugin.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"file":"BaseTelemetryPlugin.js.map","sources":["BaseTelemetryPlugin.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { createProcessTelemetryContext } from \"./ProcessTelemetryContext\";\r\nimport { isArray, isFunction, isNullOrUndefined, setValue } from \"./HelperFuncs\";\r\nimport { strExtensionConfig } from \"./Constants\";\r\nvar strGetPlugin = \"getPlugin\";\r\n/**\r\n * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins\r\n * can avoid implementation the same set of boiler plate code as well as provide a base\r\n * implementation so that new default implementations can be added without breaking all plugins.\r\n */\r\nvar BaseTelemetryPlugin = /** @class */ (function () {\r\n function BaseTelemetryPlugin() {\r\n var _self = this; // Setting _self here as it's used outside of the dynamicProto as well\r\n // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()\r\n var _isinitialized;\r\n var _rootCtx; // Used as the root context, holding the current config and initialized core\r\n var _nextPlugin; // Used for backward compatibility where plugins don't call the main pipeline\r\n var _hooks;\r\n _initDefaults();\r\n dynamicProto(BaseTelemetryPlugin, _self, function (_self) {\r\n _self.initialize = function (config, core, extensions, pluginChain) {\r\n _setDefaults(config, core, pluginChain);\r\n _isinitialized = true;\r\n };\r\n _self._addHook = function (hooks) {\r\n if (hooks) {\r\n if (isArray(hooks)) {\r\n _hooks = _hooks.concat(hooks);\r\n }\r\n else {\r\n _hooks.push(hooks);\r\n }\r\n }\r\n };\r\n });\r\n // These are added after the dynamicProto so that are not moved to the prototype\r\n _self.diagLog = function (itemCtx) {\r\n return _getTelCtx(itemCtx).diagLog();\r\n };\r\n _self.isInitialized = function () {\r\n return _isinitialized;\r\n };\r\n _self.setInitialized = function (isInitialized) {\r\n _isinitialized = isInitialized;\r\n };\r\n // _self.getNextPlugin = () => DO NOT IMPLEMENT\r\n // Sub-classes of this base class *should* not be relying on this value and instead\r\n // should use processNext() function. If you require access to the plugin use the\r\n // IProcessTelemetryContext.getNext().getPlugin() while in the pipeline, Note getNext() may return null.\r\n _self.setNextPlugin = function (next) {\r\n _nextPlugin = next;\r\n };\r\n _self.processNext = function (env, itemCtx) {\r\n if (itemCtx) {\r\n // Normal core execution sequence\r\n itemCtx.processNext(env);\r\n }\r\n else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {\r\n // Looks like backward compatibility or out of band processing. And as it looks\r\n // like a ITelemetryPlugin or ITelemetryPluginChain, just call processTelemetry\r\n _nextPlugin.processTelemetry(env, null);\r\n }\r\n };\r\n _self._getTelCtx = _getTelCtx;\r\n function _getTelCtx(currentCtx) {\r\n if (currentCtx === void 0) { currentCtx = null; }\r\n var itemCtx = currentCtx;\r\n if (!itemCtx) {\r\n var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);\r\n // tslint:disable-next-line: prefer-conditional-expression\r\n if (_nextPlugin && _nextPlugin[strGetPlugin]) {\r\n // Looks like a chain object\r\n itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);\r\n }\r\n else {\r\n itemCtx = rootCtx.createNew(null, _nextPlugin);\r\n }\r\n }\r\n return itemCtx;\r\n }\r\n function _setDefaults(config, core, pluginChain) {\r\n if (config) {\r\n // Make sure the extensionConfig exists\r\n setValue(config, strExtensionConfig, [], null, isNullOrUndefined);\r\n }\r\n if (!pluginChain && core) {\r\n // Get the first plugin from the core\r\n pluginChain = core.getProcessTelContext().getNext();\r\n }\r\n var nextPlugin = _nextPlugin;\r\n if (_nextPlugin && _nextPlugin[strGetPlugin]) {\r\n // If it looks like a proxy/chain then get the plugin\r\n nextPlugin = _nextPlugin[strGetPlugin]();\r\n }\r\n // Support legacy plugins where core was defined as a property\r\n _self.core = core;\r\n _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);\r\n }\r\n function _initDefaults() {\r\n _isinitialized = false;\r\n _self.core = null;\r\n _rootCtx = null;\r\n _nextPlugin = null;\r\n _hooks = [];\r\n }\r\n }\r\n BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add this hook so that it is automatically removed during unloading\r\n * @param hooks - The single hook or an array of IInstrumentHook objects\r\n */\r\n BaseTelemetryPlugin.prototype._addHook = function (hooks) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return BaseTelemetryPlugin;\r\n}());\r\nexport { BaseTelemetryPlugin };\r\n//# sourceMappingURL=BaseTelemetryPlugin.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;2DASM;AACN;AACA;AACA;AACA"}