@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
|
@@ -3,557 +3,90 @@
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
|
|
6
|
+
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
|
|
6
7
|
import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
|
|
7
8
|
import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
|
|
8
9
|
import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
|
|
9
|
-
import {
|
|
10
|
+
import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
10
11
|
import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
|
|
11
|
-
import { safeGetLogger
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { eLoggingSeverity, _eInternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
15
|
-
import { dumpObj } from "./EnvUtils";
|
|
16
|
-
import { strCore, strDisabled, strEmpty, strIsInitialized, strTeardown, strUpdate } from "./InternalConstants";
|
|
17
|
-
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
|
|
18
|
-
import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
19
|
-
import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
|
|
20
|
-
import { _getPluginState } from "./TelemetryHelpers";
|
|
21
|
-
|
|
22
|
-
const strTelemetryPluginChain = "TelemetryPluginChain";
|
|
23
|
-
const strHasRunFlags = "_hasRun";
|
|
24
|
-
const strGetTelCtx = "_getTelCtx";
|
|
25
|
-
|
|
26
|
-
let _chainId = 0;
|
|
27
|
-
|
|
28
|
-
interface OnCompleteCallback {
|
|
29
|
-
func: () => void;
|
|
30
|
-
self: any; // This for the function
|
|
31
|
-
args: any[]; // Additional arguments for the function
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface IInternalTelemetryPluginChain extends ITelemetryPluginChain {
|
|
35
|
-
_id: string;
|
|
36
|
-
_setNext: (nextPlugin: IInternalTelemetryPluginChain) => void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface IInternalContext<T extends IBaseProcessingContext> {
|
|
40
|
-
_next: () => ITelemetryPluginChain,
|
|
41
|
-
|
|
42
|
-
// The public context that will be exposed
|
|
43
|
-
ctx: T
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function _getNextProxyStart(proxy: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt: IPlugin): ITelemetryPluginChain {
|
|
47
|
-
while (proxy) {
|
|
48
|
-
if (proxy.getPlugin() === startAt) {
|
|
49
|
-
return proxy;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
proxy = proxy.getNext();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// This wasn't found in the existing chain so create an isolated one with just this plugin
|
|
56
|
-
return createTelemetryProxyChain([startAt], config, core);
|
|
57
|
-
}
|
|
12
|
+
import { safeGetLogger } from "./DiagnosticLogger";
|
|
13
|
+
import { TelemetryPluginChain } from "./TelemetryPluginChain";
|
|
14
|
+
import { arrForEach, isFunction, isNullOrUndefined, isUndefined } from "./HelperFuncs";
|
|
58
15
|
|
|
59
16
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param telemetryChain
|
|
62
|
-
* @param config
|
|
63
|
-
* @param core
|
|
64
|
-
* @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
|
|
65
|
-
* @returns
|
|
17
|
+
* Creates the instance execution chain for the plugins
|
|
66
18
|
*/
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
let _onComplete: OnCompleteCallback[] = [];
|
|
72
|
-
|
|
73
|
-
if (startAt !== null) {
|
|
74
|
-
// There is no next element (null) vs not defined (undefined) so use the full chain
|
|
75
|
-
_nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let context: IInternalContext<T> = {
|
|
79
|
-
_next: _moveNext,
|
|
80
|
-
ctx: {
|
|
81
|
-
core: () => {
|
|
82
|
-
return core
|
|
83
|
-
},
|
|
84
|
-
diagLog: () => {
|
|
85
|
-
return safeGetLogger(core, config);
|
|
86
|
-
},
|
|
87
|
-
getCfg: () => {
|
|
88
|
-
return config;
|
|
89
|
-
},
|
|
90
|
-
getExtCfg: _getExtCfg,
|
|
91
|
-
getConfig: _getConfig,
|
|
92
|
-
hasNext: () => {
|
|
93
|
-
return !!_nextProxy;
|
|
94
|
-
},
|
|
95
|
-
getNext: () => {
|
|
96
|
-
return _nextProxy;
|
|
97
|
-
},
|
|
98
|
-
setNext: (nextPlugin:ITelemetryPluginChain) => {
|
|
99
|
-
_nextProxy = nextPlugin;
|
|
100
|
-
},
|
|
101
|
-
iterate: _iterateChain,
|
|
102
|
-
onComplete: _addOnComplete
|
|
103
|
-
} as T
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
function _addOnComplete(onComplete: () => void, that?: any, ...args: any[]) {
|
|
107
|
-
if (onComplete) {
|
|
108
|
-
_onComplete.push({
|
|
109
|
-
func: onComplete,
|
|
110
|
-
self: !isUndefined(that) ? that : context.ctx,
|
|
111
|
-
args: args
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function _moveNext() {
|
|
117
|
-
let nextProxy = _nextProxy;
|
|
118
|
-
|
|
119
|
-
// Automatically move to the next plugin
|
|
120
|
-
_nextProxy = nextProxy ? nextProxy.getNext() : null;
|
|
121
|
-
|
|
122
|
-
if (!nextProxy) {
|
|
123
|
-
let onComplete = _onComplete;
|
|
124
|
-
if (onComplete && onComplete.length > 0) {
|
|
125
|
-
arrForEach(onComplete, (completeDetails) => {
|
|
126
|
-
try {
|
|
127
|
-
completeDetails.func.call(completeDetails.self, completeDetails.args);
|
|
128
|
-
} catch (e) {
|
|
129
|
-
_throwInternal(
|
|
130
|
-
core.logger,
|
|
131
|
-
eLoggingSeverity.WARNING,
|
|
132
|
-
_eInternalMessageId.PluginException,
|
|
133
|
-
"Unexpected Exception during onComplete - " + dumpObj(e));
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
_onComplete = [];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return nextProxy;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function _getExtCfg<T>(identifier: string, defaultValue: T|any = {}, mergeDefault: GetExtCfgMergeType = GetExtCfgMergeType.None) {
|
|
145
|
-
let theConfig: T;
|
|
146
|
-
if (config) {
|
|
147
|
-
let extConfig = config.extensionConfig;
|
|
148
|
-
if (extConfig && identifier) {
|
|
149
|
-
theConfig = extConfig[identifier];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (!theConfig) {
|
|
154
|
-
// Just use the defaults
|
|
155
|
-
theConfig = defaultValue as T;
|
|
156
|
-
} else if (isObject(defaultValue)) {
|
|
157
|
-
if (mergeDefault !== GetExtCfgMergeType.None) {
|
|
158
|
-
// Merge the defaults and configured values
|
|
159
|
-
let newConfig = objExtend(true, defaultValue, theConfig);
|
|
160
|
-
|
|
161
|
-
if (config && mergeDefault === GetExtCfgMergeType.MergeDefaultFromRootOrDefault) {
|
|
162
|
-
// Enumerate over the defaultValues and if not already populate attempt to
|
|
163
|
-
// find a value from the root config
|
|
164
|
-
objForEachKey(defaultValue, (field) => {
|
|
165
|
-
// for each unspecified field, set the default value
|
|
166
|
-
if (isNullOrUndefined(newConfig[field])) {
|
|
167
|
-
let cfgValue = config[field];
|
|
168
|
-
if (!isNullOrUndefined(cfgValue)) {
|
|
169
|
-
newConfig[field] = cfgValue;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return theConfig;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function _getConfig(identifier:string, field: string, defaultValue: number | string | boolean | string[] | RegExp[] | Function = false) {
|
|
181
|
-
let theValue;
|
|
182
|
-
let extConfig = _getExtCfg(identifier, null);
|
|
183
|
-
if (extConfig && !isNullOrUndefined(extConfig[field])) {
|
|
184
|
-
theValue = extConfig[field];
|
|
185
|
-
} else if (config && !isNullOrUndefined(config[field])) {
|
|
186
|
-
theValue = config[field];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return !isNullOrUndefined(theValue) ? theValue : defaultValue;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function _iterateChain<T extends ITelemetryPlugin = ITelemetryPlugin>(cb: (plugin: T) => void) {
|
|
193
|
-
// Keep processing until we reach the end of the chain
|
|
194
|
-
let nextPlugin: ITelemetryPluginChain;
|
|
195
|
-
while(!!(nextPlugin = context._next())) {
|
|
196
|
-
let plugin = nextPlugin.getPlugin();
|
|
197
|
-
if (plugin) {
|
|
198
|
-
// callback with the current on
|
|
199
|
-
cb(plugin as T);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return context;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Creates a new Telemetry Item context with the current config, core and plugin execution chain
|
|
209
|
-
* @param plugins - The plugin instances that will be executed
|
|
210
|
-
* @param config - The current config
|
|
211
|
-
* @param core - The current core instance
|
|
212
|
-
* @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
|
|
213
|
-
*/
|
|
214
|
-
export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain | null, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext {
|
|
215
|
-
let internalContext: IInternalContext<IProcessTelemetryContext> = _createInternalContext<IProcessTelemetryContext>(telemetryChain, config, core, startAt);
|
|
216
|
-
let context = internalContext.ctx;
|
|
217
|
-
|
|
218
|
-
function _processNext(env: ITelemetryItem) {
|
|
219
|
-
let nextPlugin: ITelemetryPluginChain = internalContext._next();
|
|
220
|
-
// Run the next plugin which will call "processNext()"
|
|
221
|
-
nextPlugin && nextPlugin.processTelemetry(env, context);
|
|
222
|
-
|
|
223
|
-
return !nextPlugin;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function _createNew(plugins: IPlugin[] | ITelemetryPluginChain | null = null, startAt?: IPlugin) {
|
|
227
|
-
if (isArray(plugins)) {
|
|
228
|
-
plugins = createTelemetryProxyChain(plugins, config, core, startAt);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
context.processNext = _processNext;
|
|
235
|
-
context.createNew = _createNew;
|
|
236
|
-
|
|
237
|
-
return context;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Creates a new Telemetry Item context with the current config, core and plugin execution chain for handling the unloading of the chain
|
|
242
|
-
* @param plugins - The plugin instances that will be executed
|
|
243
|
-
* @param config - The current config
|
|
244
|
-
* @param core - The current core instance
|
|
245
|
-
* @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
|
|
246
|
-
*/
|
|
247
|
-
export function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUnloadContext {
|
|
248
|
-
let internalContext: IInternalContext<IProcessTelemetryUnloadContext> = _createInternalContext<IProcessTelemetryUnloadContext>(telemetryChain, config, core, startAt);
|
|
249
|
-
let context = internalContext.ctx;
|
|
250
|
-
|
|
251
|
-
function _processNext(unloadState: ITelemetryUnloadState) {
|
|
252
|
-
let nextPlugin: ITelemetryPluginChain = internalContext._next();
|
|
253
|
-
nextPlugin && nextPlugin.unload(context, unloadState);
|
|
254
|
-
|
|
255
|
-
return !nextPlugin;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function _createNew(plugins: IPlugin[] | ITelemetryPluginChain = null, startAt?: IPlugin): IProcessTelemetryUnloadContext {
|
|
259
|
-
if (isArray(plugins)) {
|
|
260
|
-
plugins = createTelemetryProxyChain(plugins, config, core, startAt);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
context.processNext = _processNext;
|
|
267
|
-
context.createNew = _createNew
|
|
268
|
-
|
|
269
|
-
return context;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Creates a new Telemetry Item context with the current config, core and plugin execution chain for updating the configuration
|
|
274
|
-
* @param plugins - The plugin instances that will be executed
|
|
275
|
-
* @param config - The current config
|
|
276
|
-
* @param core - The current core instance
|
|
277
|
-
* @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
|
|
278
|
-
*/
|
|
279
|
-
export function createProcessTelemetryUpdateContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUpdateContext {
|
|
280
|
-
let internalContext: IInternalContext<IProcessTelemetryUpdateContext> = _createInternalContext<IProcessTelemetryUpdateContext>(telemetryChain, config, core, startAt);
|
|
281
|
-
let context = internalContext.ctx;
|
|
282
|
-
|
|
283
|
-
function _processNext(updateState: ITelemetryUpdateState) {
|
|
284
|
-
return context.iterate((plugin) => {
|
|
285
|
-
if (isFunction(plugin[strUpdate])) {
|
|
286
|
-
plugin[strUpdate](context, updateState);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function _createNew(plugins: IPlugin[] | ITelemetryPluginChain = null, startAt?: IPlugin) {
|
|
292
|
-
if (isArray(plugins)) {
|
|
293
|
-
plugins = createTelemetryProxyChain(plugins, config, core, startAt);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
context.processNext = _processNext;
|
|
300
|
-
context.createNew = _createNew;
|
|
301
|
-
|
|
302
|
-
return context;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Creates an execution chain from the array of plugins
|
|
307
|
-
* @param plugins - The array of plugins that will be executed in this order
|
|
308
|
-
* @param defItemCtx - The default execution context to use when no telemetry context is passed to processTelemetry(), this
|
|
309
|
-
* should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
|
|
310
|
-
* reporting (hasRun) when errors occur.
|
|
311
|
-
*/
|
|
312
|
-
export function createTelemetryProxyChain(plugins: IPlugin[], config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): ITelemetryPluginChain {
|
|
313
|
-
let firstProxy: ITelemetryPluginChain = null;
|
|
314
|
-
let add = startAt ? false : true;
|
|
315
|
-
|
|
316
|
-
if (isArray(plugins) && plugins.length > 0) {
|
|
19
|
+
function _createProxyChain(plugins:IPlugin[], itemCtx:IProcessTelemetryContext) {
|
|
20
|
+
let proxies:ITelemetryPluginChain[] = [];
|
|
21
|
+
|
|
22
|
+
if (plugins && plugins.length > 0) {
|
|
317
23
|
// Create the proxies and wire up the next plugin chain
|
|
318
|
-
let lastProxy:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
|
|
24
|
+
let lastProxy:TelemetryPluginChain = null;
|
|
25
|
+
for (let idx = 0; idx < plugins.length; idx++) {
|
|
26
|
+
let thePlugin = plugins[idx] as ITelemetryPlugin;
|
|
27
|
+
if (thePlugin && isFunction(thePlugin.processTelemetry)) {
|
|
325
28
|
// Only add plugins that are processors
|
|
326
|
-
let newProxy =
|
|
327
|
-
|
|
328
|
-
firstProxy = newProxy;
|
|
329
|
-
}
|
|
330
|
-
|
|
29
|
+
let newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
|
|
30
|
+
proxies.push(newProxy);
|
|
331
31
|
if (lastProxy) {
|
|
332
32
|
// Set this new proxy as the next for the previous one
|
|
333
|
-
lastProxy.
|
|
33
|
+
lastProxy.setNext(newProxy);
|
|
334
34
|
}
|
|
335
35
|
|
|
336
|
-
lastProxy = newProxy
|
|
36
|
+
lastProxy = newProxy;
|
|
337
37
|
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (startAt && !firstProxy) {
|
|
342
|
-
// Special case where the "startAt" was not in the original list of plugins
|
|
343
|
-
return createTelemetryProxyChain([startAt], config, core);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return firstProxy;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Create the processing telemetry proxy instance, the proxy is used to abstract the current plugin to allow monitoring and
|
|
351
|
-
* execution plugins while passing around the dynamic execution state (IProcessTelemetryContext), the proxy instance no longer
|
|
352
|
-
* contains any execution state and can be reused between requests (this was not the case for 2.7.2 and earlier with the
|
|
353
|
-
* TelemetryPluginChain class).
|
|
354
|
-
* @param plugin - The plugin instance to proxy
|
|
355
|
-
* @param config - The default execution context to use when no telemetry context is passed to processTelemetry(), this
|
|
356
|
-
* should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
|
|
357
|
-
* reporting (hasRun) when errors occur.
|
|
358
|
-
* @returns
|
|
359
|
-
*/
|
|
360
|
-
export function createTelemetryPluginProxy(plugin: ITelemetryPlugin, config: IConfiguration, core: IAppInsightsCore): ITelemetryPluginChain {
|
|
361
|
-
let nextProxy: IInternalTelemetryPluginChain = null;
|
|
362
|
-
let hasProcessTelemetry = isFunction(plugin.processTelemetry);
|
|
363
|
-
let hasSetNext = isFunction(plugin.setNextPlugin);
|
|
364
|
-
let chainId: string;
|
|
365
|
-
if (plugin) {
|
|
366
|
-
chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
|
|
367
|
-
} else {
|
|
368
|
-
chainId = "Unknown-0-" + _chainId++;
|
|
369
|
-
}
|
|
370
|
-
let proxyChain: IInternalTelemetryPluginChain = {
|
|
371
|
-
getPlugin: () => {
|
|
372
|
-
return plugin;
|
|
373
|
-
},
|
|
374
|
-
getNext: () => {
|
|
375
|
-
return nextProxy;
|
|
376
|
-
},
|
|
377
|
-
processTelemetry: _processTelemetry,
|
|
378
|
-
unload: _unloadPlugin,
|
|
379
|
-
update: _updatePlugin,
|
|
380
|
-
_id: chainId,
|
|
381
|
-
_setNext: (nextPlugin: IInternalTelemetryPluginChain) => {
|
|
382
|
-
nextProxy = nextPlugin;
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
function _getTelCtx() {
|
|
387
|
-
let itemCtx: IProcessTelemetryContext;
|
|
388
|
-
|
|
389
|
-
// Looks like a plugin didn't pass the (optional) context, so create a new one
|
|
390
|
-
if (plugin && isFunction(plugin[strGetTelCtx])) {
|
|
391
|
-
// This plugin extends from the BaseTelemetryPlugin so lets use it
|
|
392
|
-
itemCtx = plugin[strGetTelCtx]();
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (!itemCtx) {
|
|
396
|
-
// Create a temporary one
|
|
397
|
-
itemCtx = createProcessTelemetryContext(proxyChain, config, core);
|
|
398
38
|
}
|
|
399
|
-
|
|
400
|
-
return itemCtx;
|
|
401
39
|
}
|
|
402
40
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
processPluginFn: (itemCtx: T) => boolean,
|
|
406
|
-
name: string,
|
|
407
|
-
details: () => any,
|
|
408
|
-
isAsync: boolean) {
|
|
409
|
-
|
|
410
|
-
let hasRun = false;
|
|
411
|
-
let identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
|
|
412
|
-
let hasRunContext = itemCtx[strHasRunFlags];
|
|
413
|
-
if (!hasRunContext) {
|
|
414
|
-
// Assign and populate
|
|
415
|
-
hasRunContext = itemCtx[strHasRunFlags] = {};
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Ensure that we keep the context in sync
|
|
419
|
-
itemCtx.setNext(nextProxy);
|
|
420
|
-
|
|
421
|
-
if (plugin) {
|
|
422
|
-
doPerf(itemCtx[strCore](), () => identifier + ":" + name, () => {
|
|
423
|
-
// Mark this component as having run
|
|
424
|
-
hasRunContext[chainId] = true;
|
|
425
|
-
|
|
426
|
-
try {
|
|
427
|
-
// Set a flag on the next plugin so we know if it was attempted to be executed
|
|
428
|
-
let nextId = nextProxy ? nextProxy._id : strEmpty;
|
|
429
|
-
if (nextId) {
|
|
430
|
-
hasRunContext[nextId] = false;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
hasRun = processPluginFn(itemCtx);
|
|
434
|
-
} catch (error) {
|
|
435
|
-
let hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
|
|
436
|
-
if (hasNextRun) {
|
|
437
|
-
// The next plugin after us has already run so set this one as complete
|
|
438
|
-
hasRun = true;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (!nextProxy || !hasNextRun) {
|
|
442
|
-
|
|
443
|
-
// Either we have no next plugin or the current one did not attempt to call the next plugin
|
|
444
|
-
// Which means the current one is the root of the failure so log/report this failure
|
|
445
|
-
_throwInternal(
|
|
446
|
-
itemCtx.diagLog(),
|
|
447
|
-
eLoggingSeverity.CRITICAL,
|
|
448
|
-
_eInternalMessageId.PluginException,
|
|
449
|
-
"Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}, details, isAsync);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return hasRun;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
function _processTelemetry(env: ITelemetryItem, itemCtx: IProcessTelemetryContext) {
|
|
459
|
-
itemCtx = itemCtx || _getTelCtx();
|
|
460
|
-
|
|
461
|
-
function _callProcessTelemetry(itemCtx: IProcessTelemetryContext) {
|
|
462
|
-
if (!plugin || !hasProcessTelemetry) {
|
|
463
|
-
return false;
|
|
464
|
-
}
|
|
41
|
+
return proxies.length > 0 ? proxies[0] : null;
|
|
42
|
+
}
|
|
465
43
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
44
|
+
function _copyProxyChain(proxy:ITelemetryPluginChain, itemCtx:IProcessTelemetryContext, startAt:IPlugin) {
|
|
45
|
+
let plugins:IPlugin[] = [];
|
|
46
|
+
let add = startAt ? false : true;
|
|
470
47
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
|
|
48
|
+
if (proxy) {
|
|
49
|
+
while (proxy) {
|
|
50
|
+
let thePlugin = proxy.getPlugin();
|
|
51
|
+
if (add || thePlugin === startAt) {
|
|
52
|
+
add = true;
|
|
53
|
+
plugins.push(thePlugin);
|
|
477
54
|
}
|
|
478
|
-
|
|
479
|
-
plugin.processTelemetry(env, itemCtx);
|
|
480
|
-
|
|
481
|
-
// Process Telemetry is expected to call itemCtx.processNext() or nextPlugin.processTelemetry()
|
|
482
|
-
return true;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", () => ({ item: env }), !((env as any).sync))) {
|
|
486
|
-
// The underlying plugin is either not defined, not enabled or does not have a processTelemetry implementation
|
|
487
|
-
// so we still want the next plugin to be executed.
|
|
488
|
-
itemCtx.processNext(env);
|
|
55
|
+
proxy = proxy.getNext();
|
|
489
56
|
}
|
|
490
57
|
}
|
|
491
58
|
|
|
492
|
-
|
|
59
|
+
if (!add) {
|
|
60
|
+
plugins.push(startAt);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return _createProxyChain(plugins, itemCtx);
|
|
64
|
+
}
|
|
493
65
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
let pluginCore = plugin[strCore] || pluginState.core;
|
|
500
|
-
// Only teardown the plugin if it was initialized by the current core (i.e. It's not a shared plugin)
|
|
501
|
-
if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
|
|
502
|
-
// Handle plugins that don't extend from the BaseTelemetryPlugin
|
|
503
|
-
pluginState[strCore] = null;
|
|
504
|
-
pluginState[strTeardown] = true;
|
|
505
|
-
pluginState[strIsInitialized] = false;
|
|
66
|
+
function _copyPluginChain(srcPlugins:IPlugin[], itemCtx:IProcessTelemetryContext, startAt:IPlugin) {
|
|
67
|
+
let plugins:IPlugin[] = srcPlugins;
|
|
68
|
+
let add = false;
|
|
69
|
+
if (startAt && srcPlugins) {
|
|
70
|
+
plugins = [];
|
|
506
71
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
72
|
+
arrForEach(srcPlugins, thePlugin => {
|
|
73
|
+
if (add || thePlugin === startAt) {
|
|
74
|
+
add = true;
|
|
75
|
+
plugins.push(thePlugin);
|
|
512
76
|
}
|
|
513
|
-
|
|
514
|
-
return hasRun;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (!_processChain(unloadCtx, _callTeardown, "unload", () => {}, unloadState.isAsync)) {
|
|
518
|
-
// Only called if we hasRun was not true
|
|
519
|
-
unloadCtx.processNext(unloadState);
|
|
520
|
-
}
|
|
77
|
+
});
|
|
521
78
|
}
|
|
522
79
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
// Setting default of hasRun as false so the proxyProcessFn() is called as teardown() doesn't have to exist or call unloadNext().
|
|
527
|
-
let hasRun = false;
|
|
528
|
-
if (plugin) {
|
|
529
|
-
let pluginState = _getPluginState(plugin);
|
|
530
|
-
let pluginCore = plugin[strCore] || pluginState.core;
|
|
531
|
-
|
|
532
|
-
// Only update the plugin if it was initialized by the current core (i.e. It's not a shared plugin)
|
|
533
|
-
if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
|
|
534
|
-
if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
|
|
535
|
-
// plugin told us that it was going to (or has) call unloadCtx.processNext()
|
|
536
|
-
hasRun = true;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
return hasRun;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
if (!_processChain(updateCtx, _callUpdate, "update", () => {}, false)) {
|
|
545
|
-
// Only called if we hasRun was not true
|
|
546
|
-
updateCtx.processNext(updateState);
|
|
80
|
+
if (startAt && !add) {
|
|
81
|
+
if (!plugins) {
|
|
82
|
+
plugins = [];
|
|
547
83
|
}
|
|
84
|
+
plugins.push(startAt);
|
|
548
85
|
}
|
|
549
|
-
|
|
550
|
-
return
|
|
86
|
+
|
|
87
|
+
return _createProxyChain(plugins, itemCtx);
|
|
551
88
|
}
|
|
552
89
|
|
|
553
|
-
/**
|
|
554
|
-
* This class will be removed!
|
|
555
|
-
* @deprecated use createProcessTelemetryContext() instead
|
|
556
|
-
*/
|
|
557
90
|
export class ProcessTelemetryContext implements IProcessTelemetryContext {
|
|
558
91
|
/**
|
|
559
92
|
* Gets the current core config instance
|
|
@@ -562,7 +95,7 @@ export class ProcessTelemetryContext implements IProcessTelemetryContext {
|
|
|
562
95
|
|
|
563
96
|
public getExtCfg: <T>(identifier:string, defaultValue?:T|any) => T;
|
|
564
97
|
|
|
565
|
-
public getConfig: (identifier:string, field: string, defaultValue?: number | string | boolean
|
|
98
|
+
public getConfig: (identifier:string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
|
|
566
99
|
|
|
567
100
|
/**
|
|
568
101
|
* Returns the IAppInsightsCore instance for the current request
|
|
@@ -596,42 +129,100 @@ export class ProcessTelemetryContext implements IProcessTelemetryContext {
|
|
|
596
129
|
* @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
|
|
597
130
|
* can optionally use this to access the current core instance or define / pass additional information
|
|
598
131
|
* to later plugins (vs appending items to the telemetry item)
|
|
599
|
-
* @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
|
|
600
132
|
*/
|
|
601
|
-
public processNext: (env: ITelemetryItem) =>
|
|
133
|
+
public processNext: (env: ITelemetryItem) => void;
|
|
602
134
|
|
|
603
|
-
/**
|
|
604
|
-
* Synchronously iterate over the context chain running the callback for each plugin, once
|
|
605
|
-
* every plugin has been executed via the callback, any associated onComplete will be called.
|
|
606
|
-
* @param callback - The function call for each plugin in the context chain
|
|
607
|
-
*/
|
|
608
|
-
public iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
|
|
609
|
-
|
|
610
135
|
/**
|
|
611
136
|
* Create a new context using the core and config from the current instance
|
|
612
|
-
* @param plugins - The execution order to process the plugins, if null or not supplied
|
|
613
|
-
* then the current execution order will be copied.
|
|
614
|
-
* @param startAt - The plugin to start processing from, if missing from the execution
|
|
615
|
-
* order then the next plugin will be NOT set.
|
|
616
137
|
*/
|
|
617
138
|
public createNew: (plugins?:IPlugin[]|ITelemetryPluginChain, startAt?:IPlugin) => IProcessTelemetryContext;
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* Set the function to call when the current chain has executed all processNext or unloadNext items.
|
|
621
|
-
*/
|
|
622
|
-
public onComplete: (onComplete: () => void) => void;
|
|
623
|
-
|
|
139
|
+
|
|
624
140
|
/**
|
|
625
141
|
* Creates a new Telemetry Item context with the current config, core and plugin execution chain
|
|
626
142
|
* @param plugins - The plugin instances that will be executed
|
|
627
143
|
* @param config - The current config
|
|
628
144
|
* @param core - The current core instance
|
|
629
145
|
*/
|
|
630
|
-
constructor(
|
|
146
|
+
constructor(plugins:IPlugin[]|ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?:IPlugin) {
|
|
631
147
|
let _self = this;
|
|
148
|
+
let _nextProxy: ITelemetryPluginChain = null; // Null == No next plugin
|
|
149
|
+
|
|
150
|
+
// There is no next element (null) vs not defined (undefined)
|
|
151
|
+
if (startAt !== null) {
|
|
152
|
+
if (plugins && isFunction((plugins as ITelemetryPluginChain).getPlugin)) {
|
|
153
|
+
// We have a proxy chain object
|
|
154
|
+
_nextProxy = _copyProxyChain(plugins as ITelemetryPluginChain, _self, startAt||(plugins as ITelemetryPluginChain).getPlugin());
|
|
155
|
+
} else {
|
|
156
|
+
// We just have an array
|
|
157
|
+
if (startAt) {
|
|
158
|
+
_nextProxy = _copyPluginChain(plugins as IPlugin[], _self, startAt);
|
|
159
|
+
} else if (isUndefined(startAt)) {
|
|
160
|
+
// Undefined means copy the existing chain
|
|
161
|
+
_nextProxy = _createProxyChain(plugins as IPlugin[], _self)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
632
165
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
166
|
+
_self.core = () => {
|
|
167
|
+
return core;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
_self.diagLog = () => {
|
|
171
|
+
return safeGetLogger(core, config);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
_self.getCfg = () => {
|
|
175
|
+
return config;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
_self.getExtCfg = <T>(identifier:string, defaultValue:T|any = {}) => {
|
|
179
|
+
let theConfig:T;
|
|
180
|
+
if (config) {
|
|
181
|
+
let extConfig = config.extensionConfig;
|
|
182
|
+
if (extConfig && identifier) {
|
|
183
|
+
theConfig = extConfig[identifier];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return (theConfig ? theConfig : defaultValue) as T;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
_self.getConfig = (identifier:string, field: string, defaultValue: number | string | boolean = false) => {
|
|
191
|
+
let theValue;
|
|
192
|
+
let extConfig = _self.getExtCfg(identifier, null);
|
|
193
|
+
if (extConfig && !isNullOrUndefined(extConfig[field])) {
|
|
194
|
+
theValue = extConfig[field];
|
|
195
|
+
} else if (config && !isNullOrUndefined(config[field])) {
|
|
196
|
+
theValue = config[field];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return !isNullOrUndefined(theValue) ? theValue : defaultValue;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
_self.hasNext = () => {
|
|
203
|
+
return _nextProxy != null;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
_self.getNext = () => {
|
|
207
|
+
return _nextProxy;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
_self.setNext = (nextPlugin:ITelemetryPluginChain) => {
|
|
211
|
+
_nextProxy = nextPlugin;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
_self.processNext = (env: ITelemetryItem) => {
|
|
215
|
+
let nextPlugin = _nextProxy;
|
|
216
|
+
|
|
217
|
+
if (nextPlugin) {
|
|
218
|
+
// Automatically move to the next plugin
|
|
219
|
+
_nextProxy = nextPlugin.getNext();
|
|
220
|
+
nextPlugin.processTelemetry(env, _self);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
_self.createNew = (plugins:IPlugin[]|ITelemetryPluginChain = null, startAt?:IPlugin) => {
|
|
225
|
+
return new ProcessTelemetryContext(plugins||_nextProxy, config, core, startAt);
|
|
226
|
+
}
|
|
636
227
|
}
|
|
637
228
|
}
|