@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.
- package/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +860 -457
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +1193 -267
- package/dist/applicationinsights-core-js.api.md +54 -14
- package/dist/applicationinsights-core-js.d.ts +133 -45
- package/dist/applicationinsights-core-js.js +860 -457
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +133 -45
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +237 -82
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +45 -19
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +155 -87
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +2 -27
- package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +6 -6
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +51 -11
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +34 -36
- package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +289 -119
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +29 -4
- package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +2 -2
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +82 -0
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
- package/dist-esm/applicationinsights-core-js.js +4 -4
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +2 -2
- package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
- package/src/JavaScriptSDK/BaseCore.ts +330 -100
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +69 -32
- package/src/JavaScriptSDK/ChannelController.ts +175 -103
- package/src/JavaScriptSDK/CoreUtils.ts +1 -28
- package/src/JavaScriptSDK/EnvUtils.ts +5 -5
- package/src/JavaScriptSDK/HelperFuncs.ts +57 -14
- package/src/JavaScriptSDK/InstrumentHooks.ts +3 -1
- package/src/JavaScriptSDK/NotificationManager.ts +32 -31
- package/src/JavaScriptSDK/PerfManager.ts +1 -1
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +350 -133
- package/src/JavaScriptSDK/RandomHelper.ts +34 -3
- package/src/JavaScriptSDK/TelemetryHelpers.ts +4 -6
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +119 -0
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +17 -1
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +7 -3
- package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +5 -0
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +23 -5
- package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +1 -1
- package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
- package/types/JavaScriptSDK/BaseCore.d.ts +30 -1
- package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +13 -11
- package/types/JavaScriptSDK/ChannelController.d.ts +12 -17
- package/types/JavaScriptSDK/CoreUtils.d.ts +0 -6
- package/types/JavaScriptSDK/HelperFuncs.d.ts +14 -5
- package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +49 -3
- package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
- package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -3
- package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +23 -0
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +15 -0
- package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +7 -3
- package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +4 -0
- package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +18 -3
- package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
- package/types/applicationinsights-core-js.d.ts +5 -4
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
- package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
- package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
|
@@ -1,75 +1,313 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 2.
|
|
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
8
|
import { safeGetLogger } from "./DiagnosticLogger";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { arrForEach, isArray, isFunction, isNullOrUndefined, isObject, objExtend, objForEachKey, objFreeze, objKeys, proxyFunctions } from "./HelperFuncs";
|
|
10
|
+
import { doPerf } from "./PerfManager";
|
|
11
|
+
import { LoggingSeverity, _InternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
12
|
+
import { dumpObj } from "./EnvUtils";
|
|
13
|
+
var strTelemetryPluginChain = "TelemetryPluginChain";
|
|
14
|
+
var strHasRunFlags = "_hasRun";
|
|
15
|
+
var strGetTelCtx = "_getTelCtx";
|
|
16
|
+
var _chainId = 0;
|
|
17
|
+
function _getNextProxyStart(proxy, config, core, startAt) {
|
|
18
|
+
while (proxy) {
|
|
19
|
+
if (proxy.getPlugin() === startAt) {
|
|
20
|
+
return proxy;
|
|
21
|
+
}
|
|
22
|
+
proxy = proxy.getNext();
|
|
23
|
+
}
|
|
24
|
+
// This wasn't found in the existing chain so create an isolated one with just this plugin
|
|
25
|
+
return createTelemetryProxyChain([startAt], config, core);
|
|
26
|
+
}
|
|
11
27
|
/**
|
|
12
|
-
* Creates
|
|
28
|
+
* Creates a new Telemetry Item context with the current config, core and plugin execution chain
|
|
29
|
+
* @param plugins - The plugin instances that will be executed
|
|
30
|
+
* @param config - The current config
|
|
31
|
+
* @param core - The current core instance
|
|
13
32
|
*/
|
|
14
|
-
function
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
export function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
|
|
34
|
+
var _nextProxy = null; // Null == No next plugin
|
|
35
|
+
var _onComplete = null;
|
|
36
|
+
// There is no next element (null === last element) vs not defined (undefined)
|
|
37
|
+
// We have a proxy chain object
|
|
38
|
+
if (startAt) {
|
|
39
|
+
// We have a special case where we want to start execution from this specific plugin
|
|
40
|
+
_nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Reuse the existing telemetry plugin chain (normal execution case)
|
|
44
|
+
_nextProxy = telemetryChain;
|
|
45
|
+
}
|
|
46
|
+
var context = {
|
|
47
|
+
core: function () {
|
|
48
|
+
return core;
|
|
49
|
+
},
|
|
50
|
+
diagLog: function () {
|
|
51
|
+
return safeGetLogger(core, config);
|
|
52
|
+
},
|
|
53
|
+
getCfg: function () {
|
|
54
|
+
return config;
|
|
55
|
+
},
|
|
56
|
+
getExtCfg: _getExtCfg,
|
|
57
|
+
getConfig: _getConfig,
|
|
58
|
+
hasNext: function () {
|
|
59
|
+
return _nextProxy != null;
|
|
60
|
+
},
|
|
61
|
+
getNext: function () {
|
|
62
|
+
return _nextProxy;
|
|
63
|
+
},
|
|
64
|
+
setNext: function (nextPlugin) {
|
|
65
|
+
_nextProxy = nextPlugin;
|
|
66
|
+
},
|
|
67
|
+
processNext: function (env) {
|
|
68
|
+
_processChain(function (nextPlugin) {
|
|
69
|
+
// Run the next plugin which will call "processNext()"
|
|
70
|
+
nextPlugin.processTelemetry(env, context);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
iterate: _iterateChain,
|
|
74
|
+
createNew: function (plugins, startAt) {
|
|
75
|
+
if (plugins === void 0) { plugins = null; }
|
|
76
|
+
if (isArray(plugins)) {
|
|
77
|
+
plugins = createTelemetryProxyChain(plugins, config, core, startAt);
|
|
78
|
+
}
|
|
79
|
+
return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
|
|
80
|
+
},
|
|
81
|
+
onComplete: function (onComplete) {
|
|
82
|
+
_onComplete = onComplete;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function _getExtCfg(identifier, defaultValue, mergeDefault) {
|
|
86
|
+
if (defaultValue === void 0) { defaultValue = {}; }
|
|
87
|
+
if (mergeDefault === void 0) { mergeDefault = 0 /* None */; }
|
|
88
|
+
var theConfig;
|
|
89
|
+
if (config) {
|
|
90
|
+
var extConfig = config.extensionConfig;
|
|
91
|
+
if (extConfig && identifier) {
|
|
92
|
+
theConfig = extConfig[identifier];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!theConfig) {
|
|
96
|
+
// Just use the defaults
|
|
97
|
+
theConfig = defaultValue;
|
|
98
|
+
}
|
|
99
|
+
else if (isObject(defaultValue)) {
|
|
100
|
+
if (mergeDefault !== 0 /* None */) {
|
|
101
|
+
// Merge the defaults and configured values
|
|
102
|
+
var newConfig_1 = objExtend(true, defaultValue, theConfig);
|
|
103
|
+
if (config && mergeDefault === 2 /* MergeDefaultFromRootOrDefault */) {
|
|
104
|
+
// Enumerate over the defaultValues and if not already populate attempt to
|
|
105
|
+
// find a value from the root config
|
|
106
|
+
objForEachKey(defaultValue, function (field) {
|
|
107
|
+
// for each unspecified field, set the default value
|
|
108
|
+
if (isNullOrUndefined(newConfig_1[field])) {
|
|
109
|
+
var cfgValue = config[field];
|
|
110
|
+
if (!isNullOrUndefined(cfgValue)) {
|
|
111
|
+
newConfig_1[field] = cfgValue;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
28
115
|
}
|
|
29
|
-
lastProxy = newProxy;
|
|
30
116
|
}
|
|
31
117
|
}
|
|
118
|
+
return theConfig;
|
|
32
119
|
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
120
|
+
function _getConfig(identifier, field, defaultValue) {
|
|
121
|
+
if (defaultValue === void 0) { defaultValue = false; }
|
|
122
|
+
var theValue;
|
|
123
|
+
var extConfig = _getExtCfg(identifier, null);
|
|
124
|
+
if (extConfig && !isNullOrUndefined(extConfig[field])) {
|
|
125
|
+
theValue = extConfig[field];
|
|
126
|
+
}
|
|
127
|
+
else if (config && !isNullOrUndefined(config[field])) {
|
|
128
|
+
theValue = config[field];
|
|
129
|
+
}
|
|
130
|
+
return !isNullOrUndefined(theValue) ? theValue : defaultValue;
|
|
131
|
+
}
|
|
132
|
+
function _processChain(cb) {
|
|
133
|
+
var nextPlugin = _nextProxy;
|
|
134
|
+
if (nextPlugin) {
|
|
135
|
+
// Automatically move to the next plugin
|
|
136
|
+
_nextProxy = nextPlugin.getNext();
|
|
137
|
+
cb(nextPlugin);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (_onComplete) {
|
|
141
|
+
_onComplete();
|
|
142
|
+
_onComplete = null;
|
|
44
143
|
}
|
|
45
|
-
proxy = proxy.getNext();
|
|
46
144
|
}
|
|
47
145
|
}
|
|
48
|
-
|
|
49
|
-
|
|
146
|
+
function _iterateChain(cb) {
|
|
147
|
+
while (_nextProxy) {
|
|
148
|
+
_processChain(function (nextPlugin) {
|
|
149
|
+
var plugin = nextPlugin.getPlugin();
|
|
150
|
+
if (plugin) {
|
|
151
|
+
// callback with the current on
|
|
152
|
+
cb(plugin);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
50
156
|
}
|
|
51
|
-
return
|
|
157
|
+
return context;
|
|
52
158
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Creates an execution chain from the array of plugins
|
|
161
|
+
* @param plugins - The array of plugins that will be executed in this order
|
|
162
|
+
* @param defItemCtx - The default execution context to use when no telemetry context is passed to processTelemetry(), this
|
|
163
|
+
* should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
|
|
164
|
+
* reporting (hasRun) when errors occur.
|
|
165
|
+
*/
|
|
166
|
+
export function createTelemetryProxyChain(plugins, config, core, startAt) {
|
|
167
|
+
var firstProxy = null;
|
|
168
|
+
var add = startAt ? false : true;
|
|
169
|
+
if (isArray(plugins) && plugins.length > 0) {
|
|
170
|
+
// Create the proxies and wire up the next plugin chain
|
|
171
|
+
var lastProxy_1 = null;
|
|
172
|
+
arrForEach(plugins, function (thePlugin) {
|
|
173
|
+
if (!add && startAt === thePlugin) {
|
|
60
174
|
add = true;
|
|
61
|
-
|
|
175
|
+
}
|
|
176
|
+
if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
|
|
177
|
+
// Only add plugins that are processors
|
|
178
|
+
var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
|
|
179
|
+
if (!firstProxy) {
|
|
180
|
+
firstProxy = newProxy;
|
|
181
|
+
}
|
|
182
|
+
if (lastProxy_1) {
|
|
183
|
+
// Set this new proxy as the next for the previous one
|
|
184
|
+
lastProxy_1._setNext(newProxy);
|
|
185
|
+
}
|
|
186
|
+
lastProxy_1 = newProxy;
|
|
62
187
|
}
|
|
63
188
|
});
|
|
64
189
|
}
|
|
65
|
-
if (startAt && !
|
|
66
|
-
|
|
67
|
-
|
|
190
|
+
if (startAt && !firstProxy) {
|
|
191
|
+
// Special case where the "startAt" was not in the original list of plugins
|
|
192
|
+
return createTelemetryProxyChain([startAt], config, core);
|
|
193
|
+
}
|
|
194
|
+
return firstProxy;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Create the processing telemetry proxy instance, the proxy is used to abstract the current plugin to allow monitoring and
|
|
198
|
+
* execution plugins while passing around the dynamic execution state (IProcessTelemetryContext), the proxy instance no longer
|
|
199
|
+
* contains any execution state and can be reused between requests (this was not the case for 2.7.2 and earlier with the
|
|
200
|
+
* TelemetryPluginChain class).
|
|
201
|
+
* @param plugin - The plugin instance to proxy
|
|
202
|
+
* @param config - The default execution context to use when no telemetry context is passed to processTelemetry(), this
|
|
203
|
+
* should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
|
|
204
|
+
* reporting (hasRun) when errors occur.
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
export function createTelemetryPluginProxy(plugin, config, core) {
|
|
208
|
+
var nextProxy = null;
|
|
209
|
+
var hasProcessTelemetry = isFunction(plugin.processTelemetry);
|
|
210
|
+
var hasSetNext = isFunction(plugin.setNextPlugin);
|
|
211
|
+
var chainId;
|
|
212
|
+
if (plugin) {
|
|
213
|
+
chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
chainId = "Unknown-0-" + _chainId++;
|
|
217
|
+
}
|
|
218
|
+
var proxyChain = {
|
|
219
|
+
getPlugin: function () {
|
|
220
|
+
return plugin;
|
|
221
|
+
},
|
|
222
|
+
getNext: function () {
|
|
223
|
+
return nextProxy;
|
|
224
|
+
},
|
|
225
|
+
processTelemetry: _processTelemetry,
|
|
226
|
+
_id: chainId,
|
|
227
|
+
_setNext: function (nextPlugin) {
|
|
228
|
+
nextProxy = nextPlugin;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
|
|
232
|
+
// Make sure we have a context
|
|
233
|
+
if (!itemCtx) {
|
|
234
|
+
// Looks like a plugin didn't pass the (optional) context, so create a new one
|
|
235
|
+
if (plugin && isFunction(plugin[strGetTelCtx])) {
|
|
236
|
+
// This plugin extends from the BaseTelemetryPlugin so lets use it
|
|
237
|
+
itemCtx = plugin[strGetTelCtx]();
|
|
238
|
+
}
|
|
239
|
+
if (!itemCtx) {
|
|
240
|
+
// Create a temporary one
|
|
241
|
+
itemCtx = createProcessTelemetryContext(proxyChain, config, core);
|
|
242
|
+
}
|
|
68
243
|
}
|
|
69
|
-
|
|
244
|
+
var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
|
|
245
|
+
var hasRunContext = itemCtx[strHasRunFlags];
|
|
246
|
+
if (!hasRunContext) {
|
|
247
|
+
// Assign and populate
|
|
248
|
+
hasRunContext = itemCtx[strHasRunFlags] = {};
|
|
249
|
+
}
|
|
250
|
+
doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
|
|
251
|
+
// Mark this component as having run
|
|
252
|
+
hasRunContext[chainId] = true;
|
|
253
|
+
var hasRun = false;
|
|
254
|
+
// Ensure that we keep the context in sync
|
|
255
|
+
itemCtx.setNext(nextProxy);
|
|
256
|
+
if (plugin) {
|
|
257
|
+
try {
|
|
258
|
+
// Set a flag on the next plugin so we know if it was attempted to be executed
|
|
259
|
+
var nextId = nextProxy ? nextProxy._id : "";
|
|
260
|
+
if (nextId) {
|
|
261
|
+
hasRunContext[nextId] = false;
|
|
262
|
+
}
|
|
263
|
+
hasRun = processPluginFn(itemCtx);
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
|
|
267
|
+
if (hasNextRun) {
|
|
268
|
+
// The next plugin after us has already run so set this one as complete
|
|
269
|
+
hasRun = true;
|
|
270
|
+
}
|
|
271
|
+
if (!nextProxy || !hasNextRun) {
|
|
272
|
+
// Either we have no next plugin or the current one did not attempt to call the next plugin
|
|
273
|
+
// Which means the current one is the root of the failure so log/report this failure
|
|
274
|
+
itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (nextProxy && !hasRun) {
|
|
279
|
+
// The underlying plugin is not defined, but we still want the next plugin to be executed.
|
|
280
|
+
// So rather than leave the pipeline dead in the water we call the next plugin
|
|
281
|
+
processProxyFn(itemCtx);
|
|
282
|
+
}
|
|
283
|
+
}, details, isAsync);
|
|
70
284
|
}
|
|
71
|
-
|
|
285
|
+
function _processTelemetry(env, itemCtx) {
|
|
286
|
+
_processChain(itemCtx, function (itemCtx) {
|
|
287
|
+
if (!hasProcessTelemetry) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
// Ensure that we keep the context in sync (for processNext()), just in case a plugin
|
|
291
|
+
// doesn't calls processTelemetry() instead of itemContext.processNext() or some
|
|
292
|
+
// other form of error occurred
|
|
293
|
+
if (hasSetNext) {
|
|
294
|
+
// Backward compatibility setting the next plugin on the instance
|
|
295
|
+
plugin.setNextPlugin(nextProxy);
|
|
296
|
+
}
|
|
297
|
+
plugin.processTelemetry(env, itemCtx);
|
|
298
|
+
return true;
|
|
299
|
+
}, function (itemCtx) {
|
|
300
|
+
// The underlying plugin is either not defined or does not have a processTelemetry implementation
|
|
301
|
+
// so we still want the next plugin to be executed.
|
|
302
|
+
nextProxy.processTelemetry(env, itemCtx);
|
|
303
|
+
}, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
|
|
304
|
+
}
|
|
305
|
+
return objFreeze(proxyChain);
|
|
72
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* This class will be removed!
|
|
309
|
+
* @deprecated use createProcessTelemetryContext() instead
|
|
310
|
+
*/
|
|
73
311
|
var ProcessTelemetryContext = /** @class */ (function () {
|
|
74
312
|
/**
|
|
75
313
|
* Creates a new Telemetry Item context with the current config, core and plugin execution chain
|
|
@@ -77,79 +315,11 @@ var ProcessTelemetryContext = /** @class */ (function () {
|
|
|
77
315
|
* @param config - The current config
|
|
78
316
|
* @param core - The current core instance
|
|
79
317
|
*/
|
|
80
|
-
function ProcessTelemetryContext(
|
|
318
|
+
function ProcessTelemetryContext(pluginChain, config, core, startAt) {
|
|
81
319
|
var _self = this;
|
|
82
|
-
var
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
if (plugins && isFunction(plugins.getPlugin)) {
|
|
86
|
-
// We have a proxy chain object
|
|
87
|
-
_nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
// We just have an array
|
|
91
|
-
if (startAt) {
|
|
92
|
-
_nextProxy = _copyPluginChain(plugins, _self, startAt);
|
|
93
|
-
}
|
|
94
|
-
else if (isUndefined(startAt)) {
|
|
95
|
-
// Undefined means copy the existing chain
|
|
96
|
-
_nextProxy = _createProxyChain(plugins, _self);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
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];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
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];
|
|
126
|
-
}
|
|
127
|
-
else if (config && !isNullOrUndefined(config[field])) {
|
|
128
|
-
theValue = config[field];
|
|
129
|
-
}
|
|
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);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
_self.createNew = function (plugins, startAt) {
|
|
150
|
-
if (plugins === void 0) { plugins = null; }
|
|
151
|
-
return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
|
|
152
|
-
};
|
|
320
|
+
var context = createProcessTelemetryContext(pluginChain, config, core, startAt);
|
|
321
|
+
// Proxy all functions of the context to this object
|
|
322
|
+
proxyFunctions(_self, context, objKeys(context));
|
|
153
323
|
}
|
|
154
324
|
return ProcessTelemetryContext;
|
|
155
325
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessTelemetryContext.js.map","sources":["ProcessTelemetryContext.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { safeGetLogger } from \"./DiagnosticLogger\";\r\nimport { TelemetryPluginChain } from \"./TelemetryPluginChain\";\r\nimport { arrForEach, isFunction, isNullOrUndefined, isUndefined } from \"./HelperFuncs\";\r\n/**\r\n * Creates the instance execution chain for the plugins\r\n */\r\nfunction _createProxyChain(plugins, itemCtx) {\r\n var proxies = [];\r\n if (plugins && plugins.length > 0) {\r\n // Create the proxies and wire up the next plugin chain\r\n var lastProxy = null;\r\n for (var idx = 0; idx < plugins.length; idx++) {\r\n var thePlugin = plugins[idx];\r\n if (thePlugin && isFunction(thePlugin.processTelemetry)) {\r\n // Only add plugins that are processors\r\n var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);\r\n proxies.push(newProxy);\r\n if (lastProxy) {\r\n // Set this new proxy as the next for the previous one\r\n lastProxy.setNext(newProxy);\r\n }\r\n lastProxy = newProxy;\r\n }\r\n }\r\n }\r\n return proxies.length > 0 ? proxies[0] : null;\r\n}\r\nfunction _copyProxyChain(proxy, itemCtx, startAt) {\r\n var plugins = [];\r\n var add = startAt ? false : true;\r\n if (proxy) {\r\n while (proxy) {\r\n var thePlugin = proxy.getPlugin();\r\n if (add || thePlugin === startAt) {\r\n add = true;\r\n plugins.push(thePlugin);\r\n }\r\n proxy = proxy.getNext();\r\n }\r\n }\r\n if (!add) {\r\n plugins.push(startAt);\r\n }\r\n return _createProxyChain(plugins, itemCtx);\r\n}\r\nfunction _copyPluginChain(srcPlugins, itemCtx, startAt) {\r\n var plugins = srcPlugins;\r\n var add = false;\r\n if (startAt && srcPlugins) {\r\n plugins = [];\r\n arrForEach(srcPlugins, function (thePlugin) {\r\n if (add || thePlugin === startAt) {\r\n add = true;\r\n plugins.push(thePlugin);\r\n }\r\n });\r\n }\r\n if (startAt && !add) {\r\n if (!plugins) {\r\n plugins = [];\r\n }\r\n plugins.push(startAt);\r\n }\r\n return _createProxyChain(plugins, itemCtx);\r\n}\r\nvar ProcessTelemetryContext = /** @class */ (function () {\r\n /**\r\n * Creates a new Telemetry Item context with the current config, core and plugin execution chain\r\n * @param plugins - The plugin instances that will be executed\r\n * @param config - The current config\r\n * @param core - The current core instance\r\n */\r\n function ProcessTelemetryContext(plugins, config, core, startAt) {\r\n var _self = this;\r\n var _nextProxy = null; // Null == No next plugin\r\n // There is no next element (null) vs not defined (undefined)\r\n if (startAt !== null) {\r\n if (plugins && isFunction(plugins.getPlugin)) {\r\n // We have a proxy chain object\r\n _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());\r\n }\r\n else {\r\n // We just have an array\r\n if (startAt) {\r\n _nextProxy = _copyPluginChain(plugins, _self, startAt);\r\n }\r\n else if (isUndefined(startAt)) {\r\n // Undefined means copy the existing chain\r\n _nextProxy = _createProxyChain(plugins, _self);\r\n }\r\n }\r\n }\r\n _self.core = function () {\r\n return core;\r\n };\r\n _self.diagLog = function () {\r\n return safeGetLogger(core, config);\r\n };\r\n _self.getCfg = function () {\r\n return config;\r\n };\r\n _self.getExtCfg = function (identifier, defaultValue) {\r\n if (defaultValue === void 0) { defaultValue = {}; }\r\n var theConfig;\r\n if (config) {\r\n var extConfig = config.extensionConfig;\r\n if (extConfig && identifier) {\r\n theConfig = extConfig[identifier];\r\n }\r\n }\r\n return (theConfig ? theConfig : defaultValue);\r\n };\r\n _self.getConfig = function (identifier, field, defaultValue) {\r\n if (defaultValue === void 0) { defaultValue = false; }\r\n var theValue;\r\n var extConfig = _self.getExtCfg(identifier, null);\r\n if (extConfig && !isNullOrUndefined(extConfig[field])) {\r\n theValue = extConfig[field];\r\n }\r\n else if (config && !isNullOrUndefined(config[field])) {\r\n theValue = config[field];\r\n }\r\n return !isNullOrUndefined(theValue) ? theValue : defaultValue;\r\n };\r\n _self.hasNext = function () {\r\n return _nextProxy != null;\r\n };\r\n _self.getNext = function () {\r\n return _nextProxy;\r\n };\r\n _self.setNext = function (nextPlugin) {\r\n _nextProxy = nextPlugin;\r\n };\r\n _self.processNext = function (env) {\r\n var nextPlugin = _nextProxy;\r\n if (nextPlugin) {\r\n // Automatically move to the next plugin\r\n _nextProxy = nextPlugin.getNext();\r\n nextPlugin.processTelemetry(env, _self);\r\n }\r\n };\r\n _self.createNew = function (plugins, startAt) {\r\n if (plugins === void 0) { plugins = null; }\r\n return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);\r\n };\r\n }\r\n return ProcessTelemetryContext;\r\n}());\r\nexport { ProcessTelemetryContext };\r\n//# sourceMappingURL=ProcessTelemetryContext.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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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":"ProcessTelemetryContext.js.map","sources":["ProcessTelemetryContext.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { safeGetLogger } from \"./DiagnosticLogger\";\r\nimport { arrForEach, isArray, isFunction, isNullOrUndefined, isObject, objExtend, objForEachKey, objFreeze, objKeys, proxyFunctions } from \"./HelperFuncs\";\r\nimport { doPerf } from \"./PerfManager\";\r\nimport { LoggingSeverity, _InternalMessageId } from \"../JavaScriptSDK.Enums/LoggingEnums\";\r\nimport { dumpObj } from \"./EnvUtils\";\r\nvar strTelemetryPluginChain = \"TelemetryPluginChain\";\r\nvar strHasRunFlags = \"_hasRun\";\r\nvar strGetTelCtx = \"_getTelCtx\";\r\nvar _chainId = 0;\r\nfunction _getNextProxyStart(proxy, config, core, startAt) {\r\n while (proxy) {\r\n if (proxy.getPlugin() === startAt) {\r\n return proxy;\r\n }\r\n proxy = proxy.getNext();\r\n }\r\n // This wasn't found in the existing chain so create an isolated one with just this plugin\r\n return createTelemetryProxyChain([startAt], config, core);\r\n}\r\n/**\r\n * Creates a new Telemetry Item context with the current config, core and plugin execution chain\r\n * @param plugins - The plugin instances that will be executed\r\n * @param config - The current config\r\n * @param core - The current core instance\r\n */\r\nexport function createProcessTelemetryContext(telemetryChain, config, core, startAt) {\r\n var _nextProxy = null; // Null == No next plugin\r\n var _onComplete = null;\r\n // There is no next element (null === last element) vs not defined (undefined)\r\n // We have a proxy chain object\r\n if (startAt) {\r\n // We have a special case where we want to start execution from this specific plugin\r\n _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);\r\n }\r\n else {\r\n // Reuse the existing telemetry plugin chain (normal execution case)\r\n _nextProxy = telemetryChain;\r\n }\r\n var context = {\r\n core: function () {\r\n return core;\r\n },\r\n diagLog: function () {\r\n return safeGetLogger(core, config);\r\n },\r\n getCfg: function () {\r\n return config;\r\n },\r\n getExtCfg: _getExtCfg,\r\n getConfig: _getConfig,\r\n hasNext: function () {\r\n return _nextProxy != null;\r\n },\r\n getNext: function () {\r\n return _nextProxy;\r\n },\r\n setNext: function (nextPlugin) {\r\n _nextProxy = nextPlugin;\r\n },\r\n processNext: function (env) {\r\n _processChain(function (nextPlugin) {\r\n // Run the next plugin which will call \"processNext()\"\r\n nextPlugin.processTelemetry(env, context);\r\n });\r\n },\r\n iterate: _iterateChain,\r\n createNew: function (plugins, startAt) {\r\n if (plugins === void 0) { plugins = null; }\r\n if (isArray(plugins)) {\r\n plugins = createTelemetryProxyChain(plugins, config, core, startAt);\r\n }\r\n return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);\r\n },\r\n onComplete: function (onComplete) {\r\n _onComplete = onComplete;\r\n }\r\n };\r\n function _getExtCfg(identifier, defaultValue, mergeDefault) {\r\n if (defaultValue === void 0) { defaultValue = {}; }\r\n if (mergeDefault === void 0) { mergeDefault = 0 /* None */; }\r\n var theConfig;\r\n if (config) {\r\n var extConfig = config.extensionConfig;\r\n if (extConfig && identifier) {\r\n theConfig = extConfig[identifier];\r\n }\r\n }\r\n if (!theConfig) {\r\n // Just use the defaults\r\n theConfig = defaultValue;\r\n }\r\n else if (isObject(defaultValue)) {\r\n if (mergeDefault !== 0 /* None */) {\r\n // Merge the defaults and configured values\r\n var newConfig_1 = objExtend(true, defaultValue, theConfig);\r\n if (config && mergeDefault === 2 /* MergeDefaultFromRootOrDefault */) {\r\n // Enumerate over the defaultValues and if not already populate attempt to\r\n // find a value from the root config\r\n objForEachKey(defaultValue, function (field) {\r\n // for each unspecified field, set the default value\r\n if (isNullOrUndefined(newConfig_1[field])) {\r\n var cfgValue = config[field];\r\n if (!isNullOrUndefined(cfgValue)) {\r\n newConfig_1[field] = cfgValue;\r\n }\r\n }\r\n });\r\n }\r\n }\r\n }\r\n return theConfig;\r\n }\r\n function _getConfig(identifier, field, defaultValue) {\r\n if (defaultValue === void 0) { defaultValue = false; }\r\n var theValue;\r\n var extConfig = _getExtCfg(identifier, null);\r\n if (extConfig && !isNullOrUndefined(extConfig[field])) {\r\n theValue = extConfig[field];\r\n }\r\n else if (config && !isNullOrUndefined(config[field])) {\r\n theValue = config[field];\r\n }\r\n return !isNullOrUndefined(theValue) ? theValue : defaultValue;\r\n }\r\n function _processChain(cb) {\r\n var nextPlugin = _nextProxy;\r\n if (nextPlugin) {\r\n // Automatically move to the next plugin\r\n _nextProxy = nextPlugin.getNext();\r\n cb(nextPlugin);\r\n }\r\n else {\r\n if (_onComplete) {\r\n _onComplete();\r\n _onComplete = null;\r\n }\r\n }\r\n }\r\n function _iterateChain(cb) {\r\n while (_nextProxy) {\r\n _processChain(function (nextPlugin) {\r\n var plugin = nextPlugin.getPlugin();\r\n if (plugin) {\r\n // callback with the current on\r\n cb(plugin);\r\n }\r\n });\r\n }\r\n }\r\n return context;\r\n}\r\n/**\r\n * Creates an execution chain from the array of plugins\r\n * @param plugins - The array of plugins that will be executed in this order\r\n * @param defItemCtx - The default execution context to use when no telemetry context is passed to processTelemetry(), this\r\n * should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error\r\n * reporting (hasRun) when errors occur.\r\n */\r\nexport function createTelemetryProxyChain(plugins, config, core, startAt) {\r\n var firstProxy = null;\r\n var add = startAt ? false : true;\r\n if (isArray(plugins) && plugins.length > 0) {\r\n // Create the proxies and wire up the next plugin chain\r\n var lastProxy_1 = null;\r\n arrForEach(plugins, function (thePlugin) {\r\n if (!add && startAt === thePlugin) {\r\n add = true;\r\n }\r\n if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {\r\n // Only add plugins that are processors\r\n var newProxy = createTelemetryPluginProxy(thePlugin, config, core);\r\n if (!firstProxy) {\r\n firstProxy = newProxy;\r\n }\r\n if (lastProxy_1) {\r\n // Set this new proxy as the next for the previous one\r\n lastProxy_1._setNext(newProxy);\r\n }\r\n lastProxy_1 = newProxy;\r\n }\r\n });\r\n }\r\n if (startAt && !firstProxy) {\r\n // Special case where the \"startAt\" was not in the original list of plugins\r\n return createTelemetryProxyChain([startAt], config, core);\r\n }\r\n return firstProxy;\r\n}\r\n/**\r\n * Create the processing telemetry proxy instance, the proxy is used to abstract the current plugin to allow monitoring and\r\n * execution plugins while passing around the dynamic execution state (IProcessTelemetryContext), the proxy instance no longer\r\n * contains any execution state and can be reused between requests (this was not the case for 2.7.2 and earlier with the\r\n * TelemetryPluginChain class).\r\n * @param plugin - The plugin instance to proxy\r\n * @param config - The default execution context to use when no telemetry context is passed to processTelemetry(), this\r\n * should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error\r\n * reporting (hasRun) when errors occur.\r\n * @returns\r\n */\r\nexport function createTelemetryPluginProxy(plugin, config, core) {\r\n var nextProxy = null;\r\n var hasProcessTelemetry = isFunction(plugin.processTelemetry);\r\n var hasSetNext = isFunction(plugin.setNextPlugin);\r\n var chainId;\r\n if (plugin) {\r\n chainId = plugin.identifier + \"-\" + plugin.priority + \"-\" + _chainId++;\r\n }\r\n else {\r\n chainId = \"Unknown-0-\" + _chainId++;\r\n }\r\n var proxyChain = {\r\n getPlugin: function () {\r\n return plugin;\r\n },\r\n getNext: function () {\r\n return nextProxy;\r\n },\r\n processTelemetry: _processTelemetry,\r\n _id: chainId,\r\n _setNext: function (nextPlugin) {\r\n nextProxy = nextPlugin;\r\n }\r\n };\r\n function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {\r\n // Make sure we have a context\r\n if (!itemCtx) {\r\n // Looks like a plugin didn't pass the (optional) context, so create a new one\r\n if (plugin && isFunction(plugin[strGetTelCtx])) {\r\n // This plugin extends from the BaseTelemetryPlugin so lets use it\r\n itemCtx = plugin[strGetTelCtx]();\r\n }\r\n if (!itemCtx) {\r\n // Create a temporary one\r\n itemCtx = createProcessTelemetryContext(proxyChain, config, core);\r\n }\r\n }\r\n var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;\r\n var hasRunContext = itemCtx[strHasRunFlags];\r\n if (!hasRunContext) {\r\n // Assign and populate\r\n hasRunContext = itemCtx[strHasRunFlags] = {};\r\n }\r\n doPerf(itemCtx.core(), function () { return identifier + \":\" + name; }, function () {\r\n // Mark this component as having run\r\n hasRunContext[chainId] = true;\r\n var hasRun = false;\r\n // Ensure that we keep the context in sync\r\n itemCtx.setNext(nextProxy);\r\n if (plugin) {\r\n try {\r\n // Set a flag on the next plugin so we know if it was attempted to be executed\r\n var nextId = nextProxy ? nextProxy._id : \"\";\r\n if (nextId) {\r\n hasRunContext[nextId] = false;\r\n }\r\n hasRun = processPluginFn(itemCtx);\r\n }\r\n catch (error) {\r\n var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;\r\n if (hasNextRun) {\r\n // The next plugin after us has already run so set this one as complete\r\n hasRun = true;\r\n }\r\n if (!nextProxy || !hasNextRun) {\r\n // Either we have no next plugin or the current one did not attempt to call the next plugin\r\n // Which means the current one is the root of the failure so log/report this failure\r\n itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, \"Plugin [\" + plugin.identifier + \"] failed during \" + name + \" - \" + dumpObj(error) + \", run flags: \" + dumpObj(hasRunContext));\r\n }\r\n }\r\n }\r\n if (nextProxy && !hasRun) {\r\n // The underlying plugin is not defined, but we still want the next plugin to be executed.\r\n // So rather than leave the pipeline dead in the water we call the next plugin\r\n processProxyFn(itemCtx);\r\n }\r\n }, details, isAsync);\r\n }\r\n function _processTelemetry(env, itemCtx) {\r\n _processChain(itemCtx, function (itemCtx) {\r\n if (!hasProcessTelemetry) {\r\n return false;\r\n }\r\n // Ensure that we keep the context in sync (for processNext()), just in case a plugin\r\n // doesn't calls processTelemetry() instead of itemContext.processNext() or some\r\n // other form of error occurred\r\n if (hasSetNext) {\r\n // Backward compatibility setting the next plugin on the instance\r\n plugin.setNextPlugin(nextProxy);\r\n }\r\n plugin.processTelemetry(env, itemCtx);\r\n return true;\r\n }, function (itemCtx) {\r\n // The underlying plugin is either not defined or does not have a processTelemetry implementation\r\n // so we still want the next plugin to be executed.\r\n nextProxy.processTelemetry(env, itemCtx);\r\n }, \"processTelemetry\", function () { return ({ item: env }); }, !(env.sync));\r\n }\r\n return objFreeze(proxyChain);\r\n}\r\n/**\r\n * This class will be removed!\r\n * @deprecated use createProcessTelemetryContext() instead\r\n */\r\nvar ProcessTelemetryContext = /** @class */ (function () {\r\n /**\r\n * Creates a new Telemetry Item context with the current config, core and plugin execution chain\r\n * @param plugins - The plugin instances that will be executed\r\n * @param config - The current config\r\n * @param core - The current core instance\r\n */\r\n function ProcessTelemetryContext(pluginChain, config, core, startAt) {\r\n var _self = this;\r\n var context = createProcessTelemetryContext(pluginChain, config, core, startAt);\r\n // Proxy all functions of the context to this object\r\n proxyFunctions(_self, context, objKeys(context));\r\n }\r\n return ProcessTelemetryContext;\r\n}());\r\nexport { ProcessTelemetryContext };\r\n//# sourceMappingURL=ProcessTelemetryContext.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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 2.
|
|
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
|
|
|
@@ -49,13 +49,13 @@ export function randomValue(maxValue) {
|
|
|
49
49
|
* @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)
|
|
50
50
|
*/
|
|
51
51
|
export function random32(signed) {
|
|
52
|
-
var value;
|
|
52
|
+
var value = 0;
|
|
53
53
|
var c = getCrypto() || getMsCrypto();
|
|
54
54
|
if (c && c.getRandomValues) {
|
|
55
55
|
// Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
|
|
56
56
|
value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
if (value === 0 && isIE()) {
|
|
59
59
|
// For IE 6, 7, 8 (especially on XP) Math.random is not very random
|
|
60
60
|
if (!_mwcSeeded) {
|
|
61
61
|
// Set the seed for the Mwc algorithm
|
|
@@ -65,7 +65,7 @@ export function random32(signed) {
|
|
|
65
65
|
// Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
|
|
66
66
|
value = mwcRandom32() & MaxUInt32;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
if (value === 0) {
|
|
69
69
|
// Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
|
|
70
70
|
value = Math.floor((UInt32Mask * Math.random()) | 0);
|
|
71
71
|
}
|
|
@@ -103,4 +103,29 @@ export function mwcRandom32(signed) {
|
|
|
103
103
|
}
|
|
104
104
|
return value;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Generate random base64 id string.
|
|
108
|
+
* The default length is 22 which is 132-bits so almost the same as a GUID but as base64 (the previous default was 5)
|
|
109
|
+
* @param maxLength - Optional value to specify the length of the id to be generated, defaults to 22
|
|
110
|
+
*/
|
|
111
|
+
export function newId(maxLength) {
|
|
112
|
+
if (maxLength === void 0) { maxLength = 22; }
|
|
113
|
+
var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
114
|
+
// Start with an initial random number, consuming the value in reverse byte order
|
|
115
|
+
var number = random32() >>> 0; // Make sure it's a +ve number
|
|
116
|
+
var chars = 0;
|
|
117
|
+
var result = "";
|
|
118
|
+
while (result.length < maxLength) {
|
|
119
|
+
chars++;
|
|
120
|
+
result += base64chars.charAt(number & 0x3F);
|
|
121
|
+
number >>>= 6; // Zero fill with right shift
|
|
122
|
+
if (chars === 5) {
|
|
123
|
+
// 5 base64 characters === 30 bits so we don't have enough bits for another base64 char
|
|
124
|
+
// So add on another 30 bits and make sure it's +ve
|
|
125
|
+
number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
|
|
126
|
+
chars = 0; // We need to reset the number every 5 chars (30 bits)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
106
131
|
//# sourceMappingURL=RandomHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RandomHelper.js.map","sources":["RandomHelper.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { getCrypto, getMsCrypto, isIE } from \"./EnvUtils\";\r\nimport { dateNow } from \"./HelperFuncs\";\r\nvar UInt32Mask = 0x100000000;\r\nvar MaxUInt32 = 0xffffffff;\r\n// MWC based Random generator (for IE)\r\nvar _mwcSeeded = false;\r\nvar _mwcW = 123456789;\r\nvar _mwcZ = 987654321;\r\n// Takes any integer\r\nfunction _mwcSeed(seedValue) {\r\n if (seedValue < 0) {\r\n // Make sure we end up with a positive number and not -ve one.\r\n seedValue >>>= 0;\r\n }\r\n _mwcW = (123456789 + seedValue) & MaxUInt32;\r\n _mwcZ = (987654321 - seedValue) & MaxUInt32;\r\n _mwcSeeded = true;\r\n}\r\nfunction _autoSeedMwc() {\r\n // Simple initialization using default Math.random() - So we inherit any entropy from the browser\r\n // and bitwise XOR with the current milliseconds\r\n try {\r\n var now = dateNow() & 0x7fffffff;\r\n _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);\r\n }\r\n catch (e) {\r\n // Don't crash if something goes wrong\r\n }\r\n}\r\n/**\r\n * Generate a random value between 0 and maxValue, max value should be limited to a 32-bit maximum.\r\n * So maxValue(16) will produce a number from 0..16 (range of 17)\r\n * @param maxValue\r\n */\r\nexport function randomValue(maxValue) {\r\n if (maxValue > 0) {\r\n return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;\r\n }\r\n return 0;\r\n}\r\n/**\r\n * generate a random 32-bit number (0x000000..0xFFFFFFFF) or (-0x80000000..0x7FFFFFFF), defaults un-unsigned.\r\n * @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)\r\n */\r\nexport function random32(signed) {\r\n var value;\r\n var c = getCrypto() || getMsCrypto();\r\n if (c && c.getRandomValues) {\r\n // Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)\r\n value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;\r\n }\r\n
|
|
1
|
+
{"version":3,"file":"RandomHelper.js.map","sources":["RandomHelper.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { getCrypto, getMsCrypto, isIE } from \"./EnvUtils\";\r\nimport { dateNow } from \"./HelperFuncs\";\r\nvar UInt32Mask = 0x100000000;\r\nvar MaxUInt32 = 0xffffffff;\r\n// MWC based Random generator (for IE)\r\nvar _mwcSeeded = false;\r\nvar _mwcW = 123456789;\r\nvar _mwcZ = 987654321;\r\n// Takes any integer\r\nfunction _mwcSeed(seedValue) {\r\n if (seedValue < 0) {\r\n // Make sure we end up with a positive number and not -ve one.\r\n seedValue >>>= 0;\r\n }\r\n _mwcW = (123456789 + seedValue) & MaxUInt32;\r\n _mwcZ = (987654321 - seedValue) & MaxUInt32;\r\n _mwcSeeded = true;\r\n}\r\nfunction _autoSeedMwc() {\r\n // Simple initialization using default Math.random() - So we inherit any entropy from the browser\r\n // and bitwise XOR with the current milliseconds\r\n try {\r\n var now = dateNow() & 0x7fffffff;\r\n _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);\r\n }\r\n catch (e) {\r\n // Don't crash if something goes wrong\r\n }\r\n}\r\n/**\r\n * Generate a random value between 0 and maxValue, max value should be limited to a 32-bit maximum.\r\n * So maxValue(16) will produce a number from 0..16 (range of 17)\r\n * @param maxValue\r\n */\r\nexport function randomValue(maxValue) {\r\n if (maxValue > 0) {\r\n return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;\r\n }\r\n return 0;\r\n}\r\n/**\r\n * generate a random 32-bit number (0x000000..0xFFFFFFFF) or (-0x80000000..0x7FFFFFFF), defaults un-unsigned.\r\n * @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)\r\n */\r\nexport function random32(signed) {\r\n var value = 0;\r\n var c = getCrypto() || getMsCrypto();\r\n if (c && c.getRandomValues) {\r\n // Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)\r\n value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;\r\n }\r\n if (value === 0 && isIE()) {\r\n // For IE 6, 7, 8 (especially on XP) Math.random is not very random\r\n if (!_mwcSeeded) {\r\n // Set the seed for the Mwc algorithm\r\n _autoSeedMwc();\r\n }\r\n // Don't use Math.random for IE\r\n // Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)\r\n value = mwcRandom32() & MaxUInt32;\r\n }\r\n if (value === 0) {\r\n // Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)\r\n value = Math.floor((UInt32Mask * Math.random()) | 0);\r\n }\r\n if (!signed) {\r\n // Make sure we end up with a positive number and not -ve one.\r\n value >>>= 0;\r\n }\r\n return value;\r\n}\r\n/**\r\n * Seed the MWC random number generator with the specified seed or a random value\r\n * @param value - optional the number to used as the seed, if undefined, null or zero a random value will be chosen\r\n */\r\nexport function mwcRandomSeed(value) {\r\n if (!value) {\r\n _autoSeedMwc();\r\n }\r\n else {\r\n _mwcSeed(value);\r\n }\r\n}\r\n/**\r\n * Generate a random 32-bit number between (0x000000..0xFFFFFFFF) or (-0x80000000..0x7FFFFFFF), using MWC (Multiply with carry)\r\n * instead of Math.random() defaults to un-signed.\r\n * Used as a replacement random generator for IE to avoid issues with older IE instances.\r\n * @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)\r\n */\r\nexport function mwcRandom32(signed) {\r\n _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;\r\n _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;\r\n var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;\r\n if (!signed) {\r\n // Make sure we end up with a positive number and not -ve one.\r\n value >>>= 0;\r\n }\r\n return value;\r\n}\r\n/**\r\n * Generate random base64 id string.\r\n * The default length is 22 which is 132-bits so almost the same as a GUID but as base64 (the previous default was 5)\r\n * @param maxLength - Optional value to specify the length of the id to be generated, defaults to 22\r\n */\r\nexport function newId(maxLength) {\r\n if (maxLength === void 0) { maxLength = 22; }\r\n var base64chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\r\n // Start with an initial random number, consuming the value in reverse byte order\r\n var number = random32() >>> 0; // Make sure it's a +ve number\r\n var chars = 0;\r\n var result = \"\";\r\n while (result.length < maxLength) {\r\n chars++;\r\n result += base64chars.charAt(number & 0x3F);\r\n number >>>= 6; // Zero fill with right shift\r\n if (chars === 5) {\r\n // 5 base64 characters === 30 bits so we don't have enough bits for another base64 char\r\n // So add on another 30 bits and make sure it's +ve\r\n number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;\r\n chars = 0; // We need to reset the number every 5 chars (30 bits)\r\n }\r\n }\r\n return result;\r\n}\r\n//# sourceMappingURL=RandomHelper.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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 2.
|
|
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
|
|
|
@@ -38,7 +38,7 @@ export function initializePlugins(processContext, extensions) {
|
|
|
38
38
|
proxy = proxy.getNext();
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
// Now
|
|
41
|
+
// Now initialize the plugins
|
|
42
42
|
arrForEach(initPlugins, function (thePlugin) {
|
|
43
43
|
thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());
|
|
44
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TelemetryHelpers.js.map","sources":["TelemetryHelpers.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { arrForEach, isFunction } from \"./HelperFuncs\";\r\nvar processTelemetry = \"processTelemetry\";\r\nvar priority = \"priority\";\r\nvar setNextPlugin = \"setNextPlugin\";\r\nvar isInitialized = \"isInitialized\";\r\n/**\r\n * Initialize the queue of plugins\r\n * @param plugins - The array of plugins to initialize and setting of the next plugin\r\n * @param config The current config for the instance\r\n * @param core THe current core instance\r\n * @param extensions The extensions\r\n */\r\nexport function initializePlugins(processContext, extensions) {\r\n // Set the next plugin and identified the uninitialized plugins\r\n var initPlugins = [];\r\n var lastPlugin = null;\r\n var proxy = processContext.getNext();\r\n while (proxy) {\r\n var thePlugin = proxy.getPlugin();\r\n if (thePlugin) {\r\n if (lastPlugin &&\r\n isFunction(lastPlugin[setNextPlugin]) &&\r\n isFunction(thePlugin[processTelemetry])) {\r\n // Set this plugin as the next for the previous one\r\n lastPlugin[setNextPlugin](thePlugin);\r\n }\r\n if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {\r\n initPlugins.push(thePlugin);\r\n }\r\n lastPlugin = thePlugin;\r\n proxy = proxy.getNext();\r\n }\r\n }\r\n // Now
|
|
1
|
+
{"version":3,"file":"TelemetryHelpers.js.map","sources":["TelemetryHelpers.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { arrForEach, isFunction } from \"./HelperFuncs\";\r\nvar processTelemetry = \"processTelemetry\";\r\nvar priority = \"priority\";\r\nvar setNextPlugin = \"setNextPlugin\";\r\nvar isInitialized = \"isInitialized\";\r\n/**\r\n * Initialize the queue of plugins\r\n * @param plugins - The array of plugins to initialize and setting of the next plugin\r\n * @param config The current config for the instance\r\n * @param core THe current core instance\r\n * @param extensions The extensions\r\n */\r\nexport function initializePlugins(processContext, extensions) {\r\n // Set the next plugin and identified the uninitialized plugins\r\n var initPlugins = [];\r\n var lastPlugin = null;\r\n var proxy = processContext.getNext();\r\n while (proxy) {\r\n var thePlugin = proxy.getPlugin();\r\n if (thePlugin) {\r\n if (lastPlugin &&\r\n isFunction(lastPlugin[setNextPlugin]) &&\r\n isFunction(thePlugin[processTelemetry])) {\r\n // Set this plugin as the next for the previous one\r\n lastPlugin[setNextPlugin](thePlugin);\r\n }\r\n if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {\r\n initPlugins.push(thePlugin);\r\n }\r\n lastPlugin = thePlugin;\r\n proxy = proxy.getNext();\r\n }\r\n }\r\n // Now initialize the plugins\r\n arrForEach(initPlugins, function (thePlugin) {\r\n thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());\r\n });\r\n}\r\nexport function sortPlugins(plugins) {\r\n // Sort by priority\r\n return plugins.sort(function (extA, extB) {\r\n var result = 0;\r\n var bHasProcess = isFunction(extB[processTelemetry]);\r\n if (isFunction(extA[processTelemetry])) {\r\n result = bHasProcess ? extA[priority] - extB[priority] : 1;\r\n }\r\n else if (bHasProcess) {\r\n result = -1;\r\n }\r\n return result;\r\n });\r\n // sort complete\r\n}\r\n//# sourceMappingURL=TelemetryHelpers.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"}
|