@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
|
@@ -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
|
|
7
|
+
import { IAppInsightsCore } 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,36 +12,23 @@ 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 {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
15
|
+
import { ChannelController } from "./ChannelController";
|
|
16
|
+
import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
17
|
+
import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
|
|
18
|
+
import { initializePlugins, sortPlugins } from "./TelemetryHelpers";
|
|
19
|
+
import { _InternalMessageId, LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
19
20
|
import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
|
|
20
21
|
import { getGblPerfMgr, PerfManager } from "./PerfManager";
|
|
21
22
|
import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
|
|
22
23
|
import { createCookieMgr } from "./CookieMgr";
|
|
23
|
-
import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction
|
|
24
|
+
import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction } from "./HelperFuncs";
|
|
24
25
|
import { strExtensionConfig, strIKey } from "./Constants";
|
|
25
|
-
import { DiagnosticLogger
|
|
26
|
+
import { DiagnosticLogger } from "./DiagnosticLogger";
|
|
26
27
|
import { getDebugListener } from "./DbgExtensionUtils";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
import { TelemetryInitializerPlugin } from "./TelemetryInitializerPlugin";
|
|
31
|
-
import { createUniqueNamespace } from "./DataCacheHelper";
|
|
32
|
-
import { createUnloadHandlerContainer, IUnloadHandlerContainer, UnloadHandler } from "./UnloadHandlerContainer";
|
|
33
|
-
import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
|
|
34
|
-
import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
|
|
35
|
-
import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
36
|
-
import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
|
|
37
|
-
import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
|
|
38
|
-
import { strAddNotificationListener, strDisabled, strEventsDiscarded, strEventsSendRequest, strEventsSent, strRemoveNotificationListener, strTeardown } from "./InternalConstants";
|
|
39
|
-
|
|
40
|
-
const strValidationError = "Plugins must provide initialize method";
|
|
28
|
+
|
|
29
|
+
const validationError = "Extensions must provide callback to initialize";
|
|
30
|
+
|
|
41
31
|
const strNotificationManager = "_notificationManager";
|
|
42
|
-
const strSdkUnloadingError = "SDK is still unloading...";
|
|
43
|
-
const strSdkNotInitialized = "SDK is not initialized";
|
|
44
|
-
// const strPluginUnloadFailed = "Failed to unload plugin";
|
|
45
32
|
|
|
46
33
|
/**
|
|
47
34
|
* Helper to create the default performance manager
|
|
@@ -52,68 +39,6 @@ function _createPerfManager (core: IAppInsightsCore, notificationMgr: INotificat
|
|
|
52
39
|
return new PerfManager(notificationMgr);
|
|
53
40
|
}
|
|
54
41
|
|
|
55
|
-
function _validateExtensions(logger: IDiagnosticLogger, channelPriority: number, allExtensions: IPlugin[]): { all: IPlugin[]; core: ITelemetryPlugin[] } {
|
|
56
|
-
// Concat all available extensions
|
|
57
|
-
let coreExtensions: ITelemetryPlugin[] = [];
|
|
58
|
-
|
|
59
|
-
// Check if any two extensions have the same priority, then warn to console
|
|
60
|
-
// And extract the local extensions from the
|
|
61
|
-
let extPriorities = {};
|
|
62
|
-
|
|
63
|
-
// Extension validation
|
|
64
|
-
arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
|
|
65
|
-
if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
|
|
66
|
-
throwError(strValidationError);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const extPriority = ext.priority;
|
|
70
|
-
const identifier = ext.identifier;
|
|
71
|
-
|
|
72
|
-
if (ext && extPriority) {
|
|
73
|
-
if (!isNullOrUndefined(extPriorities[extPriority])) {
|
|
74
|
-
logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
|
|
75
|
-
} else {
|
|
76
|
-
// set a value
|
|
77
|
-
extPriorities[extPriority] = identifier;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Split extensions to core and channelController
|
|
82
|
-
if (!extPriority || extPriority < channelPriority) {
|
|
83
|
-
// Add to core extension that will be managed by BaseCore
|
|
84
|
-
coreExtensions.push(ext);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
all: allExtensions,
|
|
90
|
-
core: coreExtensions
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function _isPluginPresent(thePlugin: IPlugin, plugins: IPlugin[]) {
|
|
95
|
-
let exists = false;
|
|
96
|
-
|
|
97
|
-
arrForEach(plugins, (plugin) => {
|
|
98
|
-
if (plugin === thePlugin) {
|
|
99
|
-
exists = true;
|
|
100
|
-
return -1;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return exists;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function _createDummyNotificationManager(): INotificationManager {
|
|
108
|
-
return objCreateFn({
|
|
109
|
-
[strAddNotificationListener]: (listener: INotificationListener) => { },
|
|
110
|
-
[strRemoveNotificationListener]: (listener: INotificationListener) => { },
|
|
111
|
-
[strEventsSent]: (events: ITelemetryItem[]) => { },
|
|
112
|
-
[strEventsDiscarded]: (events: ITelemetryItem[], reason: number) => { },
|
|
113
|
-
[strEventsSendRequest]: (sendReason: number, isAsync: boolean) => { }
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
42
|
export class BaseCore implements IAppInsightsCore {
|
|
118
43
|
public static defaultConfig: IConfiguration;
|
|
119
44
|
public config: IConfiguration;
|
|
@@ -123,48 +48,28 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
123
48
|
public isInitialized: () => boolean;
|
|
124
49
|
|
|
125
50
|
constructor() {
|
|
126
|
-
|
|
127
|
-
let _isInitialized: boolean;
|
|
51
|
+
let _isInitialized = false;
|
|
128
52
|
let _eventQueue: ITelemetryItem[];
|
|
129
|
-
let
|
|
130
|
-
let
|
|
131
|
-
let
|
|
132
|
-
let _cookieManager: ICookieMgr
|
|
133
|
-
|
|
134
|
-
let _configExtensions: IPlugin[];
|
|
135
|
-
let _coreExtensions: ITelemetryPlugin[] | null;
|
|
136
|
-
let _channelControl: IChannelController | null;
|
|
137
|
-
let _channelConfig: IChannelControls[][] | null | undefined;
|
|
138
|
-
let _channelQueue: _IInternalChannels[] | null;
|
|
139
|
-
let _isUnloading: boolean;
|
|
140
|
-
let _telemetryInitializerPlugin: TelemetryInitializerPlugin;
|
|
141
|
-
let _internalLogsEventName: string | null;
|
|
142
|
-
let _evtNamespace: string;
|
|
143
|
-
let _unloadHandlers: IUnloadHandlerContainer;
|
|
144
|
-
let _debugListener: INotificationListener | null;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Internal log poller
|
|
148
|
-
*/
|
|
149
|
-
let _internalLogPoller: number = 0;
|
|
150
|
-
|
|
53
|
+
let _channelController: ChannelController;
|
|
54
|
+
let _notificationManager: INotificationManager;
|
|
55
|
+
let _perfManager: IPerfManager;
|
|
56
|
+
let _cookieManager: ICookieMgr;
|
|
57
|
+
|
|
151
58
|
dynamicProto(BaseCore, this, (_self) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
59
|
+
_self._extensions = new Array<IPlugin>();
|
|
60
|
+
_channelController = new ChannelController();
|
|
61
|
+
// Use a default logger so initialization errors are not dropped on the floor with full logging
|
|
62
|
+
_self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
|
|
63
|
+
|
|
64
|
+
_eventQueue = [];
|
|
156
65
|
_self.isInitialized = () => _isInitialized;
|
|
157
66
|
|
|
158
67
|
_self.initialize = (config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void => {
|
|
159
|
-
if (_isUnloading) {
|
|
160
|
-
throwError(strSdkUnloadingError);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
68
|
// Make sure core is only initialized once
|
|
164
69
|
if (_self.isInitialized()) {
|
|
165
70
|
throwError("Core should not be initialized more than once");
|
|
166
71
|
}
|
|
167
|
-
|
|
72
|
+
|
|
168
73
|
if (!config || isNullOrUndefined(config.instrumentationKey)) {
|
|
169
74
|
throwError("Please provide instrumentation key");
|
|
170
75
|
}
|
|
@@ -175,26 +80,83 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
175
80
|
_self[strNotificationManager] = notificationManager;
|
|
176
81
|
_self.config = config || {};
|
|
177
82
|
|
|
178
|
-
|
|
179
|
-
|
|
83
|
+
if (notificationManager && _self.config.disableDbgExt !== true) {
|
|
84
|
+
notificationManager.addNotificationListener(getDebugListener(config));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (_self.config.enablePerfMgr) {
|
|
88
|
+
// Set the performance manager creation function if not defined
|
|
89
|
+
setValue(_self.config, "createPerfMgr", _createPerfManager);
|
|
90
|
+
}
|
|
180
91
|
|
|
181
92
|
config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
|
|
182
93
|
|
|
183
94
|
// add notification to the extensions in the config so other plugins can access it
|
|
184
|
-
|
|
95
|
+
let extConfig = getSetValue(config, strExtensionConfig);
|
|
96
|
+
extConfig.NotificationManager = notificationManager;
|
|
185
97
|
|
|
186
98
|
if (logger) {
|
|
187
99
|
_self.logger = logger;
|
|
188
100
|
}
|
|
189
101
|
|
|
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
|
+
|
|
190
114
|
// Extension validation
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
115
|
+
arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
|
|
116
|
+
if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
|
|
117
|
+
throwError(validationError);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const extPriority = ext.priority;
|
|
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
|
+
|
|
159
|
+
if (_self.getTransmissionControls().length === 0) {
|
|
198
160
|
throwError("No channels available");
|
|
199
161
|
}
|
|
200
162
|
|
|
@@ -203,14 +165,7 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
203
165
|
};
|
|
204
166
|
|
|
205
167
|
_self.getTransmissionControls = (): IChannelControls[][] => {
|
|
206
|
-
|
|
207
|
-
if (_channelQueue) {
|
|
208
|
-
arrForEach(_channelQueue, (channels) => {
|
|
209
|
-
controls.push(channels.queue);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return objFreeze(controls);
|
|
168
|
+
return _channelController.getChannelControls();
|
|
214
169
|
};
|
|
215
170
|
|
|
216
171
|
_self.track = (telemetryItem: ITelemetryItem) => {
|
|
@@ -223,21 +178,38 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
223
178
|
// Common Schema 4.0
|
|
224
179
|
setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
|
|
225
180
|
|
|
226
|
-
if (
|
|
181
|
+
if (_self.isInitialized()) {
|
|
227
182
|
// Process the telemetry plugin chain
|
|
228
|
-
|
|
183
|
+
_self.getProcessTelContext().processNext(telemetryItem);
|
|
229
184
|
} else {
|
|
230
185
|
// Queue events until all extensions are initialized
|
|
231
186
|
_eventQueue.push(telemetryItem);
|
|
232
187
|
}
|
|
233
188
|
};
|
|
234
189
|
|
|
235
|
-
_self.getProcessTelContext =
|
|
190
|
+
_self.getProcessTelContext = (): IProcessTelemetryContext => {
|
|
191
|
+
let extensions = _self._extensions;
|
|
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);
|
|
201
|
+
};
|
|
236
202
|
|
|
237
203
|
_self.getNotifyMgr = (): INotificationManager => {
|
|
238
204
|
if (!_notificationManager) {
|
|
239
205
|
// Create Dummy notification manager
|
|
240
|
-
_notificationManager =
|
|
206
|
+
_notificationManager = objCreateFn({
|
|
207
|
+
addNotificationListener: (listener: INotificationListener) => { },
|
|
208
|
+
removeNotificationListener: (listener: INotificationListener) => { },
|
|
209
|
+
eventsSent: (events: ITelemetryItem[]) => { },
|
|
210
|
+
eventsDiscarded: (events: ITelemetryItem[], reason: number) => { },
|
|
211
|
+
eventsSendRequest: (sendReason: number, isAsync: boolean) => { }
|
|
212
|
+
});
|
|
241
213
|
|
|
242
214
|
// For backward compatibility only
|
|
243
215
|
_self[strNotificationManager] = _notificationManager;
|
|
@@ -245,28 +217,6 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
245
217
|
|
|
246
218
|
return _notificationManager;
|
|
247
219
|
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
|
|
251
|
-
* The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
|
|
252
|
-
* called.
|
|
253
|
-
* @param {INotificationListener} listener - An INotificationListener object.
|
|
254
|
-
*/
|
|
255
|
-
_self[strAddNotificationListener] = (listener: INotificationListener): void => {
|
|
256
|
-
if (_notificationManager) {
|
|
257
|
-
_notificationManager[strAddNotificationListener](listener);
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Removes all instances of the listener.
|
|
263
|
-
* @param {INotificationListener} listener - INotificationListener to remove.
|
|
264
|
-
*/
|
|
265
|
-
_self[strRemoveNotificationListener] = (listener: INotificationListener): void => {
|
|
266
|
-
if (_notificationManager) {
|
|
267
|
-
_notificationManager[strRemoveNotificationListener](listener);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
220
|
|
|
271
221
|
_self.getCookieMgr = (): ICookieMgr => {
|
|
272
222
|
if (!_cookieManager) {
|
|
@@ -281,13 +231,13 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
281
231
|
};
|
|
282
232
|
|
|
283
233
|
_self.getPerfMgr = (): IPerfManager => {
|
|
284
|
-
if (!_perfManager
|
|
234
|
+
if (!_perfManager) {
|
|
285
235
|
if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {
|
|
286
|
-
|
|
236
|
+
_perfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());
|
|
287
237
|
}
|
|
288
238
|
}
|
|
289
239
|
|
|
290
|
-
return _perfManager ||
|
|
240
|
+
return _perfManager || getGblPerfMgr();
|
|
291
241
|
};
|
|
292
242
|
|
|
293
243
|
_self.setPerfMgr = (perfMgr: IPerfManager) => {
|
|
@@ -299,428 +249,14 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
299
249
|
};
|
|
300
250
|
|
|
301
251
|
_self.releaseQueue = () => {
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
arrForEach(eventQueue, (event: ITelemetryItem) => {
|
|
307
|
-
_createTelCtx().processNext(event);
|
|
252
|
+
if (_eventQueue.length > 0) {
|
|
253
|
+
arrForEach(_eventQueue, (event: ITelemetryItem) => {
|
|
254
|
+
_self.getProcessTelContext().processNext(event);
|
|
308
255
|
});
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Periodically check logger.queue for log messages to be flushed
|
|
314
|
-
*/
|
|
315
|
-
_self.pollInternalLogs = (eventName?: string): number => {
|
|
316
|
-
_internalLogsEventName = eventName || null;
|
|
317
|
-
|
|
318
|
-
let interval = _self.config.diagnosticLogInterval;
|
|
319
|
-
if (!interval || !(interval > 0)) {
|
|
320
|
-
interval = 10000;
|
|
321
|
-
}
|
|
322
|
-
if(_internalLogPoller) {
|
|
323
|
-
clearInterval(_internalLogPoller);
|
|
324
|
-
}
|
|
325
|
-
_internalLogPoller = setInterval(() => {
|
|
326
|
-
_flushInternalLogs();
|
|
327
|
-
}, interval) as any;
|
|
328
|
-
|
|
329
|
-
return _internalLogPoller;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Stop polling log messages from logger.queue
|
|
334
|
-
*/
|
|
335
|
-
_self.stopPollingInternalLogs = (): void => {
|
|
336
|
-
if(_internalLogPoller) {
|
|
337
|
-
clearInterval(_internalLogPoller);
|
|
338
|
-
_internalLogPoller = 0;
|
|
339
|
-
_flushInternalLogs();
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// Add addTelemetryInitializer
|
|
344
|
-
proxyFunctions(_self, () => _telemetryInitializerPlugin, [ "addTelemetryInitializer" ]);
|
|
345
|
-
|
|
346
|
-
_self.unload = (isAsync: boolean = true, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void => {
|
|
347
|
-
if (!_isInitialized) {
|
|
348
|
-
// The SDK is not initialized
|
|
349
|
-
throwError(strSdkNotInitialized);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Check if the SDK still unloading so throw
|
|
353
|
-
if (_isUnloading) {
|
|
354
|
-
// The SDK is already unloading
|
|
355
|
-
throwError(strSdkUnloadingError);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
let unloadState: ITelemetryUnloadState = {
|
|
359
|
-
reason: TelemetryUnloadReason.SdkUnload,
|
|
360
|
-
isAsync: isAsync,
|
|
361
|
-
flushComplete: false
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
let processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
|
|
365
|
-
processUnloadCtx.onComplete(() => {
|
|
366
|
-
_initDefaults();
|
|
367
|
-
unloadComplete && unloadComplete(unloadState);
|
|
368
|
-
}, _self);
|
|
369
|
-
|
|
370
|
-
function _doUnload(flushComplete: boolean) {
|
|
371
|
-
unloadState.flushComplete = flushComplete;
|
|
372
|
-
_isUnloading = true;
|
|
373
|
-
|
|
374
|
-
// Run all of the unload handlers first (before unloading the plugins)
|
|
375
|
-
_unloadHandlers.run(processUnloadCtx, unloadState);
|
|
376
|
-
|
|
377
|
-
// Stop polling the internal logs
|
|
378
|
-
_self.stopPollingInternalLogs();
|
|
379
|
-
|
|
380
|
-
// Start unloading the components, from this point onwards the SDK should be considered to be in an unstable state
|
|
381
|
-
processUnloadCtx.processNext(unloadState);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (!_flushChannels(isAsync, _doUnload, SendRequestReason.SdkUnload, cbTimeout)) {
|
|
385
|
-
_doUnload(false);
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
_self.getPlugin = _getPlugin;
|
|
390
|
-
|
|
391
|
-
_self.addPlugin = <T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, isAsync?: boolean, addCb?: (added?: boolean) => void): void => {
|
|
392
|
-
if (!plugin) {
|
|
393
|
-
addCb && addCb(false);
|
|
394
|
-
_logOrThrowError(strValidationError);
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
let existingPlugin = _getPlugin(plugin.identifier);
|
|
399
|
-
if (existingPlugin && !replaceExisting) {
|
|
400
|
-
addCb && addCb(false);
|
|
401
256
|
|
|
402
|
-
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
let updateState: ITelemetryUpdateState = {
|
|
407
|
-
reason: TelemetryUpdateReason.PluginAdded
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
function _addPlugin(removed: boolean) {
|
|
411
|
-
_configExtensions.push(plugin);
|
|
412
|
-
updateState.added = [plugin];
|
|
413
|
-
|
|
414
|
-
// Re-Initialize the plugin chain
|
|
415
|
-
_initPluginChain(_self.config, updateState);
|
|
416
|
-
addCb && addCb(true);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (existingPlugin) {
|
|
420
|
-
let removedPlugins: IPlugin[] = [existingPlugin.plugin];
|
|
421
|
-
let unloadState: ITelemetryUnloadState = {
|
|
422
|
-
reason: TelemetryUnloadReason.PluginReplace,
|
|
423
|
-
isAsync: !!isAsync
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
_removePlugins(removedPlugins, unloadState, (removed) => {
|
|
427
|
-
if (!removed) {
|
|
428
|
-
// Previous plugin was successfully removed or was not installed
|
|
429
|
-
addCb && addCb(false);
|
|
430
|
-
} else {
|
|
431
|
-
updateState.removed = removedPlugins
|
|
432
|
-
updateState.reason |= TelemetryUpdateReason.PluginRemoved;
|
|
433
|
-
_addPlugin(true);
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
} else {
|
|
437
|
-
_addPlugin(false);
|
|
257
|
+
_eventQueue = [];
|
|
438
258
|
}
|
|
439
259
|
};
|
|
440
|
-
|
|
441
|
-
_self.evtNamespace = (): string => {
|
|
442
|
-
return _evtNamespace;
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
_self.flush = _flushChannels;
|
|
446
|
-
|
|
447
|
-
// Create the addUnloadCb
|
|
448
|
-
proxyFunctionAs(_self, "addUnloadCb", () => _unloadHandlers, "add");
|
|
449
|
-
|
|
450
|
-
function _initDefaults() {
|
|
451
|
-
_isInitialized = false;
|
|
452
|
-
|
|
453
|
-
// Use a default logger so initialization errors are not dropped on the floor with full logging
|
|
454
|
-
_self.logger = new DiagnosticLogger({ loggingLevelConsole: eLoggingSeverity.CRITICAL });
|
|
455
|
-
_self.config = {};
|
|
456
|
-
_self._extensions = [];
|
|
457
|
-
|
|
458
|
-
_telemetryInitializerPlugin = new TelemetryInitializerPlugin();
|
|
459
|
-
_eventQueue = [];
|
|
460
|
-
_notificationManager = null;
|
|
461
|
-
_perfManager = null;
|
|
462
|
-
_cfgPerfManager = null;
|
|
463
|
-
_cookieManager = null;
|
|
464
|
-
_pluginChain = null;
|
|
465
|
-
_coreExtensions = null;
|
|
466
|
-
_configExtensions = [];
|
|
467
|
-
_channelControl = null;
|
|
468
|
-
_channelConfig = null;
|
|
469
|
-
_channelQueue = null;
|
|
470
|
-
_isUnloading = false;
|
|
471
|
-
_internalLogsEventName = null;
|
|
472
|
-
_evtNamespace = createUniqueNamespace("AIBaseCore", true);
|
|
473
|
-
_unloadHandlers = createUnloadHandlerContainer();
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function _createTelCtx(): IProcessTelemetryContext {
|
|
477
|
-
return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Initialize or Re-initialize the plugins
|
|
481
|
-
function _initPluginChain(config: IConfiguration, updateState: ITelemetryUpdateState | null) {
|
|
482
|
-
// Extension validation
|
|
483
|
-
let theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
|
|
484
|
-
|
|
485
|
-
_coreExtensions = theExtensions.core;
|
|
486
|
-
_pluginChain = null;
|
|
487
|
-
|
|
488
|
-
// Sort the complete set of extensions by priority
|
|
489
|
-
let allExtensions = theExtensions.all;
|
|
490
|
-
|
|
491
|
-
// Initialize the Channel Queues and the channel plugins first
|
|
492
|
-
_channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
|
|
493
|
-
if (_channelControl) {
|
|
494
|
-
// During add / remove of a plugin this may get called again, so don't re-add if already present
|
|
495
|
-
// But we also want the controller as the last, so remove if already present
|
|
496
|
-
// And reusing the existing instance, just in case an installed plugin has a reference and
|
|
497
|
-
// is using it.
|
|
498
|
-
let idx = allExtensions.indexOf(_channelControl);
|
|
499
|
-
if (idx !== -1) {
|
|
500
|
-
allExtensions.splice(idx, 1);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
idx = _coreExtensions.indexOf(_channelControl);
|
|
504
|
-
if (idx !== -1) {
|
|
505
|
-
_coreExtensions.splice(idx, 1);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
(_channelControl as IInternalChannelController)._setQueue(_channelQueue);
|
|
509
|
-
} else {
|
|
510
|
-
_channelControl = createChannelControllerPlugin(_channelQueue, _self);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// Add on "channelController" as the last "plugin"
|
|
514
|
-
allExtensions.push(_channelControl);
|
|
515
|
-
_coreExtensions.push(_channelControl);
|
|
516
|
-
|
|
517
|
-
// Required to allow plugins to call core.getPlugin() during their own initialization
|
|
518
|
-
_self._extensions = sortPlugins(allExtensions);
|
|
519
|
-
|
|
520
|
-
// Initialize the controls
|
|
521
|
-
_channelControl.initialize(config, _self, allExtensions);
|
|
522
|
-
|
|
523
|
-
initializePlugins(_createTelCtx(), allExtensions);
|
|
524
|
-
|
|
525
|
-
// Now reset the extensions to just those being managed by Basecore
|
|
526
|
-
_self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
|
|
527
|
-
|
|
528
|
-
if (updateState) {
|
|
529
|
-
_doUpdate(updateState);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
function _getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
|
|
534
|
-
let theExt: ILoadedPlugin<T> = null;
|
|
535
|
-
let thePlugin: IPlugin = null;
|
|
536
|
-
|
|
537
|
-
arrForEach(_self._extensions, (ext: any) => {
|
|
538
|
-
if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
|
|
539
|
-
thePlugin = ext;
|
|
540
|
-
return -1;
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
if (!thePlugin && _channelControl) {
|
|
545
|
-
// Check the channel Controller
|
|
546
|
-
thePlugin = _channelControl.getChannel(pluginIdentifier);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
if (thePlugin) {
|
|
550
|
-
theExt = {
|
|
551
|
-
plugin: thePlugin as T,
|
|
552
|
-
setEnabled: (enabled: boolean) => {
|
|
553
|
-
_getPluginState(thePlugin)[strDisabled] = !enabled;
|
|
554
|
-
},
|
|
555
|
-
isEnabled: () => {
|
|
556
|
-
let pluginState = _getPluginState(thePlugin);
|
|
557
|
-
return !pluginState[strTeardown] && !pluginState[strDisabled];
|
|
558
|
-
},
|
|
559
|
-
remove: (isAsync: boolean = true, removeCb?: (removed?: boolean) => void): void => {
|
|
560
|
-
let pluginsToRemove: IPlugin[] = [thePlugin];
|
|
561
|
-
let unloadState: ITelemetryUnloadState = {
|
|
562
|
-
reason: TelemetryUnloadReason.PluginUnload,
|
|
563
|
-
isAsync: isAsync
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
_removePlugins(pluginsToRemove, unloadState, (removed) => {
|
|
567
|
-
if (removed) {
|
|
568
|
-
// Re-Initialize the plugin chain
|
|
569
|
-
_initPluginChain(_self.config, {
|
|
570
|
-
reason: TelemetryUpdateReason.PluginRemoved,
|
|
571
|
-
removed: pluginsToRemove
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
removeCb && removeCb(removed);
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
return theExt;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
function _getPluginChain() {
|
|
585
|
-
if (!_pluginChain) {
|
|
586
|
-
// copy the collection of extensions
|
|
587
|
-
let extensions = (_coreExtensions || []).slice();
|
|
588
|
-
|
|
589
|
-
// During add / remove this may get called again, so don't readd if already present
|
|
590
|
-
if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
|
|
591
|
-
extensions.push(_telemetryInitializerPlugin);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
_pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
return _pluginChain;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
function _removePlugins(thePlugins: IPlugin[], unloadState: ITelemetryUnloadState, removeComplete: (removed: boolean) => void) {
|
|
601
|
-
|
|
602
|
-
if (thePlugins && thePlugins.length > 0) {
|
|
603
|
-
let unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
|
|
604
|
-
let unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
|
|
605
|
-
|
|
606
|
-
unloadCtx.onComplete(() => {
|
|
607
|
-
let removed = false;
|
|
608
|
-
|
|
609
|
-
// Remove the listed config extensions
|
|
610
|
-
let newConfigExtensions: IPlugin[] = [];
|
|
611
|
-
arrForEach(_configExtensions, (plugin, idx) => {
|
|
612
|
-
if (!_isPluginPresent(plugin, thePlugins)) {
|
|
613
|
-
newConfigExtensions.push(plugin);
|
|
614
|
-
} else {
|
|
615
|
-
removed = true;
|
|
616
|
-
}
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
_configExtensions = newConfigExtensions;
|
|
620
|
-
|
|
621
|
-
// Re-Create the channel config
|
|
622
|
-
let newChannelConfig: IChannelControls[][] = [];
|
|
623
|
-
if (_channelConfig) {
|
|
624
|
-
arrForEach(_channelConfig, (queue, idx) => {
|
|
625
|
-
let newQueue: IChannelControls[] = [];
|
|
626
|
-
arrForEach(queue, (channel) => {
|
|
627
|
-
if (!_isPluginPresent(channel, thePlugins)) {
|
|
628
|
-
newQueue.push(channel);
|
|
629
|
-
} else {
|
|
630
|
-
removed = true;
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
newChannelConfig.push(newQueue);
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
_channelConfig = newChannelConfig;
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
removeComplete && removeComplete(removed);
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
unloadCtx.processNext(unloadState);
|
|
644
|
-
} else {
|
|
645
|
-
removeComplete(false);
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
function _flushInternalLogs() {
|
|
650
|
-
let queue: _InternalLogMessage[] = _self.logger ? _self.logger.queue : [];
|
|
651
|
-
if (queue) {
|
|
652
|
-
arrForEach(queue, (logMessage: _InternalLogMessage) => {
|
|
653
|
-
const item: ITelemetryItem = {
|
|
654
|
-
name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
|
|
655
|
-
iKey: _self.config.instrumentationKey,
|
|
656
|
-
time: toISOString(new Date()),
|
|
657
|
-
baseType: _InternalLogMessage.dataType,
|
|
658
|
-
baseData: { message: logMessage.message }
|
|
659
|
-
};
|
|
660
|
-
_self.track(item);
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
queue.length = 0;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
function _flushChannels(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number) {
|
|
668
|
-
if (_channelControl) {
|
|
669
|
-
return _channelControl.flush(isAsync, callBack, sendReason || SendRequestReason.SdkUnload, cbTimeout);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
callBack && callBack(false);
|
|
673
|
-
return true;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
function _initDebugListener(config: IConfiguration) {
|
|
677
|
-
|
|
678
|
-
if (config.disableDbgExt === true && _debugListener) {
|
|
679
|
-
// Remove any previously loaded debug listener
|
|
680
|
-
_notificationManager[strRemoveNotificationListener](_debugListener);
|
|
681
|
-
_debugListener = null;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
|
|
685
|
-
_debugListener = getDebugListener(config);
|
|
686
|
-
_notificationManager[strAddNotificationListener](_debugListener);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
function _initPerfManager(config: IConfiguration) {
|
|
691
|
-
if (!config.enablePerfMgr && _cfgPerfManager) {
|
|
692
|
-
// Remove any existing config based performance manager
|
|
693
|
-
_cfgPerfManager = null;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
if (config.enablePerfMgr) {
|
|
697
|
-
// Set the performance manager creation function if not defined
|
|
698
|
-
setValue(_self.config, "createPerfMgr", _createPerfManager);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
function _initExtConfig(config: IConfiguration) {
|
|
703
|
-
let extConfig = getSetValue(config, strExtensionConfig);
|
|
704
|
-
extConfig.NotificationManager = _notificationManager;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
function _doUpdate(updateState: ITelemetryUpdateState): void {
|
|
708
|
-
let updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
|
|
709
|
-
|
|
710
|
-
if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
|
|
711
|
-
updateCtx.processNext(updateState);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
function _logOrThrowError(message: string) {
|
|
716
|
-
let logger = _self.logger;
|
|
717
|
-
if (logger) {
|
|
718
|
-
// there should always be a logger
|
|
719
|
-
_throwInternal(logger, eLoggingSeverity.WARNING, _eInternalMessageId.PluginException, message);
|
|
720
|
-
} else {
|
|
721
|
-
throwError(message);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
260
|
});
|
|
725
261
|
}
|
|
726
262
|
|
|
@@ -747,24 +283,6 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
747
283
|
return null;
|
|
748
284
|
}
|
|
749
285
|
|
|
750
|
-
/**
|
|
751
|
-
* Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
|
|
752
|
-
* The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
|
|
753
|
-
* called.
|
|
754
|
-
* @param {INotificationListener} listener - An INotificationListener object.
|
|
755
|
-
*/
|
|
756
|
-
public addNotificationListener(listener: INotificationListener): void {
|
|
757
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
/**
|
|
761
|
-
* Removes all instances of the listener.
|
|
762
|
-
* @param {INotificationListener} listener - INotificationListener to remove.
|
|
763
|
-
*/
|
|
764
|
-
public removeNotificationListener(listener: INotificationListener): void {
|
|
765
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
766
|
-
}
|
|
767
|
-
|
|
768
286
|
/**
|
|
769
287
|
* Get the current cookie manager for this instance
|
|
770
288
|
*/
|
|
@@ -795,101 +313,7 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
795
313
|
return 0;
|
|
796
314
|
}
|
|
797
315
|
|
|
798
|
-
/**
|
|
799
|
-
* Periodically check logger.queue for
|
|
800
|
-
*/
|
|
801
|
-
public pollInternalLogs(eventName?: string): number {
|
|
802
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
803
|
-
return 0;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Periodically check logger.queue for
|
|
808
|
-
*/
|
|
809
|
-
public stopPollingInternalLogs(): void {
|
|
810
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
/**
|
|
814
|
-
* Add a telemetry processor to decorate or drop telemetry events.
|
|
815
|
-
* @param telemetryInitializer - The Telemetry Initializer function
|
|
816
|
-
* @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
|
|
817
|
-
*/
|
|
818
|
-
public addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void {
|
|
819
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
/**
|
|
823
|
-
* Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
|
|
824
|
-
* to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
|
|
825
|
-
* unload call return `true` stating that all plugins reported that they also unloaded, the recommended
|
|
826
|
-
* approach is to create a new instance and initialize that instance.
|
|
827
|
-
* This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
|
|
828
|
-
* to successfully remove any global references or they may just be completing the unload process asynchronously.
|
|
829
|
-
* @param isAsync - Can the unload be performed asynchronously (default)
|
|
830
|
-
* @param unloadComplete - An optional callback that will be called once the unload has completed
|
|
831
|
-
* @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
|
|
832
|
-
*/
|
|
833
|
-
public unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void {
|
|
834
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
public getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T> {
|
|
838
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
839
|
-
return null;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
/**
|
|
843
|
-
* Add a new plugin to the installation
|
|
844
|
-
* @param plugin - The new plugin to add
|
|
845
|
-
* @param replaceExisting - should any existing plugin be replaced, default is false
|
|
846
|
-
* @param doAsync - Should the add be performed asynchronously
|
|
847
|
-
* @param addCb - [Optional] callback to call after the plugin has been added
|
|
848
|
-
*/
|
|
849
|
-
public addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void {
|
|
850
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
/**
|
|
854
|
-
* Returns the unique event namespace that should be used
|
|
855
|
-
*/
|
|
856
|
-
public evtNamespace(): string {
|
|
857
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
858
|
-
return null;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* Add an unload handler that will be called when the SDK is being unloaded
|
|
863
|
-
* @param handler - the handler
|
|
864
|
-
*/
|
|
865
|
-
public addUnloadCb(handler: UnloadHandler): void {
|
|
866
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
/**
|
|
870
|
-
* Flush and send any batched / cached data immediately
|
|
871
|
-
* @param async - send data asynchronously when true (defaults to true)
|
|
872
|
-
* @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.
|
|
873
|
-
* If the caller doesn't return true the caller should assume that it may never be called.
|
|
874
|
-
* @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
|
|
875
|
-
* @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
|
|
876
|
-
*/
|
|
877
|
-
public flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void {
|
|
878
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
879
|
-
}
|
|
880
|
-
|
|
881
316
|
protected releaseQueue() {
|
|
882
317
|
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
883
318
|
}
|
|
884
|
-
|
|
885
|
-
/**
|
|
886
|
-
* Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
|
|
887
|
-
* @param updateCtx - The plugin update context
|
|
888
|
-
* @param updateState - The Update State
|
|
889
|
-
* @returns boolean - True means the extension class will call updateState otherwise the Core will
|
|
890
|
-
*/
|
|
891
|
-
protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean {
|
|
892
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
893
|
-
return false;
|
|
894
|
-
}
|
|
895
319
|
}
|