@microsoft/applicationinsights-core-js 2.8.0-beta.2203-02 → 2.8.0-beta.2203-03
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 +197 -10
- 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 +751 -33
- package/dist/applicationinsights-core-js.api.md +26 -0
- package/dist/applicationinsights-core-js.d.ts +73 -2
- package/dist/applicationinsights-core-js.js +197 -10
- 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 +73 -2
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +183 -10
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +8 -2
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +2 -2
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +16 -2
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +32 -0
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.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/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/applicationinsights-core-js.js +2 -1
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +1 -1
- package/src/JavaScriptSDK/BaseCore.ts +233 -10
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +16 -2
- package/src/JavaScriptSDK/HelperFuncs.ts +1 -1
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +16 -2
- package/src/JavaScriptSDK/UnloadHandlerContainer.ts +44 -0
- package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +3 -3
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +29 -2
- package/types/JavaScriptSDK/BaseCore.d.ts +17 -1
- package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +6 -0
- package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +2 -0
- package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
- package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
- package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +13 -1
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +24 -1
- package/types/applicationinsights-core-js.d.ts +1 -0
|
@@ -60,7 +60,10 @@ export function attachEvent(obj: any, eventNameWithoutOn: string, handlerRef: an
|
|
|
60
60
|
export class BaseCore implements IAppInsightsCore {
|
|
61
61
|
constructor();
|
|
62
62
|
addNotificationListener(listener: INotificationListener): void;
|
|
63
|
+
// (undocumented)
|
|
64
|
+
addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
|
|
63
65
|
addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
|
|
66
|
+
addUnloadCb(handler: UnloadHandler): void;
|
|
64
67
|
// (undocumented)
|
|
65
68
|
config: IConfiguration;
|
|
66
69
|
// (undocumented)
|
|
@@ -99,12 +102,14 @@ export class BaseCore implements IAppInsightsCore {
|
|
|
99
102
|
stopPollingInternalLogs(): void;
|
|
100
103
|
// (undocumented)
|
|
101
104
|
track(telemetryItem: ITelemetryItem): void;
|
|
105
|
+
unload(isAsync?: boolean, unloadComplete?: () => void): void;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
// @public
|
|
105
109
|
export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
106
110
|
constructor();
|
|
107
111
|
protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
|
|
112
|
+
protected _addUnloadCb(handler: UnloadHandler): void;
|
|
108
113
|
core: IAppInsightsCore;
|
|
109
114
|
diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
|
|
110
115
|
// Warning: (ae-forgotten-export) The symbol "IProcessTelemetryUnloadContext" needs to be exported by the entry point applicationinsights-core-js.d.ts
|
|
@@ -148,6 +153,12 @@ export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginCh
|
|
|
148
153
|
// @public (undocumented)
|
|
149
154
|
export function createUniqueNamespace(name: string, includeVersion?: boolean): string;
|
|
150
155
|
|
|
156
|
+
// @public (undocumented)
|
|
157
|
+
export function createUnloadHandlerContainer(): {
|
|
158
|
+
add: (handler: UnloadHandler) => void;
|
|
159
|
+
run: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
|
|
160
|
+
};
|
|
161
|
+
|
|
151
162
|
// @public
|
|
152
163
|
export function dateNow(): number;
|
|
153
164
|
|
|
@@ -466,7 +477,9 @@ export function hasWindow(): boolean;
|
|
|
466
477
|
// @public (undocumented)
|
|
467
478
|
export interface IAppInsightsCore extends IPerfManagerProvider {
|
|
468
479
|
addNotificationListener?(listener: INotificationListener): void;
|
|
480
|
+
addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
|
|
469
481
|
addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
|
|
482
|
+
addUnloadCb(handler: UnloadHandler): void;
|
|
470
483
|
// (undocumented)
|
|
471
484
|
config: IConfiguration;
|
|
472
485
|
evtNamespace(): string;
|
|
@@ -489,6 +502,7 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
|
|
|
489
502
|
stopPollingInternalLogs?(): void;
|
|
490
503
|
// (undocumented)
|
|
491
504
|
track(telemetryItem: ITelemetryItem): void;
|
|
505
|
+
unload(isAsync?: boolean, unloadComplete?: () => void): void;
|
|
492
506
|
}
|
|
493
507
|
|
|
494
508
|
// @public
|
|
@@ -995,6 +1009,14 @@ export interface ITelemetryUnloadState {
|
|
|
995
1009
|
reason: TelemetryUnloadReason;
|
|
996
1010
|
}
|
|
997
1011
|
|
|
1012
|
+
// @public (undocumented)
|
|
1013
|
+
export interface IUnloadHandlerContainer {
|
|
1014
|
+
// (undocumented)
|
|
1015
|
+
add: (handler: UnloadHandler) => void;
|
|
1016
|
+
// (undocumented)
|
|
1017
|
+
run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
998
1020
|
// @public
|
|
999
1021
|
export function _legacyCookieMgr(config?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr;
|
|
1000
1022
|
|
|
@@ -1158,6 +1180,7 @@ export const enum SendRequestReason {
|
|
|
1158
1180
|
NormalSchedule = 1,
|
|
1159
1181
|
Resumed = 4,
|
|
1160
1182
|
Retry = 5,
|
|
1183
|
+
SdkUnload = 6,
|
|
1161
1184
|
SyncEvent = 3,
|
|
1162
1185
|
Undefined = 0,
|
|
1163
1186
|
Unload = 2
|
|
@@ -1225,6 +1248,9 @@ export function uaDisallowsSameSiteNone(userAgent: string): boolean;
|
|
|
1225
1248
|
// @public (undocumented)
|
|
1226
1249
|
export const Undefined = "undefined";
|
|
1227
1250
|
|
|
1251
|
+
// @public (undocumented)
|
|
1252
|
+
export type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
|
|
1253
|
+
|
|
1228
1254
|
// @public (undocumented)
|
|
1229
1255
|
export function useXDomainRequest(): boolean | undefined;
|
|
1230
1256
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Microsoft Application Insights Core Javascript SDK, 2.8.0-beta.2203-
|
|
2
|
+
* Microsoft Application Insights Core Javascript SDK, 2.8.0-beta.2203-03
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* Microsoft Application Insights Team
|
|
@@ -189,11 +189,26 @@ declare namespace ApplicationInsights {
|
|
|
189
189
|
* @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
|
|
190
190
|
*/
|
|
191
191
|
addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
|
|
192
|
+
/**
|
|
193
|
+
* Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
|
|
194
|
+
* to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
|
|
195
|
+
* unload call return `true` stating that all plugins reported that they also unloaded, the recommended
|
|
196
|
+
* approach is to create a new instance and initialize that instance.
|
|
197
|
+
* This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
|
|
198
|
+
* to successfully remove any global references or they may just be completing the unload process asynchronously.
|
|
199
|
+
*/
|
|
200
|
+
unload(isAsync?: boolean, unloadComplete?: () => void): void;
|
|
192
201
|
getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
|
|
202
|
+
addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
|
|
193
203
|
/**
|
|
194
204
|
* Returns the unique event namespace that should be used
|
|
195
205
|
*/
|
|
196
206
|
evtNamespace(): string;
|
|
207
|
+
/**
|
|
208
|
+
* Add an unload handler that will be called when the SDK is being unloaded
|
|
209
|
+
* @param handler - the handler
|
|
210
|
+
*/
|
|
211
|
+
addUnloadCb(handler: UnloadHandler): void;
|
|
197
212
|
protected releaseQueue(): void;
|
|
198
213
|
}
|
|
199
214
|
|
|
@@ -263,6 +278,11 @@ declare namespace ApplicationInsights {
|
|
|
263
278
|
*/
|
|
264
279
|
teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
|
|
265
280
|
abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
|
|
281
|
+
/**
|
|
282
|
+
* Add an unload handler that will be called when the SDK is being unloaded
|
|
283
|
+
* @param handler - the handler
|
|
284
|
+
*/
|
|
285
|
+
protected _addUnloadCb(handler: UnloadHandler): void;
|
|
266
286
|
/**
|
|
267
287
|
* Add this hook so that it is automatically removed during unloading
|
|
268
288
|
* @param hooks - The single hook or an array of IInstrumentHook objects
|
|
@@ -305,11 +325,17 @@ declare namespace ApplicationInsights {
|
|
|
305
325
|
* @param plugins - The plugin instances that will be executed
|
|
306
326
|
* @param config - The current config
|
|
307
327
|
* @param core - The current core instance
|
|
328
|
+
* @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
|
|
308
329
|
*/
|
|
309
330
|
function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
|
|
310
331
|
|
|
311
332
|
function createUniqueNamespace(name: string, includeVersion?: boolean): string;
|
|
312
333
|
|
|
334
|
+
function createUnloadHandlerContainer(): {
|
|
335
|
+
add: (handler: UnloadHandler) => void;
|
|
336
|
+
run: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
|
|
337
|
+
};
|
|
338
|
+
|
|
313
339
|
/**
|
|
314
340
|
* Return the current time via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less)
|
|
315
341
|
* https://caniuse.com/#search=Date.now
|
|
@@ -781,15 +807,36 @@ declare namespace ApplicationInsights {
|
|
|
781
807
|
* Return a new instance of the IProcessTelemetryContext for processing events
|
|
782
808
|
*/
|
|
783
809
|
getProcessTelContext(): IProcessTelemetryContext;
|
|
810
|
+
/**
|
|
811
|
+
* Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
|
|
812
|
+
* to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
|
|
813
|
+
* unload call return `true` stating that all plugins reported that they also unloaded, the recommended
|
|
814
|
+
* approach is to create a new instance and initialize that instance.
|
|
815
|
+
* This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
|
|
816
|
+
* to successfully remove any global references or they may just be completing the unload process asynchronously.
|
|
817
|
+
*/
|
|
818
|
+
unload(isAsync?: boolean, unloadComplete?: () => void): void;
|
|
784
819
|
/**
|
|
785
820
|
* Find and return the (first) plugin with the specified identifier if present
|
|
786
821
|
* @param pluginIdentifier
|
|
787
822
|
*/
|
|
788
823
|
getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
|
|
824
|
+
/**
|
|
825
|
+
* Add a new plugin to the installation
|
|
826
|
+
* @param plugin - The new plugin to add
|
|
827
|
+
* @param replaceExisting - should any existing plugin be replaced
|
|
828
|
+
* @param doAsync - Should the add be performed asynchronously
|
|
829
|
+
*/
|
|
830
|
+
addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
|
|
789
831
|
/**
|
|
790
832
|
* Returns the unique event namespace that should be used when registering events
|
|
791
833
|
*/
|
|
792
834
|
evtNamespace(): string;
|
|
835
|
+
/**
|
|
836
|
+
* Add a handler that will be called when the SDK is being unloaded
|
|
837
|
+
* @param handler - the handler
|
|
838
|
+
*/
|
|
839
|
+
addUnloadCb(handler: UnloadHandler): void;
|
|
793
840
|
}
|
|
794
841
|
|
|
795
842
|
interface IBaseProcessingContext {
|
|
@@ -1491,6 +1538,7 @@ declare namespace ApplicationInsights {
|
|
|
1491
1538
|
* (unless it's also been re-initialized)
|
|
1492
1539
|
*/
|
|
1493
1540
|
setEnabled: (isEnabled: boolean) => void;
|
|
1541
|
+
remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
|
|
1494
1542
|
}
|
|
1495
1543
|
|
|
1496
1544
|
/**
|
|
@@ -2102,6 +2150,11 @@ declare namespace ApplicationInsights {
|
|
|
2102
2150
|
flushComplete?: boolean;
|
|
2103
2151
|
}
|
|
2104
2152
|
|
|
2153
|
+
interface IUnloadHandlerContainer {
|
|
2154
|
+
add: (handler: UnloadHandler) => void;
|
|
2155
|
+
run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2105
2158
|
/**
|
|
2106
2159
|
* Helper to support backward compatibility for users that use the legacy cookie handling functions and the use the internal
|
|
2107
2160
|
* CoreUtils._canUseCookies global flag to enable/disable cookies usage.
|
|
@@ -2522,6 +2575,10 @@ declare namespace ApplicationInsights {
|
|
|
2522
2575
|
* The event(s) being sent as a retry
|
|
2523
2576
|
*/
|
|
2524
2577
|
Retry = 5,
|
|
2578
|
+
/**
|
|
2579
|
+
* The SDK is unloading
|
|
2580
|
+
*/
|
|
2581
|
+
SdkUnload = 6,
|
|
2525
2582
|
/**
|
|
2526
2583
|
* Maximum batch size would be exceeded
|
|
2527
2584
|
*/
|
|
@@ -2617,7 +2674,19 @@ declare namespace ApplicationInsights {
|
|
|
2617
2674
|
/**
|
|
2618
2675
|
* Teardown has been called without any context.
|
|
2619
2676
|
*/
|
|
2620
|
-
ManualTeardown = 0
|
|
2677
|
+
ManualTeardown = 0,
|
|
2678
|
+
/**
|
|
2679
|
+
* Just this plugin is being removed
|
|
2680
|
+
*/
|
|
2681
|
+
PluginUnload = 1,
|
|
2682
|
+
/**
|
|
2683
|
+
* This instance of the plugin is being removed and replaced
|
|
2684
|
+
*/
|
|
2685
|
+
PluginReplace = 2,
|
|
2686
|
+
/**
|
|
2687
|
+
* The entire SDK is being unloaded
|
|
2688
|
+
*/
|
|
2689
|
+
SdkUnload = 50
|
|
2621
2690
|
}
|
|
2622
2691
|
|
|
2623
2692
|
function throwError(message: string): never;
|
|
@@ -2631,6 +2700,8 @@ declare namespace ApplicationInsights {
|
|
|
2631
2700
|
|
|
2632
2701
|
const Undefined = "undefined";
|
|
2633
2702
|
|
|
2703
|
+
type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
|
|
2704
|
+
|
|
2634
2705
|
function useXDomainRequest(): boolean | undefined;
|
|
2635
2706
|
|
|
2636
2707
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 2.8.0-beta.2203-
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 2.8.0-beta.2203-03
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
(function (global, factory) {
|
|
@@ -833,7 +833,7 @@
|
|
|
833
833
|
objForEachKey(values, function (field, value) {
|
|
834
834
|
enumClass[field] = value;
|
|
835
835
|
if (!isUndefined(enumClass[value])) {
|
|
836
|
-
throwError("
|
|
836
|
+
throwError("[" + value + "] exists for " + field);
|
|
837
837
|
}
|
|
838
838
|
enumClass[value] = field;
|
|
839
839
|
});
|
|
@@ -1676,8 +1676,11 @@
|
|
|
1676
1676
|
return createTelemetryProxyChain([startAt], config, core);
|
|
1677
1677
|
}
|
|
1678
1678
|
function _createInternalContext(telemetryChain, config, core, startAt) {
|
|
1679
|
-
var _nextProxy =
|
|
1679
|
+
var _nextProxy = null;
|
|
1680
1680
|
var _onComplete = [];
|
|
1681
|
+
if (startAt !== null) {
|
|
1682
|
+
_nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
|
|
1683
|
+
}
|
|
1681
1684
|
var context = {
|
|
1682
1685
|
_next: _moveNext,
|
|
1683
1686
|
ctx: {
|
|
@@ -2401,6 +2404,30 @@
|
|
|
2401
2404
|
return channelQueue;
|
|
2402
2405
|
}
|
|
2403
2406
|
|
|
2407
|
+
function createUnloadHandlerContainer() {
|
|
2408
|
+
var handlers = [];
|
|
2409
|
+
function _addHandler(handler) {
|
|
2410
|
+
if (handler) {
|
|
2411
|
+
handlers.push(handler);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
function _runHandlers(unloadCtx, unloadState) {
|
|
2415
|
+
arrForEach(handlers, function (handler) {
|
|
2416
|
+
try {
|
|
2417
|
+
handler(unloadCtx, unloadState);
|
|
2418
|
+
}
|
|
2419
|
+
catch (e) {
|
|
2420
|
+
unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
|
|
2421
|
+
}
|
|
2422
|
+
});
|
|
2423
|
+
handlers = [];
|
|
2424
|
+
}
|
|
2425
|
+
return {
|
|
2426
|
+
add: _addHandler,
|
|
2427
|
+
run: _runHandlers
|
|
2428
|
+
};
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2404
2431
|
var strGetPlugin = "getPlugin";
|
|
2405
2432
|
var BaseTelemetryPlugin = /** @class */ (function () {
|
|
2406
2433
|
function BaseTelemetryPlugin() {
|
|
@@ -2408,6 +2435,7 @@
|
|
|
2408
2435
|
var _isinitialized;
|
|
2409
2436
|
var _rootCtx;
|
|
2410
2437
|
var _nextPlugin;
|
|
2438
|
+
var _unloadHandlerContainer;
|
|
2411
2439
|
var _hooks;
|
|
2412
2440
|
_initDefaults();
|
|
2413
2441
|
dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
|
|
@@ -2429,6 +2457,7 @@
|
|
|
2429
2457
|
function _unloadCallback() {
|
|
2430
2458
|
if (!unloadDone) {
|
|
2431
2459
|
unloadDone = true;
|
|
2460
|
+
_unloadHandlerContainer.run(theUnloadCtx, unloadState);
|
|
2432
2461
|
arrForEach(_hooks, function (fn) {
|
|
2433
2462
|
fn.rm();
|
|
2434
2463
|
});
|
|
@@ -2457,6 +2486,7 @@
|
|
|
2457
2486
|
}
|
|
2458
2487
|
}
|
|
2459
2488
|
};
|
|
2489
|
+
proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
|
|
2460
2490
|
});
|
|
2461
2491
|
_self.diagLog = function (itemCtx) {
|
|
2462
2492
|
return _getTelCtx(itemCtx).diagLog();
|
|
@@ -2513,6 +2543,7 @@
|
|
|
2513
2543
|
_rootCtx = null;
|
|
2514
2544
|
_nextPlugin = null;
|
|
2515
2545
|
_hooks = [];
|
|
2546
|
+
_unloadHandlerContainer = createUnloadHandlerContainer();
|
|
2516
2547
|
}
|
|
2517
2548
|
}
|
|
2518
2549
|
return BaseTelemetryPlugin;
|
|
@@ -2582,6 +2613,8 @@
|
|
|
2582
2613
|
|
|
2583
2614
|
var strValidationError = "Plugins must provide initialize method";
|
|
2584
2615
|
var strNotificationManager = "_notificationManager";
|
|
2616
|
+
var strSdkUnloadingError = "SDK is still unloading...";
|
|
2617
|
+
var strSdkNotInitialized = "SDK is not initialized";
|
|
2585
2618
|
function _createPerfManager(core, notificationMgr) {
|
|
2586
2619
|
return new PerfManager(notificationMgr);
|
|
2587
2620
|
}
|
|
@@ -2611,6 +2644,16 @@
|
|
|
2611
2644
|
core: coreExtensions
|
|
2612
2645
|
};
|
|
2613
2646
|
}
|
|
2647
|
+
function _isPluginPresent(thePlugin, plugins) {
|
|
2648
|
+
var exists = false;
|
|
2649
|
+
arrForEach(plugins, function (plugin) {
|
|
2650
|
+
if (plugin === thePlugin) {
|
|
2651
|
+
exists = true;
|
|
2652
|
+
return -1;
|
|
2653
|
+
}
|
|
2654
|
+
});
|
|
2655
|
+
return exists;
|
|
2656
|
+
}
|
|
2614
2657
|
function _createDummyNotificationManager() {
|
|
2615
2658
|
var _a;
|
|
2616
2659
|
return objCreateFn((_a = {},
|
|
@@ -2635,15 +2678,20 @@
|
|
|
2635
2678
|
var _channelControl;
|
|
2636
2679
|
var _channelConfig;
|
|
2637
2680
|
var _channelQueue;
|
|
2681
|
+
var _isUnloading;
|
|
2638
2682
|
var _telemetryInitializerPlugin;
|
|
2639
2683
|
var _internalLogsEventName;
|
|
2640
2684
|
var _evtNamespace;
|
|
2685
|
+
var _unloadHandlers;
|
|
2641
2686
|
var _debugListener;
|
|
2642
2687
|
var _internalLogPoller = 0;
|
|
2643
2688
|
dynamicProto(BaseCore, this, function (_self) {
|
|
2644
2689
|
_initDefaults();
|
|
2645
2690
|
_self.isInitialized = function () { return _isInitialized; };
|
|
2646
2691
|
_self.initialize = function (config, extensions, logger, notificationManager) {
|
|
2692
|
+
if (_isUnloading) {
|
|
2693
|
+
throwError(strSdkUnloadingError);
|
|
2694
|
+
}
|
|
2647
2695
|
if (_self.isInitialized()) {
|
|
2648
2696
|
throwError("Core should not be initialized more than once");
|
|
2649
2697
|
}
|
|
@@ -2656,8 +2704,7 @@
|
|
|
2656
2704
|
_initDebugListener(config);
|
|
2657
2705
|
_initPerfManager(config);
|
|
2658
2706
|
config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
|
|
2659
|
-
|
|
2660
|
-
extConfig.NotificationManager = notificationManager;
|
|
2707
|
+
_initExtConfig(config);
|
|
2661
2708
|
if (logger) {
|
|
2662
2709
|
_self.logger = logger;
|
|
2663
2710
|
}
|
|
@@ -2682,7 +2729,7 @@
|
|
|
2682
2729
|
setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
|
|
2683
2730
|
setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
|
|
2684
2731
|
setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
|
|
2685
|
-
if (_self.isInitialized()) {
|
|
2732
|
+
if (!_isUnloading && _self.isInitialized()) {
|
|
2686
2733
|
_createTelCtx().processNext(telemetryItem);
|
|
2687
2734
|
}
|
|
2688
2735
|
else {
|
|
@@ -2697,14 +2744,14 @@
|
|
|
2697
2744
|
}
|
|
2698
2745
|
return _notificationManager;
|
|
2699
2746
|
};
|
|
2700
|
-
_self
|
|
2747
|
+
_self[strAddNotificationListener] = function (listener) {
|
|
2701
2748
|
if (_notificationManager) {
|
|
2702
|
-
_notificationManager
|
|
2749
|
+
_notificationManager[strAddNotificationListener](listener);
|
|
2703
2750
|
}
|
|
2704
2751
|
};
|
|
2705
|
-
_self
|
|
2752
|
+
_self[strRemoveNotificationListener] = function (listener) {
|
|
2706
2753
|
if (_notificationManager) {
|
|
2707
|
-
_notificationManager
|
|
2754
|
+
_notificationManager[strRemoveNotificationListener](listener);
|
|
2708
2755
|
}
|
|
2709
2756
|
};
|
|
2710
2757
|
_self.getCookieMgr = function () {
|
|
@@ -2761,10 +2808,80 @@
|
|
|
2761
2808
|
}
|
|
2762
2809
|
};
|
|
2763
2810
|
proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
|
|
2811
|
+
_self.unload = function (isAsync, unloadComplete, cbTimeout) {
|
|
2812
|
+
if (isAsync === void 0) { isAsync = true; }
|
|
2813
|
+
if (!_isInitialized) {
|
|
2814
|
+
throwError(strSdkNotInitialized);
|
|
2815
|
+
}
|
|
2816
|
+
if (_isUnloading) {
|
|
2817
|
+
throwError(strSdkUnloadingError);
|
|
2818
|
+
}
|
|
2819
|
+
var unloadState = {
|
|
2820
|
+
reason: 50 ,
|
|
2821
|
+
isAsync: isAsync,
|
|
2822
|
+
flushComplete: false
|
|
2823
|
+
};
|
|
2824
|
+
var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
|
|
2825
|
+
processUnloadCtx.onComplete(function () {
|
|
2826
|
+
_initDefaults();
|
|
2827
|
+
unloadComplete && unloadComplete(unloadState);
|
|
2828
|
+
}, _self);
|
|
2829
|
+
function _doUnload(flushComplete) {
|
|
2830
|
+
unloadState.flushComplete = flushComplete;
|
|
2831
|
+
_isUnloading = true;
|
|
2832
|
+
_unloadHandlers.run(processUnloadCtx, unloadState);
|
|
2833
|
+
_self.stopPollingInternalLogs();
|
|
2834
|
+
processUnloadCtx.processNext(unloadState);
|
|
2835
|
+
}
|
|
2836
|
+
if (_channelControl) {
|
|
2837
|
+
_channelControl.flush(isAsync, _doUnload, 6 , cbTimeout);
|
|
2838
|
+
}
|
|
2839
|
+
else {
|
|
2840
|
+
_doUnload(true);
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2764
2843
|
_self.getPlugin = _getPlugin;
|
|
2844
|
+
_self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
|
|
2845
|
+
if (isAsync === void 0) { isAsync = true; }
|
|
2846
|
+
if (!plugin) {
|
|
2847
|
+
addCb && addCb(false);
|
|
2848
|
+
_logOrThrowError(strValidationError);
|
|
2849
|
+
return;
|
|
2850
|
+
}
|
|
2851
|
+
var existingPlugin = _getPlugin(plugin.identifier);
|
|
2852
|
+
if (existingPlugin && !replaceExisting) {
|
|
2853
|
+
addCb && addCb(false);
|
|
2854
|
+
_logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
|
|
2855
|
+
return;
|
|
2856
|
+
}
|
|
2857
|
+
function _addPlugin(removed) {
|
|
2858
|
+
_configExtensions.push(plugin);
|
|
2859
|
+
_initPluginChain(_self.config);
|
|
2860
|
+
addCb && addCb(true);
|
|
2861
|
+
}
|
|
2862
|
+
if (existingPlugin) {
|
|
2863
|
+
var removedPlugins = [existingPlugin.plugin];
|
|
2864
|
+
var unloadState = {
|
|
2865
|
+
reason: 2 ,
|
|
2866
|
+
isAsync: isAsync
|
|
2867
|
+
};
|
|
2868
|
+
_removePlugins(removedPlugins, unloadState, function (removed) {
|
|
2869
|
+
if (!removed) {
|
|
2870
|
+
addCb && addCb(false);
|
|
2871
|
+
}
|
|
2872
|
+
else {
|
|
2873
|
+
_addPlugin();
|
|
2874
|
+
}
|
|
2875
|
+
});
|
|
2876
|
+
}
|
|
2877
|
+
else {
|
|
2878
|
+
_addPlugin();
|
|
2879
|
+
}
|
|
2880
|
+
};
|
|
2765
2881
|
_self.evtNamespace = function () {
|
|
2766
2882
|
return _evtNamespace;
|
|
2767
2883
|
};
|
|
2884
|
+
proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
|
|
2768
2885
|
function _initDefaults() {
|
|
2769
2886
|
_isInitialized = false;
|
|
2770
2887
|
_self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
|
|
@@ -2782,8 +2899,10 @@
|
|
|
2782
2899
|
_channelControl = null;
|
|
2783
2900
|
_channelConfig = null;
|
|
2784
2901
|
_channelQueue = null;
|
|
2902
|
+
_isUnloading = false;
|
|
2785
2903
|
_internalLogsEventName = null;
|
|
2786
2904
|
_evtNamespace = createUniqueNamespace("AIBaseCore", true);
|
|
2905
|
+
_unloadHandlers = createUnloadHandlerContainer();
|
|
2787
2906
|
}
|
|
2788
2907
|
function _createTelCtx() {
|
|
2789
2908
|
return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
|
|
@@ -2836,6 +2955,20 @@
|
|
|
2836
2955
|
isEnabled: function () {
|
|
2837
2956
|
var pluginState = _getPluginState(thePlugin);
|
|
2838
2957
|
return !pluginState[strTeardown] && !pluginState[strDisabled];
|
|
2958
|
+
},
|
|
2959
|
+
remove: function (isAsync, removeCb) {
|
|
2960
|
+
if (isAsync === void 0) { isAsync = true; }
|
|
2961
|
+
var pluginsToRemove = [thePlugin];
|
|
2962
|
+
var unloadState = {
|
|
2963
|
+
reason: 1 ,
|
|
2964
|
+
isAsync: isAsync
|
|
2965
|
+
};
|
|
2966
|
+
_removePlugins(pluginsToRemove, unloadState, function (removed) {
|
|
2967
|
+
if (removed) {
|
|
2968
|
+
_initPluginChain(_self.config);
|
|
2969
|
+
}
|
|
2970
|
+
removeCb && removeCb(removed);
|
|
2971
|
+
});
|
|
2839
2972
|
}
|
|
2840
2973
|
};
|
|
2841
2974
|
}
|
|
@@ -2851,6 +2984,46 @@
|
|
|
2851
2984
|
}
|
|
2852
2985
|
return _pluginChain;
|
|
2853
2986
|
}
|
|
2987
|
+
function _removePlugins(thePlugins, unloadState, removeComplete) {
|
|
2988
|
+
if (thePlugins && thePlugins.length > 0) {
|
|
2989
|
+
var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
|
|
2990
|
+
var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
|
|
2991
|
+
unloadCtx.onComplete(function () {
|
|
2992
|
+
var removed = false;
|
|
2993
|
+
var newConfigExtensions = [];
|
|
2994
|
+
arrForEach(_configExtensions, function (plugin, idx) {
|
|
2995
|
+
if (!_isPluginPresent(plugin, thePlugins)) {
|
|
2996
|
+
newConfigExtensions.push(plugin);
|
|
2997
|
+
}
|
|
2998
|
+
else {
|
|
2999
|
+
removed = true;
|
|
3000
|
+
}
|
|
3001
|
+
});
|
|
3002
|
+
_configExtensions = newConfigExtensions;
|
|
3003
|
+
var newChannelConfig = [];
|
|
3004
|
+
if (_channelConfig) {
|
|
3005
|
+
arrForEach(_channelConfig, function (queue, idx) {
|
|
3006
|
+
var newQueue = [];
|
|
3007
|
+
arrForEach(queue, function (channel) {
|
|
3008
|
+
if (!_isPluginPresent(channel, thePlugins)) {
|
|
3009
|
+
newQueue.push(channel);
|
|
3010
|
+
}
|
|
3011
|
+
else {
|
|
3012
|
+
removed = true;
|
|
3013
|
+
}
|
|
3014
|
+
});
|
|
3015
|
+
newChannelConfig.push(newQueue);
|
|
3016
|
+
});
|
|
3017
|
+
_channelConfig = newChannelConfig;
|
|
3018
|
+
}
|
|
3019
|
+
removeComplete && removeComplete(removed);
|
|
3020
|
+
});
|
|
3021
|
+
unloadCtx.processNext(unloadState);
|
|
3022
|
+
}
|
|
3023
|
+
else {
|
|
3024
|
+
removeComplete(false);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
2854
3027
|
function _flushInternalLogs() {
|
|
2855
3028
|
var queue = _self.logger ? _self.logger.queue : [];
|
|
2856
3029
|
if (queue) {
|
|
@@ -2885,6 +3058,19 @@
|
|
|
2885
3058
|
setValue(_self.config, "createPerfMgr", _createPerfManager);
|
|
2886
3059
|
}
|
|
2887
3060
|
}
|
|
3061
|
+
function _initExtConfig(config) {
|
|
3062
|
+
var extConfig = getSetValue(config, strExtensionConfig);
|
|
3063
|
+
extConfig.NotificationManager = _notificationManager;
|
|
3064
|
+
}
|
|
3065
|
+
function _logOrThrowError(message) {
|
|
3066
|
+
var logger = _self.logger;
|
|
3067
|
+
if (logger) {
|
|
3068
|
+
logger.throwInternal(2 , 73 , message);
|
|
3069
|
+
}
|
|
3070
|
+
else {
|
|
3071
|
+
throwError(message);
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
2888
3074
|
});
|
|
2889
3075
|
}
|
|
2890
3076
|
return BaseCore;
|
|
@@ -3699,6 +3885,7 @@
|
|
|
3699
3885
|
exports.createEnumStyle = createEnumStyle;
|
|
3700
3886
|
exports.createProcessTelemetryContext = createProcessTelemetryContext;
|
|
3701
3887
|
exports.createUniqueNamespace = createUniqueNamespace;
|
|
3888
|
+
exports.createUnloadHandlerContainer = createUnloadHandlerContainer;
|
|
3702
3889
|
exports.dateNow = dateNow;
|
|
3703
3890
|
exports.deleteCookie = deleteCookie;
|
|
3704
3891
|
exports.detachEvent = detachEvent;
|