@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.
- package/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +766 -1967
- 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 +9840 -16439
- package/dist/applicationinsights-core-js.api.md +48 -425
- package/dist/applicationinsights-core-js.d.ts +123 -784
- package/dist/applicationinsights-core-js.js +766 -1967
- 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 +123 -784
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +69 -3
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +99 -496
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +21 -120
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +87 -202
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +4 -4
- package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +148 -7
- package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +14 -27
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +12 -13
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +86 -89
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -3
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +42 -37
- package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +119 -430
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +4 -30
- package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +14 -60
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +76 -0
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +96 -90
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +2 -1
- 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/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +2 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
- package/dist-esm/applicationinsights-core-js.js +7 -12
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +3 -3
- package/src/JavaScriptSDK/AppInsightsCore.ts +101 -2
- package/src/JavaScriptSDK/BaseCore.ts +120 -696
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +31 -205
- package/src/JavaScriptSDK/ChannelController.ts +103 -242
- package/src/JavaScriptSDK/CookieMgr.ts +5 -7
- package/src/JavaScriptSDK/CoreUtils.ts +172 -8
- package/src/JavaScriptSDK/DiagnosticLogger.ts +14 -29
- package/src/JavaScriptSDK/EnvUtils.ts +12 -13
- package/src/JavaScriptSDK/HelperFuncs.ts +97 -123
- package/src/JavaScriptSDK/InstrumentHooks.ts +2 -4
- package/src/JavaScriptSDK/NotificationManager.ts +37 -34
- package/src/JavaScriptSDK/PerfManager.ts +7 -4
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +134 -543
- package/src/JavaScriptSDK/RandomHelper.ts +3 -35
- package/src/JavaScriptSDK/TelemetryHelpers.ts +21 -83
- package/src/JavaScriptSDK/TelemetryPluginChain.ts +120 -0
- package/src/JavaScriptSDK.Enums/LoggingEnums.ts +87 -184
- package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -5
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +2 -82
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +5 -16
- package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +6 -16
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +14 -94
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +10 -28
- package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +11 -9
- package/types/JavaScriptSDK/AppInsightsCore.d.ts +21 -0
- package/types/JavaScriptSDK/BaseCore.d.ts +3 -81
- package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +10 -53
- package/types/JavaScriptSDK/ChannelController.d.ts +17 -16
- package/types/JavaScriptSDK/CoreUtils.d.ts +48 -1
- package/types/JavaScriptSDK/DiagnosticLogger.d.ts +0 -10
- package/types/JavaScriptSDK/HelperFuncs.d.ts +32 -33
- package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
- package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +6 -69
- package/types/JavaScriptSDK/RandomHelper.d.ts +0 -6
- package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -23
- package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +32 -0
- package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +2 -91
- package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +0 -4
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +1 -72
- package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +5 -16
- package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +0 -9
- package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +11 -82
- package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +8 -25
- package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +10 -9
- package/types/applicationinsights-core-js.d.ts +9 -18
- package/types/tsdoc-metadata.json +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +0 -93
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +0 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +0 -477
- package/dist-esm/JavaScriptSDK/EventHelpers.js.map +0 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +0 -28
- package/dist-esm/JavaScriptSDK/InternalConstants.js.map +0 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +0 -81
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +0 -1
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +0 -33
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +0 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +0 -8
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +0 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +0 -8
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +0 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +0 -6
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +0 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +0 -8
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +0 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +0 -8
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +0 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +0 -6
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +0 -1
- package/src/JavaScriptSDK/DataCacheHelper.ts +0 -106
- package/src/JavaScriptSDK/EventHelpers.ts +0 -550
- package/src/JavaScriptSDK/InternalConstants.ts +0 -26
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -111
- package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -46
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
- package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
- package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -16
- package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
- package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -34
- package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
- package/types/JavaScriptSDK/DataCacheHelper.d.ts +0 -13
- package/types/JavaScriptSDK/EventHelpers.d.ts +0 -154
- package/types/JavaScriptSDK/InternalConstants.d.ts +0 -20
- package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -16
- package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +0 -11
- package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +0 -21
- package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +0 -20
- package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +0 -13
- package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +0 -6
- package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +0 -22
- 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-
|
|
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
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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
|
-
*
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
33
|
+
return proxies.length > 0 ? proxies[0] : null;
|
|
164
34
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
189
|
-
|
|
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
|
-
|
|
215
|
-
context.createNew = _createNew;
|
|
216
|
-
return context;
|
|
51
|
+
return _createProxyChain(plugins, itemCtx);
|
|
217
52
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
236
|
-
if (plugins
|
|
237
|
-
|
|
238
|
-
plugins = createTelemetryProxyChain(plugins, config, core, startAt);
|
|
65
|
+
if (startAt && !add) {
|
|
66
|
+
if (!plugins) {
|
|
67
|
+
plugins = [];
|
|
239
68
|
}
|
|
240
|
-
|
|
69
|
+
plugins.push(startAt);
|
|
241
70
|
}
|
|
242
|
-
|
|
243
|
-
context.createNew = _createNew;
|
|
244
|
-
return context;
|
|
71
|
+
return _createProxyChain(plugins, itemCtx);
|
|
245
72
|
}
|
|
246
|
-
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
264
|
-
//
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
firstProxy = newProxy;
|
|
89
|
+
else {
|
|
90
|
+
// We just have an array
|
|
91
|
+
if (startAt) {
|
|
92
|
+
_nextProxy = _copyPluginChain(plugins, _self, startAt);
|
|
268
93
|
}
|
|
269
|
-
if (
|
|
270
|
-
//
|
|
271
|
-
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
|
|
382
|
-
|
|
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
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
function
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
}());
|