@microsoft/applicationinsights-core-js 3.0.0-beta.2209-03 → 3.0.0-beta.2210-02

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 (179) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1249 -675
  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 +3669 -1713
  7. package/dist/applicationinsights-core-js.api.md +131 -54
  8. package/dist/applicationinsights-core-js.d.ts +332 -131
  9. package/dist/applicationinsights-core-js.js +1249 -675
  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 +332 -131
  14. package/dist-esm/Config/ConfigDefaults.js +114 -0
  15. package/dist-esm/Config/ConfigDefaults.js.map +1 -0
  16. package/dist-esm/Config/DynamicConfig.js +129 -0
  17. package/dist-esm/Config/DynamicConfig.js.map +1 -0
  18. package/dist-esm/Config/DynamicProperty.js +139 -0
  19. package/dist-esm/Config/DynamicProperty.js.map +1 -0
  20. package/dist-esm/Config/DynamicState.js +109 -0
  21. package/dist-esm/Config/DynamicState.js.map +1 -0
  22. package/dist-esm/Config/DynamicSupport.js +57 -0
  23. package/dist-esm/Config/DynamicSupport.js.map +1 -0
  24. package/dist-esm/Config/IConfigDefaults.js +8 -0
  25. package/dist-esm/Config/IConfigDefaults.js.map +1 -0
  26. package/dist-esm/Config/IDynamicConfigHandler.js +8 -0
  27. package/dist-esm/Config/IDynamicConfigHandler.js.map +1 -0
  28. package/dist-esm/Config/IDynamicPropertyHandler.js +8 -0
  29. package/dist-esm/Config/IDynamicPropertyHandler.js.map +1 -0
  30. package/dist-esm/Config/IDynamicWatcher.js +8 -0
  31. package/dist-esm/Config/IDynamicWatcher.js.map +1 -0
  32. package/dist-esm/Config/_IDynamicConfigHandlerState.js +6 -0
  33. package/dist-esm/Config/_IDynamicConfigHandlerState.js.map +1 -0
  34. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +808 -23
  35. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +22 -18
  37. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/ChannelController.js +1 -1
  39. package/dist-esm/JavaScriptSDK/CookieMgr.js +78 -38
  40. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/CoreUtils.js +6 -5
  42. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  43. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +10 -8
  44. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  46. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +40 -23
  47. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  48. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -115
  49. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  50. package/dist-esm/JavaScriptSDK/EventHelpers.js +30 -29
  51. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -1
  52. package/dist-esm/JavaScriptSDK/HelperFuncs.js +19 -34
  53. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  54. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  55. package/dist-esm/JavaScriptSDK/InternalConstants.js +5 -1
  56. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -1
  57. package/dist-esm/JavaScriptSDK/NotificationManager.js +18 -11
  58. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  59. package/dist-esm/JavaScriptSDK/PerfManager.js +2 -3
  60. package/dist-esm/JavaScriptSDK/PerfManager.js.map +1 -1
  61. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +62 -53
  62. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  63. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  64. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +8 -10
  65. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  66. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +3 -4
  67. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
  68. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
  69. package/dist-esm/JavaScriptSDK/W3cTraceParent.js +12 -10
  70. package/dist-esm/JavaScriptSDK/W3cTraceParent.js.map +1 -1
  71. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -2
  72. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js.map +1 -1
  73. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +2 -107
  75. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  76. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  77. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  78. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
  79. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  80. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  81. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  82. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  83. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  84. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  85. package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js +1 -1
  86. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  87. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  88. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  89. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  90. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  91. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  92. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  93. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  94. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  95. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  96. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  97. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
  98. package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
  99. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js +8 -0
  100. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js.map +1 -0
  101. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +3 -1
  102. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -1
  103. package/dist-esm/__DynamicConstants.js +26 -23
  104. package/dist-esm/__DynamicConstants.js.map +1 -1
  105. package/dist-esm/applicationinsights-core-js.js +6 -4
  106. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  107. package/package.json +2 -2
  108. package/src/JavaScriptSDK/AppInsightsCore.ts +1156 -16
  109. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +25 -17
  110. package/src/JavaScriptSDK/CookieMgr.ts +88 -41
  111. package/src/JavaScriptSDK/CoreUtils.ts +4 -3
  112. package/src/JavaScriptSDK/DiagnosticLogger.ts +51 -29
  113. package/src/JavaScriptSDK/EnvUtils.ts +0 -133
  114. package/src/JavaScriptSDK/EventHelpers.ts +29 -28
  115. package/src/JavaScriptSDK/HelperFuncs.ts +22 -39
  116. package/src/JavaScriptSDK/InternalConstants.ts +5 -0
  117. package/src/JavaScriptSDK/NotificationManager.ts +25 -14
  118. package/src/JavaScriptSDK/PerfManager.ts +2 -2
  119. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +73 -56
  120. package/src/JavaScriptSDK/TelemetryHelpers.ts +8 -9
  121. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +2 -2
  122. package/src/JavaScriptSDK/W3cTraceParent.ts +7 -6
  123. package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +0 -1
  124. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +9 -108
  125. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +1 -1
  126. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +28 -3
  127. package/src/JavaScriptSDK.Interfaces/ICookieMgr.ts +8 -0
  128. package/src/JavaScriptSDK.Interfaces/IDiagnosticLogger.ts +15 -8
  129. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +3 -1
  130. package/src/JavaScriptSDK.Interfaces/INotificationListener.ts +5 -5
  131. package/src/JavaScriptSDK.Interfaces/INotificationManager.ts +8 -8
  132. package/src/JavaScriptSDK.Interfaces/IPerfManager.ts +3 -3
  133. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +10 -9
  134. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +2 -1
  135. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +15 -5
  136. package/src/JavaScriptSDK.Interfaces/IUnloadHook.ts +22 -0
  137. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +3 -3
  138. package/tsconfig.json +3 -2
  139. package/types/Config/ConfigDefaults.d.ts +10 -0
  140. package/types/Config/DynamicConfig.d.ts +23 -0
  141. package/types/Config/DynamicProperty.d.ts +3 -0
  142. package/types/Config/DynamicState.d.ts +3 -0
  143. package/types/Config/DynamicSupport.d.ts +15 -0
  144. package/types/Config/IConfigDefaults.d.ts +42 -0
  145. package/types/Config/IDynamicConfigHandler.d.ts +46 -0
  146. package/types/Config/IDynamicPropertyHandler.d.ts +11 -0
  147. package/types/Config/IDynamicWatcher.d.ts +28 -0
  148. package/types/Config/_IDynamicConfigHandlerState.d.ts +35 -0
  149. package/types/JavaScriptSDK/AppInsightsCore.d.ts +136 -4
  150. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +2 -2
  151. package/types/JavaScriptSDK/CookieMgr.d.ts +0 -10
  152. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +18 -16
  153. package/types/JavaScriptSDK/EventHelpers.d.ts +24 -24
  154. package/types/JavaScriptSDK/HelperFuncs.d.ts +13 -11
  155. package/types/JavaScriptSDK/InternalConstants.d.ts +4 -0
  156. package/types/JavaScriptSDK/NotificationManager.d.ts +7 -7
  157. package/types/JavaScriptSDK/PerfManager.d.ts +2 -2
  158. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +3 -2
  159. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -3
  160. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +7 -5
  161. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +1 -0
  162. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +25 -3
  163. package/types/JavaScriptSDK.Interfaces/ICookieMgr.d.ts +6 -0
  164. package/types/JavaScriptSDK.Interfaces/IDiagnosticLogger.d.ts +14 -8
  165. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +2 -1
  166. package/types/JavaScriptSDK.Interfaces/INotificationListener.d.ts +5 -5
  167. package/types/JavaScriptSDK.Interfaces/INotificationManager.d.ts +8 -8
  168. package/types/JavaScriptSDK.Interfaces/IPerfManager.d.ts +3 -3
  169. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +5 -9
  170. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +2 -1
  171. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +13 -2
  172. package/types/JavaScriptSDK.Interfaces/IUnloadHook.d.ts +18 -0
  173. package/types/__DynamicConstants.d.ts +18 -15
  174. package/types/applicationinsights-core-js.d.ts +11 -4
  175. package/types/tsdoc-metadata.json +1 -1
  176. package/dist-esm/JavaScriptSDK/BaseCore.js +0 -654
  177. package/dist-esm/JavaScriptSDK/BaseCore.js.map +0 -1
  178. package/src/JavaScriptSDK/BaseCore.ts +0 -948
  179. package/types/JavaScriptSDK/BaseCore.d.ts +0 -124
@@ -1,25 +1,247 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 3.0.0-beta.2209-03
2
+ * Application Insights JavaScript SDK - Core, 3.0.0-beta.2210-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
- import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
6
5
 
7
6
 
7
+ "use strict";
8
+ var _a;
9
+ import { __spreadArrayFn as __spreadArray } from "@microsoft/applicationinsights-shims";
8
10
  import dynamicProto from "@microsoft/dynamicproto-js";
9
- import { isNullOrUndefined, throwError } from "@nevware21/ts-utils";
10
- import { _DYN_GET_NOTIFY_MGR, _DYN_INITIALIZE, _DYN_NAME } from "../__DynamicConstants";
11
- import { BaseCore } from "./BaseCore";
12
- import { DiagnosticLogger } from "./DiagnosticLogger";
13
- import { STR_EVENTS_DISCARDED, STR_GET_PERF_MGR } from "./InternalConstants";
11
+ import { arrAppend, arrForEach, arrIndexOf, deepExtend, dumpObj, isFunction, isNullOrUndefined, objDeepFreeze, objDefineProp, objFreeze, objHasOwn, throwError } from "@nevware21/ts-utils";
12
+ import { applyDefaults } from "../Config/ConfigDefaults";
13
+ import { createDynamicConfig, onConfigChange } from "../Config/DynamicConfig";
14
+ import { _DYN_ADD_NOTIFICATION_LIS1, _DYN_CALL, _DYN_CONFIGURABLE, _DYN_ENUMERABLE, _DYN_FLUSH, _DYN_GET_NOTIFY_MGR, _DYN_GET_PLUGIN, _DYN_GET_PROCESS_TEL_CONT0, _DYN_IDENTIFIER, _DYN_INITIALIZE, _DYN_IS_ASYNC, _DYN_IS_INITIALIZED, _DYN_LENGTH, _DYN_LOGGER, _DYN_LOGGING_LEVEL_CONSOL4, _DYN_MESSAGE, _DYN_MESSAGE_ID, _DYN_NAME, _DYN_NOTIFY, _DYN_ON_COMPLETE, _DYN_PROCESS_NEXT, _DYN_PUSH, _DYN_REMOVE_NOTIFICATION_2, _DYN_SPLICE, _DYN_STOP_POLLING_INTERNA3, _DYN_TEARDOWN, _DYN_TIME, _DYN_WATCH, _DYN__EXTENSIONS } from "../__DynamicConstants";
15
+ import { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues } from "./ChannelController";
16
+ import { createCookieMgr } from "./CookieMgr";
17
+ import { createUniqueNamespace } from "./DataCacheHelper";
18
+ import { getDebugListener } from "./DbgExtensionUtils";
19
+ import { DiagnosticLogger, _InternalLogMessage, _throwInternal, _warnToConsole } from "./DiagnosticLogger";
20
+ import { getSetValue, isPlainObject, objForEachKey, proxyFunctionAs, proxyFunctions, toISOString } from "./HelperFuncs";
21
+ import { STR_CHANNELS, STR_CORE, STR_CREATE_PERF_MGR, STR_DISABLED, STR_EVENTS_DISCARDED, STR_EXTENSIONS, STR_EXTENSION_CONFIG, STR_GET_PERF_MGR, STR_PRIORITY, UNDEFINED_VALUE } from "./InternalConstants";
14
22
  import { NotificationManager } from "./NotificationManager";
15
- import { doPerf } from "./PerfManager";
16
- var AppInsightsCore = /** @class */ (function (_super) {
17
- __extends(AppInsightsCore, _super);
23
+ import { PerfManager, doPerf, getGblPerfMgr } from "./PerfManager";
24
+ import { createProcessTelemetryContext, createProcessTelemetryUnloadContext, createProcessTelemetryUpdateContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
25
+ import { _getPluginState, createDistributedTraceContext, initializePlugins, sortPlugins } from "./TelemetryHelpers";
26
+ import { TelemetryInitializerPlugin } from "./TelemetryInitializerPlugin";
27
+ import { createUnloadHandlerContainer } from "./UnloadHandlerContainer";
28
+ var strValidationError = "Plugins must provide initialize method";
29
+ var strNotificationManager = "_notificationManager";
30
+ var strSdkUnloadingError = "SDK is still unloading...";
31
+ var strSdkNotInitialized = "SDK is not initialized";
32
+ // const strPluginUnloadFailed = "Failed to unload plugin";
33
+ /**
34
+ * The default settings for the config.
35
+ * WE MUST include all defaults here to ensure that the config is created with all of the properties
36
+ * defined as dynamic.
37
+ */
38
+ var defaultConfig = objDeepFreeze((_a = {
39
+ cookieCfg: {}
40
+ },
41
+ _a[STR_EXTENSIONS] = [],
42
+ _a[STR_CHANNELS] = [],
43
+ _a[STR_EXTENSION_CONFIG] = {},
44
+ _a[STR_CREATE_PERF_MGR] = UNDEFINED_VALUE,
45
+ _a.loggingLevelConsole = 0 /* eLoggingSeverity.DISABLED */,
46
+ _a.diagnosticLogInterval = UNDEFINED_VALUE,
47
+ _a));
48
+ /**
49
+ * Helper to create the default performance manager
50
+ * @param core
51
+ * @param notificationMgr
52
+ */
53
+ function _createPerfManager(core, notificationMgr) {
54
+ return new PerfManager(notificationMgr);
55
+ }
56
+ function _validateExtensions(logger, channelPriority, allExtensions) {
57
+ var _a;
58
+ // Concat all available extensions
59
+ var coreExtensions = [];
60
+ // Check if any two extensions have the same priority, then warn to console
61
+ // And extract the local extensions from the
62
+ var extPriorities = {};
63
+ // Extension validation
64
+ arrForEach(allExtensions, function (ext) {
65
+ // Check for ext.initialize
66
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext[_DYN_INITIALIZE /* @min:%2einitialize */])) {
67
+ throwError(strValidationError);
68
+ }
69
+ var extPriority = ext[STR_PRIORITY /* @min:%2epriority */];
70
+ var identifier = ext[_DYN_IDENTIFIER /* @min:%2eidentifier */];
71
+ if (ext && extPriority) {
72
+ if (!isNullOrUndefined(extPriorities[extPriority])) {
73
+ _warnToConsole(logger, "Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
74
+ }
75
+ else {
76
+ // set a value
77
+ extPriorities[extPriority] = identifier;
78
+ }
79
+ }
80
+ // Split extensions to core and channelController
81
+ if (!extPriority || extPriority < channelPriority) {
82
+ // Add to core extension that will be managed by AppInsightsCore
83
+ coreExtensions[_DYN_PUSH /* @min:%2epush */](ext);
84
+ }
85
+ });
86
+ return _a = {
87
+ all: allExtensions
88
+ },
89
+ _a[STR_CORE /* @min:core */] = coreExtensions,
90
+ _a;
91
+ }
92
+ function _isPluginPresent(thePlugin, plugins) {
93
+ var exists = false;
94
+ arrForEach(plugins, function (plugin) {
95
+ if (plugin === thePlugin) {
96
+ exists = true;
97
+ return -1;
98
+ }
99
+ });
100
+ return exists;
101
+ }
102
+ function _deepMergeConfig(details, target, newValues, merge) {
103
+ // Lets assign the new values to the existing config
104
+ if (newValues) {
105
+ objForEachKey(newValues, function (key, value) {
106
+ if (merge) {
107
+ if (isPlainObject(value) && isPlainObject(target[key])) {
108
+ // The target is an object and it has a value
109
+ _deepMergeConfig(details, target[key], value, merge);
110
+ }
111
+ }
112
+ if (merge && isPlainObject(value) && isPlainObject(target[key])) {
113
+ // The target is an object and it has a value
114
+ _deepMergeConfig(details, target[key], value, merge);
115
+ }
116
+ else {
117
+ // Just Assign (replace) and/or make the property dynamic
118
+ details.hdlr.set(target, key, value);
119
+ }
120
+ });
121
+ }
122
+ }
123
+ function _findWatcher(listeners, newWatcher) {
124
+ var theListener = null;
125
+ var idx = -1;
126
+ arrForEach(listeners, function (listener, lp) {
127
+ if (listener.w === newWatcher) {
128
+ theListener = listener;
129
+ idx = lp;
130
+ return -1;
131
+ }
132
+ });
133
+ return { i: idx, l: theListener };
134
+ }
135
+ function _addDelayedCfgListener(listeners, newWatcher) {
136
+ var theListener = _findWatcher(listeners, newWatcher).l;
137
+ if (!theListener) {
138
+ theListener = {
139
+ w: newWatcher,
140
+ rm: function () {
141
+ var fnd = _findWatcher(listeners, newWatcher);
142
+ if (fnd.i !== -1) {
143
+ listeners[_DYN_SPLICE /* @min:%2esplice */](fnd.i, 1);
144
+ }
145
+ }
146
+ };
147
+ listeners[_DYN_PUSH /* @min:%2epush */](theListener);
148
+ }
149
+ return theListener;
150
+ }
151
+ function _registerDelayedCfgListener(config, listeners, logger) {
152
+ arrForEach(listeners, function (listener) {
153
+ var unloadHdl = onConfigChange(config, listener.w, logger);
154
+ delete listener.w; // Clear the listener reference so it will get garbage collected.
155
+ // replace the remove function
156
+ listener.rm = function () {
157
+ unloadHdl.rm();
158
+ };
159
+ });
160
+ }
161
+ var AppInsightsCore = /** @class */ (function () {
18
162
  function AppInsightsCore() {
19
- var _this = _super.call(this) || this;
20
- dynamicProto(AppInsightsCore, _this, function (_self, _base) {
163
+ // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
164
+ var _configHandler;
165
+ var _isInitialized;
166
+ var _eventQueue;
167
+ var _notificationManager;
168
+ var _perfManager;
169
+ var _cfgPerfManager;
170
+ var _cookieManager;
171
+ var _pluginChain;
172
+ var _configExtensions;
173
+ var _coreExtensions;
174
+ var _channelControl;
175
+ var _channelConfig;
176
+ var _channelQueue;
177
+ var _isUnloading;
178
+ var _telemetryInitializerPlugin;
179
+ var _internalLogsEventName;
180
+ var _evtNamespace;
181
+ var _unloadHandlers;
182
+ var _hooks;
183
+ var _debugListener;
184
+ var _traceCtx;
185
+ var _instrumentationKey;
186
+ var _cfgListeners;
187
+ /**
188
+ * Internal log poller
189
+ */
190
+ var _internalLogPoller = 0;
191
+ dynamicProto(AppInsightsCore, this, function (_self) {
192
+ // Set the default values (also called during teardown)
193
+ _initDefaults();
194
+ _self[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */] = function () { return _isInitialized; };
195
+ // Creating the self.initialize = ()
21
196
  _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (config, extensions, logger, notificationManager) {
22
- _base[_DYN_INITIALIZE /* @min:%2einitialize */](config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
197
+ if (_isUnloading) {
198
+ throwError(strSdkUnloadingError);
199
+ }
200
+ // Make sure core is only initialized once
201
+ if (_self[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */]()) {
202
+ throwError("Core cannot be initialized more than once");
203
+ }
204
+ // Re-assigning the local config property so we don't have any references to the passed value and it can be garbage collected
205
+ _configHandler = createDynamicConfig(config, defaultConfig, logger || _self[_DYN_LOGGER /* @min:%2elogger */], false);
206
+ config = _configHandler.cfg;
207
+ // This will be "re-run" if the referenced config properties are changed
208
+ _addUnloadHook(_configHandler[_DYN_WATCH /* @min:%2ewatch */](function (details) {
209
+ _instrumentationKey = details.cfg.instrumentationKey;
210
+ if (isNullOrUndefined(_instrumentationKey)) {
211
+ throwError("Please provide instrumentation key");
212
+ }
213
+ }));
214
+ _notificationManager = notificationManager;
215
+ // For backward compatibility only
216
+ _self[strNotificationManager] = notificationManager;
217
+ _initDebugListener();
218
+ _initPerfManager();
219
+ // add notification to the extensions in the config so other plugins can access it
220
+ _initExtConfig();
221
+ _self[_DYN_LOGGER /* @min:%2elogger */] = logger || new DiagnosticLogger(config);
222
+ _configHandler[_DYN_LOGGER /* @min:%2elogger */] = _self[_DYN_LOGGER /* @min:%2elogger */];
223
+ var cfgExtensions = config[STR_EXTENSIONS /* @min:%2eextensions */];
224
+ // Extension validation
225
+ _configExtensions = [];
226
+ _configExtensions[_DYN_PUSH /* @min:%2epush */].apply(_configExtensions, __spreadArray(__spreadArray([], extensions, false), cfgExtensions, false));
227
+ _channelConfig = config[STR_CHANNELS /* @min:%2echannels */];
228
+ _initPluginChain(null);
229
+ if (!_channelQueue || _channelQueue[_DYN_LENGTH /* @min:%2elength */] === 0) {
230
+ throwError("No " + STR_CHANNELS + " available");
231
+ }
232
+ _registerDelayedCfgListener(config, _cfgListeners, _self[_DYN_LOGGER /* @min:%2elogger */]);
233
+ _cfgListeners = null;
234
+ _isInitialized = true;
235
+ _self.releaseQueue();
236
+ };
237
+ _self.getTransmissionControls = function () {
238
+ var controls = [];
239
+ if (_channelQueue) {
240
+ arrForEach(_channelQueue, function (channels) {
241
+ controls[_DYN_PUSH /* @min:%2epush */](channels.queue);
242
+ });
243
+ }
244
+ return objFreeze(controls);
23
245
  };
24
246
  _self.track = function (telemetryItem) {
25
247
  doPerf(_self[STR_GET_PERF_MGR /* @min:%2egetPerfMgr */](), function () { return "AppInsightsCore:track"; }, function () {
@@ -29,14 +251,548 @@ var AppInsightsCore = /** @class */ (function (_super) {
29
251
  throwError("Invalid telemetry item");
30
252
  }
31
253
  // do basic validation before sending it through the pipeline
32
- _validateTelemetryItem(telemetryItem);
33
- _base.track(telemetryItem);
254
+ if (!telemetryItem[_DYN_NAME /* @min:%2ename */] && isNullOrUndefined(telemetryItem[_DYN_NAME /* @min:%2ename */])) {
255
+ _notifyInvalidEvent(telemetryItem);
256
+ throwError("telemetry name required");
257
+ }
258
+ // setup default iKey if not passed in
259
+ telemetryItem.iKey = telemetryItem.iKey || _instrumentationKey;
260
+ // add default timestamp if not passed in
261
+ telemetryItem[_DYN_TIME /* @min:%2etime */] = telemetryItem[_DYN_TIME /* @min:%2etime */] || toISOString(new Date());
262
+ // Common Schema 4.0
263
+ telemetryItem.ver = telemetryItem.ver || "4.0";
264
+ if (!_isUnloading && _self[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */]()) {
265
+ // Process the telemetry plugin chain
266
+ _createTelCtx()[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](telemetryItem);
267
+ }
268
+ else {
269
+ // Queue events until all extensions are initialized
270
+ _eventQueue[_DYN_PUSH /* @min:%2epush */](telemetryItem);
271
+ }
34
272
  }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
35
273
  };
36
- function _validateTelemetryItem(telemetryItem) {
37
- if (isNullOrUndefined(telemetryItem[_DYN_NAME /* @min:%2ename */])) {
38
- _notifyInvalidEvent(telemetryItem);
39
- throwError("telemetry name required");
274
+ _self[_DYN_GET_PROCESS_TEL_CONT0 /* @min:%2egetProcessTelContext */] = _createTelCtx;
275
+ _self[_DYN_GET_NOTIFY_MGR /* @min:%2egetNotifyMgr */] = function () {
276
+ if (!_notificationManager) {
277
+ _addUnloadHook(_configHandler[_DYN_WATCH /* @min:%2ewatch */](function (details) {
278
+ _notificationManager = new NotificationManager(details.cfg);
279
+ // For backward compatibility only
280
+ _self[strNotificationManager] = _notificationManager;
281
+ }));
282
+ }
283
+ return _notificationManager;
284
+ };
285
+ /**
286
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
287
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
288
+ * called.
289
+ * @param listener - An INotificationListener object.
290
+ */
291
+ _self[_DYN_ADD_NOTIFICATION_LIS1 /* @min:%2eaddNotificationListener */] = function (listener) {
292
+ if (_notificationManager) {
293
+ _notificationManager[_DYN_ADD_NOTIFICATION_LIS1 /* @min:%2eaddNotificationListener */](listener);
294
+ }
295
+ };
296
+ /**
297
+ * Removes all instances of the listener.
298
+ * @param listener - INotificationListener to remove.
299
+ */
300
+ _self[_DYN_REMOVE_NOTIFICATION_2 /* @min:%2eremoveNotificationListener */] = function (listener) {
301
+ if (_notificationManager) {
302
+ _notificationManager[_DYN_REMOVE_NOTIFICATION_2 /* @min:%2eremoveNotificationListener */](listener);
303
+ }
304
+ };
305
+ _self.getCookieMgr = function () {
306
+ if (!_cookieManager) {
307
+ _addUnloadHook(_configHandler[_DYN_WATCH /* @min:%2ewatch */](function (details) {
308
+ _cookieManager = createCookieMgr(details.cfg, _self[_DYN_LOGGER /* @min:%2elogger */]);
309
+ }));
310
+ }
311
+ return _cookieManager;
312
+ };
313
+ _self.setCookieMgr = function (cookieMgr) {
314
+ _cookieManager = cookieMgr;
315
+ };
316
+ _self[STR_GET_PERF_MGR /* @min:%2egetPerfMgr */] = function () {
317
+ if (!_perfManager && !_cfgPerfManager) {
318
+ _addUnloadHook(_configHandler[_DYN_WATCH /* @min:%2ewatch */](function (details) {
319
+ if (details.cfg.enablePerfMgr) {
320
+ var createPerfMgr = details.cfg[STR_CREATE_PERF_MGR /* @min:%2ecreatePerfMgr */];
321
+ if (isFunction(createPerfMgr)) {
322
+ _cfgPerfManager = createPerfMgr(_self, _self[_DYN_GET_NOTIFY_MGR /* @min:%2egetNotifyMgr */]());
323
+ }
324
+ }
325
+ }));
326
+ }
327
+ return _perfManager || _cfgPerfManager || getGblPerfMgr();
328
+ };
329
+ _self.setPerfMgr = function (perfMgr) {
330
+ _perfManager = perfMgr;
331
+ };
332
+ _self.eventCnt = function () {
333
+ return _eventQueue[_DYN_LENGTH /* @min:%2elength */];
334
+ };
335
+ _self.releaseQueue = function () {
336
+ if (_isInitialized && _eventQueue[_DYN_LENGTH /* @min:%2elength */] > 0) {
337
+ var eventQueue = _eventQueue;
338
+ _eventQueue = [];
339
+ arrForEach(eventQueue, function (event) {
340
+ _createTelCtx()[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](event);
341
+ });
342
+ }
343
+ };
344
+ /**
345
+ * Periodically check logger.queue for log messages to be flushed
346
+ */
347
+ _self.pollInternalLogs = function (eventName) {
348
+ _internalLogsEventName = eventName || null;
349
+ _addUnloadHook(_configHandler[_DYN_WATCH /* @min:%2ewatch */](function (details) {
350
+ var interval = details.cfg.diagnosticLogInterval;
351
+ if (!interval || !(interval > 0)) {
352
+ interval = 10000;
353
+ }
354
+ if (_internalLogPoller) {
355
+ clearInterval(_internalLogPoller);
356
+ }
357
+ _internalLogPoller = setInterval(function () {
358
+ _flushInternalLogs();
359
+ }, interval);
360
+ }));
361
+ return _internalLogPoller;
362
+ };
363
+ /**
364
+ * Stop polling log messages from logger.queue
365
+ */
366
+ _self[_DYN_STOP_POLLING_INTERNA3 /* @min:%2estopPollingInternalLogs */] = function () {
367
+ if (_internalLogPoller) {
368
+ clearInterval(_internalLogPoller);
369
+ _internalLogPoller = 0;
370
+ _flushInternalLogs();
371
+ }
372
+ };
373
+ // Add addTelemetryInitializer
374
+ proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
375
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
376
+ var _a;
377
+ if (isAsync === void 0) { isAsync = true; }
378
+ if (!_isInitialized) {
379
+ // The SDK is not initialized
380
+ throwError(strSdkNotInitialized);
381
+ }
382
+ // Check if the SDK still unloading so throw
383
+ if (_isUnloading) {
384
+ // The SDK is already unloading
385
+ throwError(strSdkUnloadingError);
386
+ }
387
+ var unloadState = (_a = {
388
+ reason: 50 /* TelemetryUnloadReason.SdkUnload */
389
+ },
390
+ _a[_DYN_IS_ASYNC /* @min:isAsync */] = isAsync,
391
+ _a.flushComplete = false,
392
+ _a);
393
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self);
394
+ processUnloadCtx[_DYN_ON_COMPLETE /* @min:%2eonComplete */](function () {
395
+ var oldHooks = _hooks;
396
+ _hooks = [];
397
+ // Remove all registered unload hooks
398
+ arrForEach(oldHooks, function (fn) {
399
+ // allow either rm or remove callback function
400
+ try {
401
+ (fn.rm || fn.remove)[_DYN_CALL /* @min:%2ecall */](fn);
402
+ }
403
+ catch (e) {
404
+ _throwInternal(_self[_DYN_LOGGER /* @min:%2elogger */], 2 /* eLoggingSeverity.WARNING */, 73 /* _eInternalMessageId.PluginException */, "Unloading:" + dumpObj(e));
405
+ }
406
+ });
407
+ _initDefaults();
408
+ unloadComplete && unloadComplete(unloadState);
409
+ }, _self);
410
+ function _doUnload(flushComplete) {
411
+ unloadState.flushComplete = flushComplete;
412
+ _isUnloading = true;
413
+ // Run all of the unload handlers first (before unloading the plugins)
414
+ _unloadHandlers.run(processUnloadCtx, unloadState);
415
+ // Stop polling the internal logs
416
+ _self[_DYN_STOP_POLLING_INTERNA3 /* @min:%2estopPollingInternalLogs */]();
417
+ // Start unloading the components, from this point onwards the SDK should be considered to be in an unstable state
418
+ processUnloadCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](unloadState);
419
+ }
420
+ if (!_flushChannels(isAsync, _doUnload, 6 /* SendRequestReason.SdkUnload */, cbTimeout)) {
421
+ _doUnload(false);
422
+ }
423
+ };
424
+ _self[_DYN_GET_PLUGIN /* @min:%2egetPlugin */] = _getPlugin;
425
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
426
+ if (!plugin) {
427
+ addCb && addCb(false);
428
+ _logOrThrowError(strValidationError);
429
+ return;
430
+ }
431
+ var existingPlugin = _getPlugin(plugin[_DYN_IDENTIFIER /* @min:%2eidentifier */]);
432
+ if (existingPlugin && !replaceExisting) {
433
+ addCb && addCb(false);
434
+ _logOrThrowError("Plugin [" + plugin[_DYN_IDENTIFIER /* @min:%2eidentifier */] + "] is already loaded!");
435
+ return;
436
+ }
437
+ var updateState = {
438
+ reason: 16 /* TelemetryUpdateReason.PluginAdded */
439
+ };
440
+ function _addPlugin(removed) {
441
+ _configExtensions[_DYN_PUSH /* @min:%2epush */](plugin);
442
+ updateState.added = [plugin];
443
+ // Re-Initialize the plugin chain
444
+ _initPluginChain(updateState);
445
+ addCb && addCb(true);
446
+ }
447
+ if (existingPlugin) {
448
+ var removedPlugins_1 = [existingPlugin.plugin];
449
+ var unloadState = {
450
+ reason: 2 /* TelemetryUnloadReason.PluginReplace */,
451
+ isAsync: !!isAsync
452
+ };
453
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
454
+ if (!removed) {
455
+ // Previous plugin was successfully removed or was not installed
456
+ addCb && addCb(false);
457
+ }
458
+ else {
459
+ updateState.removed = removedPlugins_1;
460
+ updateState.reason |= 32 /* TelemetryUpdateReason.PluginRemoved */;
461
+ _addPlugin(true);
462
+ }
463
+ });
464
+ }
465
+ else {
466
+ _addPlugin(false);
467
+ }
468
+ };
469
+ _self.updateCfg = function (newConfig, mergeExisting) {
470
+ if (mergeExisting === void 0) { mergeExisting = true; }
471
+ var updateState = {
472
+ reason: 1 /* TelemetryUpdateReason.ConfigurationChanged */,
473
+ cfg: _configHandler.cfg,
474
+ oldCfg: deepExtend({}, _configHandler.cfg),
475
+ newConfig: deepExtend({}, newConfig),
476
+ merge: mergeExisting
477
+ };
478
+ newConfig = updateState.newConfig;
479
+ var cfg = _configHandler.cfg;
480
+ // replace the immutable values
481
+ newConfig[STR_EXTENSIONS /* @min:%2eextensions */] = cfg[STR_EXTENSIONS /* @min:%2eextensions */];
482
+ newConfig[STR_CHANNELS /* @min:%2echannels */] = cfg[STR_CHANNELS /* @min:%2echannels */];
483
+ // We don't currently allow updating the extensions and channels via the update config
484
+ // So overwriting any user provided values to reuse the existing values
485
+ // Explicitly blocking any previous config watchers so that they don't get called because
486
+ // of this bulk update (Probably not necessary)
487
+ _configHandler._block(function (details) {
488
+ // Lets assign the new values to the existing config either overwriting or re-assigning
489
+ var theConfig = details.cfg;
490
+ _deepMergeConfig(details, theConfig, newConfig, mergeExisting);
491
+ if (!mergeExisting) {
492
+ // Remove (unassign) the values "missing" from the newConfig and also not in the default config
493
+ objForEachKey(theConfig, function (key) {
494
+ if (!objHasOwn(newConfig, key)) {
495
+ // Set the value to undefined
496
+ details.hdlr.set(theConfig, key, UNDEFINED_VALUE);
497
+ }
498
+ });
499
+ }
500
+ // Apply defaults to the new config
501
+ applyDefaults(theConfig, defaultConfig);
502
+ // Reapply the notification manager
503
+ _initExtConfig();
504
+ });
505
+ // Now execute all of the listeners (synchronously) so they update their values immediately
506
+ _configHandler[_DYN_NOTIFY /* @min:%2enotify */]();
507
+ _doUpdate(updateState);
508
+ };
509
+ _self.evtNamespace = function () {
510
+ return _evtNamespace;
511
+ };
512
+ _self[_DYN_FLUSH /* @min:%2eflush */] = _flushChannels;
513
+ _self.getTraceCtx = function (createNew) {
514
+ if (!_traceCtx) {
515
+ _traceCtx = createDistributedTraceContext();
516
+ }
517
+ return _traceCtx;
518
+ };
519
+ _self.setTraceCtx = function (traceCtx) {
520
+ _traceCtx = traceCtx || null;
521
+ };
522
+ _self.addUnloadHook = _addUnloadHook;
523
+ // Create the addUnloadCb
524
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
525
+ _self.onCfgChange = function (handler) {
526
+ var unloadHook;
527
+ if (!_isInitialized) {
528
+ unloadHook = _addDelayedCfgListener(_cfgListeners, handler);
529
+ }
530
+ else {
531
+ unloadHook = onConfigChange(_configHandler.cfg, handler, _self[_DYN_LOGGER /* @min:%2elogger */]);
532
+ }
533
+ return {
534
+ rm: function () {
535
+ unloadHook.rm();
536
+ }
537
+ };
538
+ };
539
+ function _initDefaults() {
540
+ var _a;
541
+ _isInitialized = false;
542
+ // Use a default logger so initialization errors are not dropped on the floor with full logging
543
+ _configHandler = createDynamicConfig({}, defaultConfig, _self[_DYN_LOGGER /* @min:%2elogger */]);
544
+ // Set the logging level to critical so that any critical initialization failures are displayed on the console
545
+ _configHandler.cfg[_DYN_LOGGING_LEVEL_CONSOL4 /* @min:%2eloggingLevelConsole */] = 1 /* eLoggingSeverity.CRITICAL */;
546
+ // Define _self.config
547
+ objDefineProp(_self, "config", (_a = {},
548
+ _a[_DYN_CONFIGURABLE /* @min:configurable */] = true,
549
+ _a[_DYN_ENUMERABLE /* @min:enumerable */] = true,
550
+ _a.get = function () { return _configHandler.cfg; },
551
+ _a.set = function (newValue) {
552
+ if (_self[_DYN_IS_INITIALIZED /* @min:%2eisInitialized */]()) {
553
+ _self.updateCfg(newValue, false);
554
+ }
555
+ },
556
+ _a));
557
+ _self[_DYN_LOGGER /* @min:%2elogger */] = new DiagnosticLogger(_configHandler.cfg);
558
+ _self[_DYN__EXTENSIONS /* @min:%2e_extensions */] = [];
559
+ _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
560
+ _eventQueue = [];
561
+ _notificationManager = null;
562
+ _perfManager = null;
563
+ _cfgPerfManager = null;
564
+ _cookieManager = null;
565
+ _pluginChain = null;
566
+ _coreExtensions = null;
567
+ _configExtensions = [];
568
+ _channelControl = null;
569
+ _channelConfig = null;
570
+ _channelQueue = null;
571
+ _isUnloading = false;
572
+ _internalLogsEventName = null;
573
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
574
+ _unloadHandlers = createUnloadHandlerContainer();
575
+ _traceCtx = null;
576
+ _instrumentationKey = null;
577
+ _hooks = [];
578
+ _cfgListeners = [];
579
+ }
580
+ function _createTelCtx() {
581
+ return createProcessTelemetryContext(_getPluginChain(), _configHandler.cfg, _self);
582
+ }
583
+ // Initialize or Re-initialize the plugins
584
+ function _initPluginChain(updateState) {
585
+ // Extension validation
586
+ var theExtensions = _validateExtensions(_self[_DYN_LOGGER /* @min:%2elogger */], ChannelControllerPriority, _configExtensions);
587
+ _coreExtensions = theExtensions[STR_CORE /* @min:%2ecore */];
588
+ _pluginChain = null;
589
+ // Sort the complete set of extensions by priority
590
+ var allExtensions = theExtensions.all;
591
+ // Initialize the Channel Queues and the channel plugins first
592
+ _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, _self));
593
+ if (_channelControl) {
594
+ // During add / remove of a plugin this may get called again, so don't re-add if already present
595
+ // But we also want the controller as the last, so remove if already present
596
+ // And reusing the existing instance, just in case an installed plugin has a reference and
597
+ // is using it.
598
+ var idx = arrIndexOf(allExtensions, _channelControl);
599
+ if (idx !== -1) {
600
+ allExtensions[_DYN_SPLICE /* @min:%2esplice */](idx, 1);
601
+ }
602
+ idx = arrIndexOf(_coreExtensions, _channelControl);
603
+ if (idx !== -1) {
604
+ _coreExtensions[_DYN_SPLICE /* @min:%2esplice */](idx, 1);
605
+ }
606
+ _channelControl._setQueue(_channelQueue);
607
+ }
608
+ else {
609
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
610
+ }
611
+ // Add on "channelController" as the last "plugin"
612
+ allExtensions[_DYN_PUSH /* @min:%2epush */](_channelControl);
613
+ _coreExtensions[_DYN_PUSH /* @min:%2epush */](_channelControl);
614
+ // Required to allow plugins to call core.getPlugin() during their own initialization
615
+ _self[_DYN__EXTENSIONS /* @min:%2e_extensions */] = sortPlugins(allExtensions);
616
+ // Initialize the controls
617
+ _channelControl[_DYN_INITIALIZE /* @min:%2einitialize */](_configHandler.cfg, _self, allExtensions);
618
+ initializePlugins(_createTelCtx(), allExtensions);
619
+ // Now reset the extensions to just those being managed by AppInsightsCore
620
+ _self[_DYN__EXTENSIONS /* @min:%2e_extensions */] = objFreeze(sortPlugins(_coreExtensions || [])).slice();
621
+ if (updateState) {
622
+ _doUpdate(updateState);
623
+ }
624
+ }
625
+ function _getPlugin(pluginIdentifier) {
626
+ var theExt = null;
627
+ var thePlugin = null;
628
+ arrForEach(_self[_DYN__EXTENSIONS /* @min:%2e_extensions */], function (ext) {
629
+ if (ext[_DYN_IDENTIFIER /* @min:%2eidentifier */] === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
630
+ thePlugin = ext;
631
+ return -1;
632
+ }
633
+ });
634
+ if (!thePlugin && _channelControl) {
635
+ // Check the channel Controller
636
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
637
+ }
638
+ if (thePlugin) {
639
+ theExt = {
640
+ plugin: thePlugin,
641
+ setEnabled: function (enabled) {
642
+ _getPluginState(thePlugin)[STR_DISABLED] = !enabled;
643
+ },
644
+ isEnabled: function () {
645
+ var pluginState = _getPluginState(thePlugin);
646
+ return !pluginState[_DYN_TEARDOWN /* @min:%2eteardown */] && !pluginState[STR_DISABLED];
647
+ },
648
+ remove: function (isAsync, removeCb) {
649
+ var _a;
650
+ if (isAsync === void 0) { isAsync = true; }
651
+ var pluginsToRemove = [thePlugin];
652
+ var unloadState = (_a = {
653
+ reason: 1 /* TelemetryUnloadReason.PluginUnload */
654
+ },
655
+ _a[_DYN_IS_ASYNC /* @min:isAsync */] = isAsync,
656
+ _a);
657
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
658
+ if (removed) {
659
+ // Re-Initialize the plugin chain
660
+ _initPluginChain({
661
+ reason: 32 /* TelemetryUpdateReason.PluginRemoved */,
662
+ removed: pluginsToRemove
663
+ });
664
+ }
665
+ removeCb && removeCb(removed);
666
+ });
667
+ }
668
+ };
669
+ }
670
+ return theExt;
671
+ }
672
+ function _getPluginChain() {
673
+ if (!_pluginChain) {
674
+ // copy the collection of extensions
675
+ var extensions = (_coreExtensions || []).slice();
676
+ // During add / remove this may get called again, so don't readd if already present
677
+ if (arrIndexOf(extensions, _telemetryInitializerPlugin) === -1) {
678
+ extensions[_DYN_PUSH /* @min:%2epush */](_telemetryInitializerPlugin);
679
+ }
680
+ _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _configHandler.cfg, _self);
681
+ }
682
+ return _pluginChain;
683
+ }
684
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
685
+ if (thePlugins && thePlugins[_DYN_LENGTH /* @min:%2elength */] > 0) {
686
+ var unloadChain = createTelemetryProxyChain(thePlugins, _configHandler.cfg, _self);
687
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self);
688
+ unloadCtx[_DYN_ON_COMPLETE /* @min:%2eonComplete */](function () {
689
+ var removed = false;
690
+ // Remove the listed config extensions
691
+ var newConfigExtensions = [];
692
+ arrForEach(_configExtensions, function (plugin, idx) {
693
+ if (!_isPluginPresent(plugin, thePlugins)) {
694
+ newConfigExtensions[_DYN_PUSH /* @min:%2epush */](plugin);
695
+ }
696
+ else {
697
+ removed = true;
698
+ }
699
+ });
700
+ _configExtensions = newConfigExtensions;
701
+ // Re-Create the channel config
702
+ var newChannelConfig = [];
703
+ if (_channelConfig) {
704
+ arrForEach(_channelConfig, function (queue, idx) {
705
+ var newQueue = [];
706
+ arrForEach(queue, function (channel) {
707
+ if (!_isPluginPresent(channel, thePlugins)) {
708
+ newQueue[_DYN_PUSH /* @min:%2epush */](channel);
709
+ }
710
+ else {
711
+ removed = true;
712
+ }
713
+ });
714
+ newChannelConfig[_DYN_PUSH /* @min:%2epush */](newQueue);
715
+ });
716
+ _channelConfig = newChannelConfig;
717
+ }
718
+ removeComplete && removeComplete(removed);
719
+ });
720
+ unloadCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](unloadState);
721
+ }
722
+ else {
723
+ removeComplete(false);
724
+ }
725
+ }
726
+ function _flushInternalLogs() {
727
+ var queue = _self[_DYN_LOGGER /* @min:%2elogger */] ? _self[_DYN_LOGGER /* @min:%2elogger */].queue : [];
728
+ if (queue) {
729
+ arrForEach(queue, function (logMessage) {
730
+ var _a;
731
+ var item = (_a = {},
732
+ _a[_DYN_NAME /* @min:name */] = _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage[_DYN_MESSAGE_ID /* @min:%2emessageId */],
733
+ _a.iKey = _instrumentationKey,
734
+ _a.time = toISOString(new Date()),
735
+ _a.baseType = _InternalLogMessage.dataType,
736
+ _a.baseData = { message: logMessage[_DYN_MESSAGE /* @min:%2emessage */] },
737
+ _a);
738
+ _self.track(item);
739
+ });
740
+ queue[_DYN_LENGTH /* @min:%2elength */] = 0;
741
+ }
742
+ }
743
+ function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
744
+ if (_channelControl) {
745
+ return _channelControl[_DYN_FLUSH /* @min:%2eflush */](isAsync, callBack, sendReason || 6 /* SendRequestReason.SdkUnload */, cbTimeout);
746
+ }
747
+ callBack && callBack(false);
748
+ return true;
749
+ }
750
+ function _initDebugListener() {
751
+ // Will get recalled if any referenced config values are changed
752
+ _addUnloadHook(_configHandler[_DYN_WATCH /* @min:%2ewatch */](function (details) {
753
+ var disableDbgExt = details.cfg.disableDbgExt;
754
+ if (disableDbgExt === true && _debugListener) {
755
+ // Remove any previously loaded debug listener
756
+ _notificationManager[_DYN_REMOVE_NOTIFICATION_2 /* @min:%2eremoveNotificationListener */](_debugListener);
757
+ _debugListener = null;
758
+ }
759
+ if (_notificationManager && !_debugListener && disableDbgExt !== true) {
760
+ _debugListener = getDebugListener(details.cfg);
761
+ _notificationManager[_DYN_ADD_NOTIFICATION_LIS1 /* @min:%2eaddNotificationListener */](_debugListener);
762
+ }
763
+ }));
764
+ }
765
+ function _initPerfManager() {
766
+ // Will get recalled if any referenced config values are changed
767
+ _addUnloadHook(_configHandler[_DYN_WATCH /* @min:%2ewatch */](function (details) {
768
+ var enablePerfMgr = details.cfg.enablePerfMgr;
769
+ if (!enablePerfMgr && _cfgPerfManager) {
770
+ // Remove any existing config based performance manager
771
+ _cfgPerfManager = null;
772
+ }
773
+ if (enablePerfMgr) {
774
+ // Set the performance manager creation function if not defined
775
+ getSetValue(details.cfg, STR_CREATE_PERF_MGR, _createPerfManager);
776
+ }
777
+ }));
778
+ }
779
+ function _initExtConfig() {
780
+ _configHandler.cfg[STR_EXTENSION_CONFIG /* @min:%2eextensionConfig */].NotificationManager = _notificationManager;
781
+ }
782
+ function _doUpdate(updateState) {
783
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self);
784
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
785
+ updateCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](updateState);
786
+ }
787
+ }
788
+ function _logOrThrowError(message) {
789
+ var logger = _self[_DYN_LOGGER /* @min:%2elogger */];
790
+ if (logger) {
791
+ // there should always be a logger
792
+ _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 73 /* _eInternalMessageId.PluginException */, message);
793
+ }
794
+ else {
795
+ throwError(message);
40
796
  }
41
797
  }
42
798
  function _notifyInvalidEvent(telemetryItem) {
@@ -45,17 +801,46 @@ var AppInsightsCore = /** @class */ (function (_super) {
45
801
  manager[STR_EVENTS_DISCARDED /* @min:%2eeventsDiscarded */]([telemetryItem], 2 /* eEventsDiscardedReason.InvalidEvent */);
46
802
  }
47
803
  }
804
+ function _addUnloadHook(hooks) {
805
+ if (hooks) {
806
+ arrAppend(_hooks, hooks);
807
+ }
808
+ }
48
809
  });
49
- return _this;
50
810
  }
51
811
  // Removed Stub for AppInsightsCore.prototype.initialize.
812
+ // Removed Stub for AppInsightsCore.prototype.getTransmissionControls.
52
813
  // Removed Stub for AppInsightsCore.prototype.track.
53
- // This is a workaround for an IE8 bug when using dynamicProto() with classes that don't have any
814
+ // Removed Stub for AppInsightsCore.prototype.getProcessTelContext.
815
+ // Removed Stub for AppInsightsCore.prototype.getNotifyMgr.
816
+ // Removed Stub for AppInsightsCore.prototype.addNotificationListener.
817
+ // Removed Stub for AppInsightsCore.prototype.removeNotificationListener.
818
+ // Removed Stub for AppInsightsCore.prototype.getCookieMgr.
819
+ // Removed Stub for AppInsightsCore.prototype.setCookieMgr.
820
+ // Removed Stub for AppInsightsCore.prototype.getPerfMgr.
821
+ // Removed Stub for AppInsightsCore.prototype.setPerfMgr.
822
+ // Removed Stub for AppInsightsCore.prototype.eventCnt.
823
+ // Removed Stub for AppInsightsCore.prototype.pollInternalLogs.
824
+ // Removed Stub for AppInsightsCore.prototype.stopPollingInternalLogs.
825
+ // Removed Stub for AppInsightsCore.prototype.addTelemetryInitializer.
826
+ // Removed Stub for AppInsightsCore.prototype.unload.
827
+ // Removed Stub for AppInsightsCore.prototype.getPlugin.
828
+ // Removed Stub for AppInsightsCore.prototype.addPlugin.
829
+ // Removed Stub for AppInsightsCore.prototype.updateCfg.
830
+ // Removed Stub for AppInsightsCore.prototype.evtNamespace.
831
+ // Removed Stub for AppInsightsCore.prototype.addUnloadCb.
832
+ // Removed Stub for AppInsightsCore.prototype.flush.
833
+ // Removed Stub for AppInsightsCore.prototype.getTraceCtx.
834
+ // Removed Stub for AppInsightsCore.prototype.setTraceCtx.
835
+ // Removed Stub for AppInsightsCore.prototype.addUnloadHook.
836
+ // Removed Stub for AppInsightsCore.prototype.onCfgChange.
837
+ // Removed Stub for AppInsightsCore.prototype.releaseQueue.
838
+ // Removed Stub for AppInsightsCore.prototype._updateHook.
839
+ // This is a workaround for an IE bug when using dynamicProto() with classes that don't have any
54
840
  // non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
55
- // this will be removed when ES3 support is dropped.
56
841
  AppInsightsCore.__ieDyn=1;
57
842
 
58
843
  return AppInsightsCore;
59
- }(BaseCore));
844
+ }());
60
845
  export { AppInsightsCore };
61
846
  //# sourceMappingURL=AppInsightsCore.js.map