@microsoft/applicationinsights-core-js 2.7.5-nightly.2203-01 → 2.8.0-beta.2203-01
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +860 -457
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +1193 -267
- package/dist/applicationinsights-core-js.api.md +54 -14
- package/dist/applicationinsights-core-js.d.ts +133 -45
- package/dist/applicationinsights-core-js.js +860 -457
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +133 -45
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +237 -82
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +45 -19
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +155 -87
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +2 -27
- package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +6 -6
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +51 -11
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +34 -36
- package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +289 -119
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +29 -4
- package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +2 -2
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +82 -0
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
- package/dist-esm/applicationinsights-core-js.js +4 -4
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +2 -2
- package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
- package/src/JavaScriptSDK/BaseCore.ts +330 -100
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +69 -32
- package/src/JavaScriptSDK/ChannelController.ts +175 -103
- package/src/JavaScriptSDK/CoreUtils.ts +1 -28
- package/src/JavaScriptSDK/EnvUtils.ts +5 -5
- package/src/JavaScriptSDK/HelperFuncs.ts +57 -14
- package/src/JavaScriptSDK/InstrumentHooks.ts +3 -1
- package/src/JavaScriptSDK/NotificationManager.ts +32 -31
- package/src/JavaScriptSDK/PerfManager.ts +1 -1
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +350 -133
- package/src/JavaScriptSDK/RandomHelper.ts +34 -3
- package/src/JavaScriptSDK/TelemetryHelpers.ts +4 -6
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +119 -0
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +17 -1
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +7 -3
- package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +5 -0
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +23 -5
- package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +1 -1
- package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
- package/types/JavaScriptSDK/BaseCore.d.ts +30 -1
- package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +13 -11
- package/types/JavaScriptSDK/ChannelController.d.ts +12 -17
- package/types/JavaScriptSDK/CoreUtils.d.ts +0 -6
- package/types/JavaScriptSDK/HelperFuncs.d.ts +14 -5
- package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +49 -3
- package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
- package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -3
- package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +23 -0
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +15 -0
- package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +7 -3
- package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +4 -0
- package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +18 -3
- package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
- package/types/applicationinsights-core-js.d.ts +5 -4
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
- package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
- package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { objCreateFn } from "@microsoft/applicationinsights-shims";
|
|
6
6
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
7
|
-
import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore"
|
|
7
|
+
import { IAppInsightsCore, ILoadedPlugin } from "../JavaScriptSDK.Interfaces/IAppInsightsCore"
|
|
8
8
|
import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
|
|
9
9
|
import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
|
|
10
10
|
import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
|
|
@@ -12,22 +12,24 @@ import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
|
|
|
12
12
|
import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
|
|
13
13
|
import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
|
|
14
14
|
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
|
|
15
|
-
import { ChannelController } from "./ChannelController";
|
|
16
15
|
import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
17
|
-
import {
|
|
16
|
+
import { createProcessTelemetryContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
|
|
18
17
|
import { initializePlugins, sortPlugins } from "./TelemetryHelpers";
|
|
19
|
-
import {
|
|
18
|
+
import { LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
20
19
|
import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
|
|
21
20
|
import { getGblPerfMgr, PerfManager } from "./PerfManager";
|
|
22
21
|
import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
|
|
23
22
|
import { createCookieMgr } from "./CookieMgr";
|
|
24
|
-
import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction } from "./HelperFuncs";
|
|
23
|
+
import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction, objFreeze, proxyFunctions } from "./HelperFuncs";
|
|
25
24
|
import { strExtensionConfig, strIKey } from "./Constants";
|
|
26
|
-
import { DiagnosticLogger } from "./DiagnosticLogger";
|
|
25
|
+
import { DiagnosticLogger, _InternalLogMessage } from "./DiagnosticLogger";
|
|
27
26
|
import { getDebugListener } from "./DbgExtensionUtils";
|
|
27
|
+
import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
|
|
28
|
+
import { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues, IChannelController, _IInternalChannels } from "./ChannelController";
|
|
29
|
+
import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
|
|
30
|
+
import { TelemetryInitializerPlugin } from "./TelemetryInitializerPlugin";
|
|
28
31
|
|
|
29
|
-
const
|
|
30
|
-
|
|
32
|
+
const strValidationError = "Plugins must provide initialize method";
|
|
31
33
|
const strNotificationManager = "_notificationManager";
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -39,6 +41,45 @@ function _createPerfManager (core: IAppInsightsCore, notificationMgr: INotificat
|
|
|
39
41
|
return new PerfManager(notificationMgr);
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
function _validateExtensions(logger: IDiagnosticLogger, channelPriority: number, allExtensions: IPlugin[]): { all: IPlugin[]; core: ITelemetryPlugin[] } {
|
|
45
|
+
// Concat all available extensions
|
|
46
|
+
let coreExtensions: ITelemetryPlugin[] = [];
|
|
47
|
+
|
|
48
|
+
// Check if any two extensions have the same priority, then warn to console
|
|
49
|
+
// And extract the local extensions from the
|
|
50
|
+
let extPriorities = {};
|
|
51
|
+
|
|
52
|
+
// Extension validation
|
|
53
|
+
arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
|
|
54
|
+
if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
|
|
55
|
+
throwError(strValidationError);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const extPriority = ext.priority;
|
|
59
|
+
const identifier = ext.identifier;
|
|
60
|
+
|
|
61
|
+
if (ext && extPriority) {
|
|
62
|
+
if (!isNullOrUndefined(extPriorities[extPriority])) {
|
|
63
|
+
logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
|
|
64
|
+
} else {
|
|
65
|
+
// set a value
|
|
66
|
+
extPriorities[extPriority] = identifier;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Split extensions to core and channelController
|
|
71
|
+
if (!extPriority || extPriority < channelPriority) {
|
|
72
|
+
// Add to core extension that will be managed by BaseCore
|
|
73
|
+
coreExtensions.push(ext);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
all: allExtensions,
|
|
79
|
+
core: coreExtensions
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
42
83
|
export class BaseCore implements IAppInsightsCore {
|
|
43
84
|
public static defaultConfig: IConfiguration;
|
|
44
85
|
public config: IConfiguration;
|
|
@@ -48,20 +89,33 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
48
89
|
public isInitialized: () => boolean;
|
|
49
90
|
|
|
50
91
|
constructor() {
|
|
51
|
-
|
|
92
|
+
// NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
|
|
93
|
+
let _isInitialized: boolean;
|
|
52
94
|
let _eventQueue: ITelemetryItem[];
|
|
53
|
-
let _channelController: ChannelController;
|
|
54
95
|
let _notificationManager: INotificationManager;
|
|
55
96
|
let _perfManager: IPerfManager;
|
|
97
|
+
let _cfgPerfManager: IPerfManager;
|
|
56
98
|
let _cookieManager: ICookieMgr;
|
|
57
|
-
|
|
99
|
+
let _pluginChain: ITelemetryPluginChain;
|
|
100
|
+
let _configExtensions: IPlugin[];
|
|
101
|
+
let _coreExtensions: ITelemetryPlugin[];
|
|
102
|
+
let _channelControl: IChannelController;
|
|
103
|
+
let _channelConfig: IChannelControls[][];
|
|
104
|
+
let _channelQueue: _IInternalChannels[];
|
|
105
|
+
let _telemetryInitializerPlugin: TelemetryInitializerPlugin;
|
|
106
|
+
let _internalLogsEventName: string;
|
|
107
|
+
let _debugListener: INotificationListener;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Internal log poller
|
|
111
|
+
*/
|
|
112
|
+
let _internalLogPoller: number = 0;
|
|
113
|
+
|
|
58
114
|
dynamicProto(BaseCore, this, (_self) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
_eventQueue = [];
|
|
115
|
+
|
|
116
|
+
// Set the default values (also called during teardown)
|
|
117
|
+
_initDefaults();
|
|
118
|
+
|
|
65
119
|
_self.isInitialized = () => _isInitialized;
|
|
66
120
|
|
|
67
121
|
_self.initialize = (config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void => {
|
|
@@ -69,7 +123,7 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
69
123
|
if (_self.isInitialized()) {
|
|
70
124
|
throwError("Core should not be initialized more than once");
|
|
71
125
|
}
|
|
72
|
-
|
|
126
|
+
|
|
73
127
|
if (!config || isNullOrUndefined(config.instrumentationKey)) {
|
|
74
128
|
throwError("Please provide instrumentation key");
|
|
75
129
|
}
|
|
@@ -80,14 +134,8 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
80
134
|
_self[strNotificationManager] = notificationManager;
|
|
81
135
|
_self.config = config || {};
|
|
82
136
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (_self.config.enablePerfMgr) {
|
|
88
|
-
// Set the performance manager creation function if not defined
|
|
89
|
-
setValue(_self.config, "createPerfMgr", _createPerfManager);
|
|
90
|
-
}
|
|
137
|
+
_initDebugListener(config);
|
|
138
|
+
_initPerfManager(config);
|
|
91
139
|
|
|
92
140
|
config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
|
|
93
141
|
|
|
@@ -99,63 +147,13 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
99
147
|
_self.logger = logger;
|
|
100
148
|
}
|
|
101
149
|
|
|
102
|
-
// Concat all available extensions
|
|
103
|
-
let allExtensions = [];
|
|
104
|
-
allExtensions.push(...extensions, ...config.extensions);
|
|
105
|
-
allExtensions = sortPlugins(allExtensions);
|
|
106
|
-
|
|
107
|
-
let coreExtensions: any[] = [];
|
|
108
|
-
let channelExtensions: any[] = [];
|
|
109
|
-
|
|
110
|
-
// Check if any two extensions have the same priority, then warn to console
|
|
111
|
-
// And extract the local extensions from the
|
|
112
|
-
const extPriorities = {};
|
|
113
|
-
|
|
114
150
|
// Extension validation
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const identifier = ext.identifier;
|
|
122
|
-
|
|
123
|
-
if (ext && extPriority) {
|
|
124
|
-
if (!isNullOrUndefined(extPriorities[extPriority])) {
|
|
125
|
-
logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
|
|
126
|
-
} else {
|
|
127
|
-
// set a value
|
|
128
|
-
extPriorities[extPriority] = identifier;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Split extensions to core and channelController
|
|
133
|
-
if (!extPriority || extPriority < _channelController.priority) {
|
|
134
|
-
// Add to core extension that will be managed by BaseCore
|
|
135
|
-
coreExtensions.push(ext);
|
|
136
|
-
} else {
|
|
137
|
-
// Add all other extensions to be managed by the channel controller
|
|
138
|
-
channelExtensions.push(ext);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
// Validation complete
|
|
142
|
-
|
|
143
|
-
// Add the channelController to the complete extension collection and
|
|
144
|
-
// to the end of the core extensions
|
|
145
|
-
allExtensions.push(_channelController);
|
|
146
|
-
coreExtensions.push(_channelController);
|
|
147
|
-
|
|
148
|
-
// Sort the complete set of extensions by priority
|
|
149
|
-
allExtensions = sortPlugins(allExtensions);
|
|
150
|
-
_self._extensions = allExtensions;
|
|
151
|
-
|
|
152
|
-
// initialize channel controller first, this will initialize all channel plugins
|
|
153
|
-
initializePlugins(new ProcessTelemetryContext([_channelController], config, _self), allExtensions);
|
|
154
|
-
initializePlugins(new ProcessTelemetryContext(coreExtensions, config, _self), allExtensions);
|
|
155
|
-
|
|
156
|
-
// Now reset the extensions to just those being managed by Basecore
|
|
157
|
-
_self._extensions = coreExtensions;
|
|
158
|
-
|
|
151
|
+
_configExtensions = [];
|
|
152
|
+
_configExtensions.push(...extensions, ...config.extensions);
|
|
153
|
+
_channelConfig = (config||{}).channels;
|
|
154
|
+
|
|
155
|
+
_initPluginChain(config);
|
|
156
|
+
|
|
159
157
|
if (_self.getTransmissionControls().length === 0) {
|
|
160
158
|
throwError("No channels available");
|
|
161
159
|
}
|
|
@@ -165,7 +163,12 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
165
163
|
};
|
|
166
164
|
|
|
167
165
|
_self.getTransmissionControls = (): IChannelControls[][] => {
|
|
168
|
-
|
|
166
|
+
let controls: IChannelControls[][] = [];
|
|
167
|
+
arrForEach(_channelQueue, (channels) => {
|
|
168
|
+
controls.push(channels.queue);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return objFreeze(controls);
|
|
169
172
|
};
|
|
170
173
|
|
|
171
174
|
_self.track = (telemetryItem: ITelemetryItem) => {
|
|
@@ -188,16 +191,7 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
188
191
|
};
|
|
189
192
|
|
|
190
193
|
_self.getProcessTelContext = (): IProcessTelemetryContext => {
|
|
191
|
-
|
|
192
|
-
let thePlugins: IPlugin[] = extensions;
|
|
193
|
-
|
|
194
|
-
// invoke any common telemetry processors before sending through pipeline
|
|
195
|
-
if (!extensions || extensions.length === 0) {
|
|
196
|
-
// Pass to Channel controller so data is sent to correct channel queues
|
|
197
|
-
thePlugins = [_channelController];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return new ProcessTelemetryContext(thePlugins, _self.config, _self);
|
|
194
|
+
return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
|
|
201
195
|
};
|
|
202
196
|
|
|
203
197
|
_self.getNotifyMgr = (): INotificationManager => {
|
|
@@ -217,6 +211,28 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
217
211
|
|
|
218
212
|
return _notificationManager;
|
|
219
213
|
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
|
|
217
|
+
* The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
|
|
218
|
+
* called.
|
|
219
|
+
* @param {INotificationListener} listener - An INotificationListener object.
|
|
220
|
+
*/
|
|
221
|
+
_self.addNotificationListener = (listener: INotificationListener): void => {
|
|
222
|
+
if (_notificationManager) {
|
|
223
|
+
_notificationManager.addNotificationListener(listener);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Removes all instances of the listener.
|
|
229
|
+
* @param {INotificationListener} listener - INotificationListener to remove.
|
|
230
|
+
*/
|
|
231
|
+
_self.removeNotificationListener = (listener: INotificationListener): void => {
|
|
232
|
+
if (_notificationManager) {
|
|
233
|
+
_notificationManager.removeNotificationListener(listener);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
220
236
|
|
|
221
237
|
_self.getCookieMgr = (): ICookieMgr => {
|
|
222
238
|
if (!_cookieManager) {
|
|
@@ -231,13 +247,13 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
231
247
|
};
|
|
232
248
|
|
|
233
249
|
_self.getPerfMgr = (): IPerfManager => {
|
|
234
|
-
if (!_perfManager) {
|
|
250
|
+
if (!_perfManager && !_cfgPerfManager) {
|
|
235
251
|
if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
|
|
236
|
-
|
|
252
|
+
_cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
|
|
240
|
-
return _perfManager || getGblPerfMgr();
|
|
256
|
+
return _perfManager || _cfgPerfManager || getGblPerfMgr();
|
|
241
257
|
};
|
|
242
258
|
|
|
243
259
|
_self.setPerfMgr = (perfMgr: IPerfManager) => {
|
|
@@ -249,14 +265,182 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
249
265
|
};
|
|
250
266
|
|
|
251
267
|
_self.releaseQueue = () => {
|
|
252
|
-
if (_eventQueue.length > 0) {
|
|
253
|
-
|
|
268
|
+
if (_isInitialized && _eventQueue.length > 0) {
|
|
269
|
+
let eventQueue = _eventQueue;
|
|
270
|
+
_eventQueue = [];
|
|
271
|
+
|
|
272
|
+
arrForEach(eventQueue, (event: ITelemetryItem) => {
|
|
254
273
|
_self.getProcessTelContext().processNext(event);
|
|
255
274
|
});
|
|
256
|
-
|
|
257
|
-
_eventQueue = [];
|
|
258
275
|
}
|
|
259
276
|
};
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Periodically check logger.queue for log messages to be flushed
|
|
280
|
+
*/
|
|
281
|
+
_self.pollInternalLogs = (eventName?: string): number => {
|
|
282
|
+
_internalLogsEventName = eventName;
|
|
283
|
+
|
|
284
|
+
let interval = _self.config.diagnosticLogInterval;
|
|
285
|
+
if (!interval || !(interval > 0)) {
|
|
286
|
+
interval = 10000;
|
|
287
|
+
}
|
|
288
|
+
if(_internalLogPoller) {
|
|
289
|
+
clearInterval(_internalLogPoller);
|
|
290
|
+
}
|
|
291
|
+
_internalLogPoller = setInterval(() => {
|
|
292
|
+
_flushInternalLogs();
|
|
293
|
+
}, interval) as any;
|
|
294
|
+
|
|
295
|
+
return _internalLogPoller;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Stop polling log messages from logger.queue
|
|
300
|
+
*/
|
|
301
|
+
_self.stopPollingInternalLogs = (): void => {
|
|
302
|
+
if(_internalLogPoller) {
|
|
303
|
+
clearInterval(_internalLogPoller);
|
|
304
|
+
_internalLogPoller = 0;
|
|
305
|
+
_flushInternalLogs();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Add addTelemetryInitializer
|
|
310
|
+
proxyFunctions(_self, () => _telemetryInitializerPlugin, [ "addTelemetryInitializer" ]);
|
|
311
|
+
|
|
312
|
+
_self.getPlugin = _getPlugin;
|
|
313
|
+
|
|
314
|
+
function _initDefaults() {
|
|
315
|
+
_isInitialized = false;
|
|
316
|
+
|
|
317
|
+
// Use a default logger so initialization errors are not dropped on the floor with full logging
|
|
318
|
+
_self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
|
|
319
|
+
_self.config = null;
|
|
320
|
+
_self._extensions = [];
|
|
321
|
+
|
|
322
|
+
_telemetryInitializerPlugin = new TelemetryInitializerPlugin();
|
|
323
|
+
_eventQueue = [];
|
|
324
|
+
_notificationManager = null;
|
|
325
|
+
_perfManager = null;
|
|
326
|
+
_cfgPerfManager = null;
|
|
327
|
+
_cookieManager = null;
|
|
328
|
+
_pluginChain = null;
|
|
329
|
+
_coreExtensions = null;
|
|
330
|
+
_configExtensions = null;
|
|
331
|
+
_channelControl = null;
|
|
332
|
+
_channelConfig = null;
|
|
333
|
+
_channelQueue = null;
|
|
334
|
+
_internalLogsEventName = null;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Initialize or Re-initialize the plugins
|
|
338
|
+
function _initPluginChain(config: IConfiguration) {
|
|
339
|
+
// Extension validation
|
|
340
|
+
let theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
|
|
341
|
+
|
|
342
|
+
_coreExtensions = theExtensions.core;
|
|
343
|
+
_pluginChain = null;
|
|
344
|
+
|
|
345
|
+
// Sort the complete set of extensions by priority
|
|
346
|
+
let allExtensions = theExtensions.all;
|
|
347
|
+
|
|
348
|
+
// Initialize the Channel Queues and the channel plugins first
|
|
349
|
+
_channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
|
|
350
|
+
_channelControl = createChannelControllerPlugin(_channelQueue, _self);
|
|
351
|
+
|
|
352
|
+
// Add on "channelController" as the last "plugin"
|
|
353
|
+
allExtensions.push(_channelControl);
|
|
354
|
+
_coreExtensions.push(_channelControl);
|
|
355
|
+
|
|
356
|
+
// Required to allow plugins to call core.getPlugin() during their own initialization
|
|
357
|
+
_self._extensions = sortPlugins(allExtensions);
|
|
358
|
+
|
|
359
|
+
// Initialize the controls
|
|
360
|
+
_channelControl.initialize(config, _self, allExtensions);
|
|
361
|
+
|
|
362
|
+
initializePlugins(_self.getProcessTelContext(), allExtensions);
|
|
363
|
+
|
|
364
|
+
// Now reset the extensions to just those being managed by Basecore
|
|
365
|
+
_self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function _getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
|
|
369
|
+
let theExt: ILoadedPlugin<T> = null;
|
|
370
|
+
let thePlugin: IPlugin = null;
|
|
371
|
+
|
|
372
|
+
arrForEach(_self._extensions, (ext: any) => {
|
|
373
|
+
if (ext.identifier === pluginIdentifier) {
|
|
374
|
+
thePlugin = ext;
|
|
375
|
+
return -1;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
if (thePlugin) {
|
|
380
|
+
theExt = {
|
|
381
|
+
plugin: thePlugin as T
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return theExt;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function _getPluginChain() {
|
|
389
|
+
if (!_pluginChain) {
|
|
390
|
+
// copy the collection of extensions
|
|
391
|
+
let extensions = (_coreExtensions || []).slice();
|
|
392
|
+
|
|
393
|
+
extensions.push(_telemetryInitializerPlugin);
|
|
394
|
+
|
|
395
|
+
_pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return _pluginChain;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function _flushInternalLogs() {
|
|
402
|
+
let queue: _InternalLogMessage[] = _self.logger ? _self.logger.queue : [];
|
|
403
|
+
if (queue) {
|
|
404
|
+
arrForEach(queue, (logMessage: _InternalLogMessage) => {
|
|
405
|
+
const item: ITelemetryItem = {
|
|
406
|
+
name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
|
|
407
|
+
iKey: _self.config.instrumentationKey,
|
|
408
|
+
time: toISOString(new Date()),
|
|
409
|
+
baseType: _InternalLogMessage.dataType,
|
|
410
|
+
baseData: { message: logMessage.message }
|
|
411
|
+
};
|
|
412
|
+
_self.track(item);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
queue.length = 0;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function _initDebugListener(config: IConfiguration) {
|
|
420
|
+
|
|
421
|
+
if (config.disableDbgExt === true && _debugListener) {
|
|
422
|
+
// Remove any previously loaded debug listener
|
|
423
|
+
_notificationManager.removeNotificationListener(_debugListener);
|
|
424
|
+
_debugListener = null;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
|
|
428
|
+
_debugListener = getDebugListener(config);
|
|
429
|
+
_notificationManager.addNotificationListener(_debugListener);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function _initPerfManager(config: IConfiguration) {
|
|
434
|
+
if (!config.enablePerfMgr && _cfgPerfManager) {
|
|
435
|
+
// Remove any existing config based performance manager
|
|
436
|
+
_cfgPerfManager = null;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (config.enablePerfMgr) {
|
|
440
|
+
// Set the performance manager creation function if not defined
|
|
441
|
+
setValue(_self.config, "createPerfMgr", _createPerfManager);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
260
444
|
});
|
|
261
445
|
}
|
|
262
446
|
|
|
@@ -283,6 +467,24 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
283
467
|
return null;
|
|
284
468
|
}
|
|
285
469
|
|
|
470
|
+
/**
|
|
471
|
+
* Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
|
|
472
|
+
* The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
|
|
473
|
+
* called.
|
|
474
|
+
* @param {INotificationListener} listener - An INotificationListener object.
|
|
475
|
+
*/
|
|
476
|
+
public addNotificationListener(listener: INotificationListener): void {
|
|
477
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Removes all instances of the listener.
|
|
482
|
+
* @param {INotificationListener} listener - INotificationListener to remove.
|
|
483
|
+
*/
|
|
484
|
+
public removeNotificationListener(listener: INotificationListener): void {
|
|
485
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
486
|
+
}
|
|
487
|
+
|
|
286
488
|
/**
|
|
287
489
|
* Get the current cookie manager for this instance
|
|
288
490
|
*/
|
|
@@ -313,6 +515,34 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
313
515
|
return 0;
|
|
314
516
|
}
|
|
315
517
|
|
|
518
|
+
/**
|
|
519
|
+
* Periodically check logger.queue for
|
|
520
|
+
*/
|
|
521
|
+
public pollInternalLogs(eventName?: string): number {
|
|
522
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
523
|
+
return 0;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Periodically check logger.queue for
|
|
528
|
+
*/
|
|
529
|
+
public stopPollingInternalLogs(): void {
|
|
530
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Add a telemetry processor to decorate or drop telemetry events.
|
|
535
|
+
* @param telemetryInitializer - The Telemetry Initializer function
|
|
536
|
+
* @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
|
|
537
|
+
*/
|
|
538
|
+
public addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void {
|
|
539
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
public getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
|
|
543
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
316
546
|
protected releaseQueue() {
|
|
317
547
|
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
318
548
|
}
|