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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +766 -1967
  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 +9840 -16439
  7. package/dist/applicationinsights-core-js.api.md +48 -425
  8. package/dist/applicationinsights-core-js.d.ts +123 -784
  9. package/dist/applicationinsights-core-js.js +766 -1967
  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 +123 -784
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +69 -3
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +99 -496
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +21 -120
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +87 -202
  21. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js +4 -4
  24. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js +148 -7
  26. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  27. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  28. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +14 -27
  29. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/EnvUtils.js +12 -13
  31. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/HelperFuncs.js +86 -89
  33. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -3
  35. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/NotificationManager.js +42 -37
  37. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  39. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +119 -430
  40. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/RandomHelper.js +4 -30
  42. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  43. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +14 -60
  44. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +76 -0
  46. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +1 -0
  47. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +96 -90
  49. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  50. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +2 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +2 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  68. package/dist-esm/applicationinsights-core-js.js +7 -12
  69. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  70. package/package.json +3 -3
  71. package/src/JavaScriptSDK/AppInsightsCore.ts +101 -2
  72. package/src/JavaScriptSDK/BaseCore.ts +120 -696
  73. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +31 -205
  74. package/src/JavaScriptSDK/ChannelController.ts +103 -242
  75. package/src/JavaScriptSDK/CookieMgr.ts +5 -7
  76. package/src/JavaScriptSDK/CoreUtils.ts +172 -8
  77. package/src/JavaScriptSDK/DiagnosticLogger.ts +14 -29
  78. package/src/JavaScriptSDK/EnvUtils.ts +12 -13
  79. package/src/JavaScriptSDK/HelperFuncs.ts +97 -123
  80. package/src/JavaScriptSDK/InstrumentHooks.ts +2 -4
  81. package/src/JavaScriptSDK/NotificationManager.ts +37 -34
  82. package/src/JavaScriptSDK/PerfManager.ts +7 -4
  83. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +134 -543
  84. package/src/JavaScriptSDK/RandomHelper.ts +3 -35
  85. package/src/JavaScriptSDK/TelemetryHelpers.ts +21 -83
  86. package/src/JavaScriptSDK/TelemetryPluginChain.ts +120 -0
  87. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +87 -184
  88. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -5
  89. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +2 -82
  90. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +5 -16
  91. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +6 -16
  92. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +14 -94
  93. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +10 -28
  94. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +11 -9
  95. package/types/JavaScriptSDK/AppInsightsCore.d.ts +21 -0
  96. package/types/JavaScriptSDK/BaseCore.d.ts +3 -81
  97. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +10 -53
  98. package/types/JavaScriptSDK/ChannelController.d.ts +17 -16
  99. package/types/JavaScriptSDK/CoreUtils.d.ts +48 -1
  100. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +0 -10
  101. package/types/JavaScriptSDK/HelperFuncs.d.ts +32 -33
  102. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  103. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +6 -69
  104. package/types/JavaScriptSDK/RandomHelper.d.ts +0 -6
  105. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -23
  106. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +32 -0
  107. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +2 -91
  108. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +0 -4
  109. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +1 -72
  110. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +5 -16
  111. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +0 -9
  112. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +11 -82
  113. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +8 -25
  114. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +10 -9
  115. package/types/applicationinsights-core-js.d.ts +9 -18
  116. package/types/tsdoc-metadata.json +1 -1
  117. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +0 -93
  118. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +0 -1
  119. package/dist-esm/JavaScriptSDK/EventHelpers.js +0 -477
  120. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +0 -1
  121. package/dist-esm/JavaScriptSDK/InternalConstants.js +0 -28
  122. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +0 -1
  123. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +0 -81
  124. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +0 -1
  125. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +0 -33
  126. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +0 -1
  127. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +0 -8
  128. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +0 -1
  129. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +0 -8
  130. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +0 -1
  131. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +0 -6
  132. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +0 -1
  133. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +0 -8
  134. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +0 -1
  135. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +0 -8
  136. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +0 -1
  137. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +0 -6
  138. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +0 -1
  139. package/src/JavaScriptSDK/DataCacheHelper.ts +0 -106
  140. package/src/JavaScriptSDK/EventHelpers.ts +0 -550
  141. package/src/JavaScriptSDK/InternalConstants.ts +0 -26
  142. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -111
  143. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -46
  144. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
  145. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
  146. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -16
  147. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
  148. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -34
  149. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
  150. package/types/JavaScriptSDK/DataCacheHelper.d.ts +0 -13
  151. package/types/JavaScriptSDK/EventHelpers.d.ts +0 -154
  152. package/types/JavaScriptSDK/InternalConstants.d.ts +0 -20
  153. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -16
  154. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +0 -11
  155. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +0 -21
  156. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +0 -20
  157. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +0 -13
  158. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +0 -6
  159. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +0 -22
  160. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +0 -13
@@ -1,466 +1,155 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.7.5-nightly.2204-03
2
+ * Application Insights JavaScript SDK - Core, 2.7.5-nightly.2204-23
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
6
6
 
7
7
  "use strict";
8
- import { safeGetLogger, _throwInternal } from "./DiagnosticLogger";
9
- import { arrForEach, isArray, isFunction, isNullOrUndefined, isObject, isUndefined, objExtend, objForEachKey, objFreeze, objKeys, proxyFunctions } from "./HelperFuncs";
10
- import { doPerf } from "./PerfManager";
11
- import { dumpObj } from "./EnvUtils";
12
- import { strCore, strDisabled, strEmpty, strIsInitialized, strTeardown, strUpdate } from "./InternalConstants";
13
- import { _getPluginState } from "./TelemetryHelpers";
14
- var strTelemetryPluginChain = "TelemetryPluginChain";
15
- var strHasRunFlags = "_hasRun";
16
- var strGetTelCtx = "_getTelCtx";
17
- var _chainId = 0;
18
- function _getNextProxyStart(proxy, config, core, startAt) {
19
- while (proxy) {
20
- if (proxy.getPlugin() === startAt) {
21
- return proxy;
22
- }
23
- proxy = proxy.getNext();
24
- }
25
- // This wasn't found in the existing chain so create an isolated one with just this plugin
26
- return createTelemetryProxyChain([startAt], config, core);
27
- }
8
+ import { safeGetLogger } from "./DiagnosticLogger";
9
+ import { TelemetryPluginChain } from "./TelemetryPluginChain";
10
+ import { arrForEach, isFunction, isNullOrUndefined, isUndefined } from "./HelperFuncs";
28
11
  /**
29
- * @ignore
30
- * @param telemetryChain
31
- * @param config
32
- * @param core
33
- * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
34
- * @returns
12
+ * Creates the instance execution chain for the plugins
35
13
  */
36
- function _createInternalContext(telemetryChain, config, core, startAt) {
37
- // We have a special case where we want to start execution from this specific plugin
38
- // or we simply reuse the existing telemetry plugin chain (normal execution case)
39
- var _nextProxy = null; // By Default set as no next plugin
40
- var _onComplete = [];
41
- if (startAt !== null) {
42
- // There is no next element (null) vs not defined (undefined) so use the full chain
43
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
44
- }
45
- var context = {
46
- _next: _moveNext,
47
- ctx: {
48
- core: function () {
49
- return core;
50
- },
51
- diagLog: function () {
52
- return safeGetLogger(core, config);
53
- },
54
- getCfg: function () {
55
- return config;
56
- },
57
- getExtCfg: _getExtCfg,
58
- getConfig: _getConfig,
59
- hasNext: function () {
60
- return !!_nextProxy;
61
- },
62
- getNext: function () {
63
- return _nextProxy;
64
- },
65
- setNext: function (nextPlugin) {
66
- _nextProxy = nextPlugin;
67
- },
68
- iterate: _iterateChain,
69
- onComplete: _addOnComplete
70
- }
71
- };
72
- function _addOnComplete(onComplete, that) {
73
- var args = [];
74
- for (var _i = 2; _i < arguments.length; _i++) {
75
- args[_i - 2] = arguments[_i];
76
- }
77
- if (onComplete) {
78
- _onComplete.push({
79
- func: onComplete,
80
- self: !isUndefined(that) ? that : context.ctx,
81
- args: args
82
- });
83
- }
84
- }
85
- function _moveNext() {
86
- var nextProxy = _nextProxy;
87
- // Automatically move to the next plugin
88
- _nextProxy = nextProxy ? nextProxy.getNext() : null;
89
- if (!nextProxy) {
90
- var onComplete = _onComplete;
91
- if (onComplete && onComplete.length > 0) {
92
- arrForEach(onComplete, function (completeDetails) {
93
- try {
94
- completeDetails.func.call(completeDetails.self, completeDetails.args);
95
- }
96
- catch (e) {
97
- _throwInternal(core.logger, 2 /* WARNING */, 73 /* PluginException */, "Unexpected Exception during onComplete - " + dumpObj(e));
98
- }
99
- });
100
- _onComplete = [];
101
- }
102
- }
103
- return nextProxy;
104
- }
105
- function _getExtCfg(identifier, defaultValue, mergeDefault) {
106
- if (defaultValue === void 0) { defaultValue = {}; }
107
- if (mergeDefault === void 0) { mergeDefault = 0 /* None */; }
108
- var theConfig;
109
- if (config) {
110
- var extConfig = config.extensionConfig;
111
- if (extConfig && identifier) {
112
- theConfig = extConfig[identifier];
113
- }
114
- }
115
- if (!theConfig) {
116
- // Just use the defaults
117
- theConfig = defaultValue;
118
- }
119
- else if (isObject(defaultValue)) {
120
- if (mergeDefault !== 0 /* None */) {
121
- // Merge the defaults and configured values
122
- var newConfig_1 = objExtend(true, defaultValue, theConfig);
123
- if (config && mergeDefault === 2 /* MergeDefaultFromRootOrDefault */) {
124
- // Enumerate over the defaultValues and if not already populate attempt to
125
- // find a value from the root config
126
- objForEachKey(defaultValue, function (field) {
127
- // for each unspecified field, set the default value
128
- if (isNullOrUndefined(newConfig_1[field])) {
129
- var cfgValue = config[field];
130
- if (!isNullOrUndefined(cfgValue)) {
131
- newConfig_1[field] = cfgValue;
132
- }
133
- }
134
- });
14
+ function _createProxyChain(plugins, itemCtx) {
15
+ var proxies = [];
16
+ if (plugins && plugins.length > 0) {
17
+ // Create the proxies and wire up the next plugin chain
18
+ var lastProxy = null;
19
+ for (var idx = 0; idx < plugins.length; idx++) {
20
+ var thePlugin = plugins[idx];
21
+ if (thePlugin && isFunction(thePlugin.processTelemetry)) {
22
+ // Only add plugins that are processors
23
+ var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
24
+ proxies.push(newProxy);
25
+ if (lastProxy) {
26
+ // Set this new proxy as the next for the previous one
27
+ lastProxy.setNext(newProxy);
135
28
  }
136
- }
137
- }
138
- return theConfig;
139
- }
140
- function _getConfig(identifier, field, defaultValue) {
141
- if (defaultValue === void 0) { defaultValue = false; }
142
- var theValue;
143
- var extConfig = _getExtCfg(identifier, null);
144
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
145
- theValue = extConfig[field];
146
- }
147
- else if (config && !isNullOrUndefined(config[field])) {
148
- theValue = config[field];
149
- }
150
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
151
- }
152
- function _iterateChain(cb) {
153
- // Keep processing until we reach the end of the chain
154
- var nextPlugin;
155
- while (!!(nextPlugin = context._next())) {
156
- var plugin = nextPlugin.getPlugin();
157
- if (plugin) {
158
- // callback with the current on
159
- cb(plugin);
29
+ lastProxy = newProxy;
160
30
  }
161
31
  }
162
32
  }
163
- return context;
33
+ return proxies.length > 0 ? proxies[0] : null;
164
34
  }
165
- /**
166
- * Creates a new Telemetry Item context with the current config, core and plugin execution chain
167
- * @param plugins - The plugin instances that will be executed
168
- * @param config - The current config
169
- * @param core - The current core instance
170
- * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
171
- */
172
- export function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
173
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
174
- var context = internalContext.ctx;
175
- function _processNext(env) {
176
- var nextPlugin = internalContext._next();
177
- // Run the next plugin which will call "processNext()"
178
- nextPlugin && nextPlugin.processTelemetry(env, context);
179
- return !nextPlugin;
180
- }
181
- function _createNew(plugins, startAt) {
182
- if (plugins === void 0) { plugins = null; }
183
- if (isArray(plugins)) {
184
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
35
+ function _copyProxyChain(proxy, itemCtx, startAt) {
36
+ var plugins = [];
37
+ var add = startAt ? false : true;
38
+ if (proxy) {
39
+ while (proxy) {
40
+ var thePlugin = proxy.getPlugin();
41
+ if (add || thePlugin === startAt) {
42
+ add = true;
43
+ plugins.push(thePlugin);
44
+ }
45
+ proxy = proxy.getNext();
185
46
  }
186
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
187
47
  }
188
- context.processNext = _processNext;
189
- context.createNew = _createNew;
190
- return context;
191
- }
192
- /**
193
- * Creates a new Telemetry Item context with the current config, core and plugin execution chain for handling the unloading of the chain
194
- * @param plugins - The plugin instances that will be executed
195
- * @param config - The current config
196
- * @param core - The current core instance
197
- * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
198
- */
199
- export function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
200
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
201
- var context = internalContext.ctx;
202
- function _processNext(unloadState) {
203
- var nextPlugin = internalContext._next();
204
- nextPlugin && nextPlugin.unload(context, unloadState);
205
- return !nextPlugin;
206
- }
207
- function _createNew(plugins, startAt) {
208
- if (plugins === void 0) { plugins = null; }
209
- if (isArray(plugins)) {
210
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
211
- }
212
- return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
48
+ if (!add) {
49
+ plugins.push(startAt);
213
50
  }
214
- context.processNext = _processNext;
215
- context.createNew = _createNew;
216
- return context;
51
+ return _createProxyChain(plugins, itemCtx);
217
52
  }
218
- /**
219
- * Creates a new Telemetry Item context with the current config, core and plugin execution chain for updating the configuration
220
- * @param plugins - The plugin instances that will be executed
221
- * @param config - The current config
222
- * @param core - The current core instance
223
- * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
224
- */
225
- export function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
226
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
227
- var context = internalContext.ctx;
228
- function _processNext(updateState) {
229
- return context.iterate(function (plugin) {
230
- if (isFunction(plugin[strUpdate])) {
231
- plugin[strUpdate](context, updateState);
53
+ function _copyPluginChain(srcPlugins, itemCtx, startAt) {
54
+ var plugins = srcPlugins;
55
+ var add = false;
56
+ if (startAt && srcPlugins) {
57
+ plugins = [];
58
+ arrForEach(srcPlugins, function (thePlugin) {
59
+ if (add || thePlugin === startAt) {
60
+ add = true;
61
+ plugins.push(thePlugin);
232
62
  }
233
63
  });
234
64
  }
235
- function _createNew(plugins, startAt) {
236
- if (plugins === void 0) { plugins = null; }
237
- if (isArray(plugins)) {
238
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
65
+ if (startAt && !add) {
66
+ if (!plugins) {
67
+ plugins = [];
239
68
  }
240
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
69
+ plugins.push(startAt);
241
70
  }
242
- context.processNext = _processNext;
243
- context.createNew = _createNew;
244
- return context;
71
+ return _createProxyChain(plugins, itemCtx);
245
72
  }
246
- /**
247
- * Creates an execution chain from the array of plugins
248
- * @param plugins - The array of plugins that will be executed in this order
249
- * @param defItemCtx - The default execution context to use when no telemetry context is passed to processTelemetry(), this
250
- * should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
251
- * reporting (hasRun) when errors occur.
252
- */
253
- export function createTelemetryProxyChain(plugins, config, core, startAt) {
254
- var firstProxy = null;
255
- var add = startAt ? false : true;
256
- if (isArray(plugins) && plugins.length > 0) {
257
- // Create the proxies and wire up the next plugin chain
258
- var lastProxy_1 = null;
259
- arrForEach(plugins, function (thePlugin) {
260
- if (!add && startAt === thePlugin) {
261
- add = true;
73
+ var ProcessTelemetryContext = /** @class */ (function () {
74
+ /**
75
+ * Creates a new Telemetry Item context with the current config, core and plugin execution chain
76
+ * @param plugins - The plugin instances that will be executed
77
+ * @param config - The current config
78
+ * @param core - The current core instance
79
+ */
80
+ function ProcessTelemetryContext(plugins, config, core, startAt) {
81
+ var _self = this;
82
+ var _nextProxy = null; // Null == No next plugin
83
+ // There is no next element (null) vs not defined (undefined)
84
+ if (startAt !== null) {
85
+ if (plugins && isFunction(plugins.getPlugin)) {
86
+ // We have a proxy chain object
87
+ _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
262
88
  }
263
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
264
- // Only add plugins that are processors
265
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
266
- if (!firstProxy) {
267
- firstProxy = newProxy;
89
+ else {
90
+ // We just have an array
91
+ if (startAt) {
92
+ _nextProxy = _copyPluginChain(plugins, _self, startAt);
268
93
  }
269
- if (lastProxy_1) {
270
- // Set this new proxy as the next for the previous one
271
- lastProxy_1._setNext(newProxy);
94
+ else if (isUndefined(startAt)) {
95
+ // Undefined means copy the existing chain
96
+ _nextProxy = _createProxyChain(plugins, _self);
272
97
  }
273
- lastProxy_1 = newProxy;
274
98
  }
275
- });
276
- }
277
- if (startAt && !firstProxy) {
278
- // Special case where the "startAt" was not in the original list of plugins
279
- return createTelemetryProxyChain([startAt], config, core);
280
- }
281
- return firstProxy;
282
- }
283
- /**
284
- * Create the processing telemetry proxy instance, the proxy is used to abstract the current plugin to allow monitoring and
285
- * execution plugins while passing around the dynamic execution state (IProcessTelemetryContext), the proxy instance no longer
286
- * contains any execution state and can be reused between requests (this was not the case for 2.7.2 and earlier with the
287
- * TelemetryPluginChain class).
288
- * @param plugin - The plugin instance to proxy
289
- * @param config - The default execution context to use when no telemetry context is passed to processTelemetry(), this
290
- * should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
291
- * reporting (hasRun) when errors occur.
292
- * @returns
293
- */
294
- export function createTelemetryPluginProxy(plugin, config, core) {
295
- var nextProxy = null;
296
- var hasProcessTelemetry = isFunction(plugin.processTelemetry);
297
- var hasSetNext = isFunction(plugin.setNextPlugin);
298
- var chainId;
299
- if (plugin) {
300
- chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
301
- }
302
- else {
303
- chainId = "Unknown-0-" + _chainId++;
304
- }
305
- var proxyChain = {
306
- getPlugin: function () {
307
- return plugin;
308
- },
309
- getNext: function () {
310
- return nextProxy;
311
- },
312
- processTelemetry: _processTelemetry,
313
- unload: _unloadPlugin,
314
- update: _updatePlugin,
315
- _id: chainId,
316
- _setNext: function (nextPlugin) {
317
- nextProxy = nextPlugin;
318
99
  }
319
- };
320
- function _getTelCtx() {
321
- var itemCtx;
322
- // Looks like a plugin didn't pass the (optional) context, so create a new one
323
- if (plugin && isFunction(plugin[strGetTelCtx])) {
324
- // This plugin extends from the BaseTelemetryPlugin so lets use it
325
- itemCtx = plugin[strGetTelCtx]();
326
- }
327
- if (!itemCtx) {
328
- // Create a temporary one
329
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
330
- }
331
- return itemCtx;
332
- }
333
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
334
- var hasRun = false;
335
- var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
336
- var hasRunContext = itemCtx[strHasRunFlags];
337
- if (!hasRunContext) {
338
- // Assign and populate
339
- hasRunContext = itemCtx[strHasRunFlags] = {};
340
- }
341
- // Ensure that we keep the context in sync
342
- itemCtx.setNext(nextProxy);
343
- if (plugin) {
344
- doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
345
- // Mark this component as having run
346
- hasRunContext[chainId] = true;
347
- try {
348
- // Set a flag on the next plugin so we know if it was attempted to be executed
349
- var nextId = nextProxy ? nextProxy._id : strEmpty;
350
- if (nextId) {
351
- hasRunContext[nextId] = false;
352
- }
353
- hasRun = processPluginFn(itemCtx);
354
- }
355
- catch (error) {
356
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
357
- if (hasNextRun) {
358
- // The next plugin after us has already run so set this one as complete
359
- hasRun = true;
360
- }
361
- if (!nextProxy || !hasNextRun) {
362
- // Either we have no next plugin or the current one did not attempt to call the next plugin
363
- // Which means the current one is the root of the failure so log/report this failure
364
- _throwInternal(itemCtx.diagLog(), 1 /* CRITICAL */, 73 /* PluginException */, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
365
- }
100
+ _self.core = function () {
101
+ return core;
102
+ };
103
+ _self.diagLog = function () {
104
+ return safeGetLogger(core, config);
105
+ };
106
+ _self.getCfg = function () {
107
+ return config;
108
+ };
109
+ _self.getExtCfg = function (identifier, defaultValue) {
110
+ if (defaultValue === void 0) { defaultValue = {}; }
111
+ var theConfig;
112
+ if (config) {
113
+ var extConfig = config.extensionConfig;
114
+ if (extConfig && identifier) {
115
+ theConfig = extConfig[identifier];
366
116
  }
367
- }, details, isAsync);
368
- }
369
- return hasRun;
370
- }
371
- function _processTelemetry(env, itemCtx) {
372
- itemCtx = itemCtx || _getTelCtx();
373
- function _callProcessTelemetry(itemCtx) {
374
- if (!plugin || !hasProcessTelemetry) {
375
- return false;
376
117
  }
377
- var pluginState = _getPluginState(plugin);
378
- if (pluginState[strTeardown] || pluginState[strDisabled]) {
379
- return false;
118
+ return (theConfig ? theConfig : defaultValue);
119
+ };
120
+ _self.getConfig = function (identifier, field, defaultValue) {
121
+ if (defaultValue === void 0) { defaultValue = false; }
122
+ var theValue;
123
+ var extConfig = _self.getExtCfg(identifier, null);
124
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
125
+ theValue = extConfig[field];
380
126
  }
381
- // Ensure that we keep the context in sync (for processNext()), just in case a plugin
382
- // doesn't calls processTelemetry() instead of itemContext.processNext() or some
383
- // other form of error occurred
384
- if (hasSetNext) {
385
- // Backward compatibility setting the next plugin on the instance
386
- plugin.setNextPlugin(nextProxy);
127
+ else if (config && !isNullOrUndefined(config[field])) {
128
+ theValue = config[field];
387
129
  }
388
- plugin.processTelemetry(env, itemCtx);
389
- // Process Telemetry is expected to call itemCtx.processNext() or nextPlugin.processTelemetry()
390
- return true;
391
- }
392
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
393
- // The underlying plugin is either not defined, not enabled or does not have a processTelemetry implementation
394
- // so we still want the next plugin to be executed.
395
- itemCtx.processNext(env);
396
- }
397
- }
398
- function _unloadPlugin(unloadCtx, unloadState) {
399
- function _callTeardown() {
400
- // Setting default of hasRun as false so the proxyProcessFn() is called as teardown() doesn't have to exist or call unloadNext().
401
- var hasRun = false;
402
- if (plugin) {
403
- var pluginState = _getPluginState(plugin);
404
- var pluginCore = plugin[strCore] || pluginState.core;
405
- // Only teardown the plugin if it was initialized by the current core (i.e. It's not a shared plugin)
406
- if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
407
- // Handle plugins that don't extend from the BaseTelemetryPlugin
408
- pluginState[strCore] = null;
409
- pluginState[strTeardown] = true;
410
- pluginState[strIsInitialized] = false;
411
- if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
412
- // plugin told us that it was going to (or has) call unloadCtx.processNext()
413
- hasRun = true;
414
- }
415
- }
130
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
131
+ };
132
+ _self.hasNext = function () {
133
+ return _nextProxy != null;
134
+ };
135
+ _self.getNext = function () {
136
+ return _nextProxy;
137
+ };
138
+ _self.setNext = function (nextPlugin) {
139
+ _nextProxy = nextPlugin;
140
+ };
141
+ _self.processNext = function (env) {
142
+ var nextPlugin = _nextProxy;
143
+ if (nextPlugin) {
144
+ // Automatically move to the next plugin
145
+ _nextProxy = nextPlugin.getNext();
146
+ nextPlugin.processTelemetry(env, _self);
416
147
  }
417
- return hasRun;
418
- }
419
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
420
- // Only called if we hasRun was not true
421
- unloadCtx.processNext(unloadState);
422
- }
423
- }
424
- function _updatePlugin(updateCtx, updateState) {
425
- function _callUpdate() {
426
- // Setting default of hasRun as false so the proxyProcessFn() is called as teardown() doesn't have to exist or call unloadNext().
427
- var hasRun = false;
428
- if (plugin) {
429
- var pluginState = _getPluginState(plugin);
430
- var pluginCore = plugin[strCore] || pluginState.core;
431
- // Only update the plugin if it was initialized by the current core (i.e. It's not a shared plugin)
432
- if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
433
- if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
434
- // plugin told us that it was going to (or has) call unloadCtx.processNext()
435
- hasRun = true;
436
- }
437
- }
438
- }
439
- return hasRun;
440
- }
441
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
442
- // Only called if we hasRun was not true
443
- updateCtx.processNext(updateState);
444
- }
445
- }
446
- return objFreeze(proxyChain);
447
- }
448
- /**
449
- * This class will be removed!
450
- * @deprecated use createProcessTelemetryContext() instead
451
- */
452
- var ProcessTelemetryContext = /** @class */ (function () {
453
- /**
454
- * Creates a new Telemetry Item context with the current config, core and plugin execution chain
455
- * @param plugins - The plugin instances that will be executed
456
- * @param config - The current config
457
- * @param core - The current core instance
458
- */
459
- function ProcessTelemetryContext(pluginChain, config, core, startAt) {
460
- var _self = this;
461
- var context = createProcessTelemetryContext(pluginChain, config, core, startAt);
462
- // Proxy all functions of the context to this object
463
- proxyFunctions(_self, context, objKeys(context));
148
+ };
149
+ _self.createNew = function (plugins, startAt) {
150
+ if (plugins === void 0) { plugins = null; }
151
+ return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
152
+ };
464
153
  }
465
154
  return ProcessTelemetryContext;
466
155
  }());