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