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