@microsoft/applicationinsights-core-js 2.8.0-beta.2203-02 → 2.8.0-beta.2203-05

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.
Files changed (107) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +319 -29
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +2458 -250
  7. package/dist/applicationinsights-core-js.api.md +87 -7
  8. package/dist/applicationinsights-core-js.d.ts +192 -7
  9. package/dist/applicationinsights-core-js.js +319 -29
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +195 -10
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +205 -13
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +37 -3
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  19. package/dist-esm/JavaScriptSDK/ChannelController.js +14 -2
  20. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  21. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  22. package/dist-esm/JavaScriptSDK/CookieMgr.js +3 -2
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  25. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +1 -1
  26. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  27. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +14 -1
  28. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  29. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  30. package/dist-esm/JavaScriptSDK/EventHelpers.js +18 -13
  31. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/HelperFuncs.js +3 -13
  33. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  35. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  36. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  37. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  38. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +71 -6
  39. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  40. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  41. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
  42. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +3 -2
  43. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
  44. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +33 -0
  45. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  46. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +8 -0
  51. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +1 -0
  52. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +8 -0
  70. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +1 -0
  71. package/dist-esm/applicationinsights-core-js.js +3 -2
  72. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/JavaScriptSDK/BaseCore.ts +272 -14
  75. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +70 -4
  76. package/src/JavaScriptSDK/ChannelController.ts +18 -1
  77. package/src/JavaScriptSDK/CookieMgr.ts +3 -1
  78. package/src/JavaScriptSDK/DiagnosticLogger.ts +14 -0
  79. package/src/JavaScriptSDK/EventHelpers.ts +18 -12
  80. package/src/JavaScriptSDK/HelperFuncs.ts +4 -2
  81. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +87 -10
  82. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +3 -1
  83. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +46 -0
  84. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  85. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +3 -3
  86. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +27 -0
  87. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +29 -2
  88. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +11 -6
  89. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +25 -2
  90. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +12 -1
  91. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +34 -0
  92. package/types/JavaScriptSDK/BaseCore.d.ts +27 -2
  93. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +23 -1
  94. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +10 -0
  95. package/types/JavaScriptSDK/EventHelpers.d.ts +4 -2
  96. package/types/JavaScriptSDK/HelperFuncs.d.ts +2 -1
  97. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +11 -1
  98. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  99. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  100. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +13 -1
  101. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +20 -0
  102. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +24 -1
  103. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +5 -0
  104. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +23 -2
  105. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +11 -1
  106. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +22 -0
  107. package/types/applicationinsights-core-js.d.ts +6 -2
@@ -12,7 +12,7 @@ import { strShimPrototype as strPrototype } from '@microsoft/applicationinsights
12
12
  import { strShimUndefined as strUndefined } from '@microsoft/applicationinsights-shims';
13
13
 
14
14
  // @public
15
- export function __getRegisteredEvents(target: any, evtName?: string): _IRegisteredEvents[];
15
+ export function __getRegisteredEvents(target: any, eventName?: string, evtNamespace?: string | string[]): _IRegisteredEvents[];
16
16
 
17
17
  // @public
18
18
  export function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]): boolean;
@@ -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,16 +102,19 @@ export class BaseCore implements IAppInsightsCore {
99
102
  stopPollingInternalLogs(): void;
100
103
  // (undocumented)
101
104
  track(telemetryItem: ITelemetryItem): void;
105
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
106
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
102
107
  }
103
108
 
104
109
  // @public
105
110
  export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
106
111
  constructor();
107
112
  protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
113
+ protected _addUnloadCb(handler: UnloadHandler): void;
108
114
  core: IAppInsightsCore;
109
115
  diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
110
- // Warning: (ae-forgotten-export) The symbol "IProcessTelemetryUnloadContext" needs to be exported by the entry point applicationinsights-core-js.d.ts
111
116
  protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
117
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
112
118
  protected _getTelCtx: (currentCtx?: IProcessTelemetryContext) => IProcessTelemetryContext;
113
119
  // (undocumented)
114
120
  identifier: string;
@@ -123,6 +129,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
123
129
  protected setInitialized: (isInitialized: boolean) => void;
124
130
  setNextPlugin: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
125
131
  teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
132
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
126
133
  // (undocumented)
127
134
  version?: string;
128
135
  }
@@ -148,6 +155,12 @@ export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginCh
148
155
  // @public (undocumented)
149
156
  export function createUniqueNamespace(name: string, includeVersion?: boolean): string;
150
157
 
158
+ // @public (undocumented)
159
+ export function createUnloadHandlerContainer(): {
160
+ add: (handler: UnloadHandler) => void;
161
+ run: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
162
+ };
163
+
151
164
  // @public
152
165
  export function dateNow(): number;
153
166
 
@@ -466,7 +479,9 @@ export function hasWindow(): boolean;
466
479
  // @public (undocumented)
467
480
  export interface IAppInsightsCore extends IPerfManagerProvider {
468
481
  addNotificationListener?(listener: INotificationListener): void;
482
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
469
483
  addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
484
+ addUnloadCb(handler: UnloadHandler): void;
470
485
  // (undocumented)
471
486
  config: IConfiguration;
472
487
  evtNamespace(): string;
@@ -489,6 +504,22 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
489
504
  stopPollingInternalLogs?(): void;
490
505
  // (undocumented)
491
506
  track(telemetryItem: ITelemetryItem): void;
507
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
508
+ }
509
+
510
+ // @public (undocumented)
511
+ export interface IBaseProcessingContext {
512
+ core: () => IAppInsightsCore;
513
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
514
+ diagLog: () => IDiagnosticLogger;
515
+ getCfg: () => IConfiguration;
516
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
517
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
518
+ getNext: () => ITelemetryPluginChain;
519
+ hasNext: () => boolean;
520
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
521
+ onComplete: (onComplete: Function, that?: any, ...args: any[]) => void;
522
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
492
523
  }
493
524
 
494
525
  // @public
@@ -677,6 +708,7 @@ export interface IInstrumentHooks {
677
708
  export interface IInstrumentHooksCallbacks {
678
709
  fnErr?: InstrumentorHooksCallback;
679
710
  hkErr?: InstrumentorHooksCallback;
711
+ ns?: string | string[];
680
712
  req?: InstrumentorHooksCallback;
681
713
  rsp?: InstrumentorHooksCallback;
682
714
  }
@@ -858,14 +890,24 @@ export interface IPlugin {
858
890
  readonly version?: string;
859
891
  }
860
892
 
861
- // Warning: (ae-forgotten-export) The symbol "IBaseProcessingContext" needs to be exported by the entry point applicationinsights-core-js.d.ts
862
- //
863
893
  // @public
864
894
  export interface IProcessTelemetryContext extends IBaseProcessingContext {
865
895
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
866
896
  processNext: (env: ITelemetryItem) => boolean | void;
867
897
  }
868
898
 
899
+ // @public
900
+ export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
901
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
902
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
903
+ }
904
+
905
+ // @public
906
+ export interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
907
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
908
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
909
+ }
910
+
869
911
  // @public (undocumented)
870
912
  export interface _IRegisteredEvents {
871
913
  // (undocumented)
@@ -989,12 +1031,25 @@ export interface ITelemetryUnloadState {
989
1031
  flushComplete?: boolean;
990
1032
  // (undocumented)
991
1033
  isAsync: boolean;
992
- // Warning: (ae-forgotten-export) The symbol "TelemetryUnloadReason" needs to be exported by the entry point applicationinsights-core-js.d.ts
993
- //
994
1034
  // (undocumented)
995
1035
  reason: TelemetryUnloadReason;
996
1036
  }
997
1037
 
1038
+ // @public (undocumented)
1039
+ export interface ITelemetryUpdateState {
1040
+ added?: IPlugin[];
1041
+ reason: TelemetryUpdateReason;
1042
+ removed?: IPlugin[];
1043
+ }
1044
+
1045
+ // @public (undocumented)
1046
+ export interface IUnloadHandlerContainer {
1047
+ // (undocumented)
1048
+ add: (handler: UnloadHandler) => void;
1049
+ // (undocumented)
1050
+ run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
1051
+ }
1052
+
998
1053
  // @public
999
1054
  export function _legacyCookieMgr(config?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr;
1000
1055
 
@@ -1047,7 +1102,10 @@ export { objCreate }
1047
1102
  export function objDefineAccessors<T>(target: any, prop: string, getProp?: () => T, setProp?: (v: T) => void): boolean;
1048
1103
 
1049
1104
  // @public
1050
- export function objExtend<T1, T2, T3, T4, T5, T6>(obj?: boolean | T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6;
1105
+ export function objExtend<T2, T3, T4, T5, T6>(deepExtend?: boolean, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T2 & T3 & T4 & T5 & T6;
1106
+
1107
+ // @public (undocumented)
1108
+ export function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6;
1051
1109
 
1052
1110
  // @public
1053
1111
  export function objForEachKey<T = any>(target: T, callbackfn: (name: string, value: T[keyof T]) => void): void;
@@ -1158,6 +1216,7 @@ export const enum SendRequestReason {
1158
1216
  NormalSchedule = 1,
1159
1217
  Resumed = 4,
1160
1218
  Retry = 5,
1219
+ SdkUnload = 6,
1161
1220
  SyncEvent = 3,
1162
1221
  Undefined = 0,
1163
1222
  Unload = 2
@@ -1213,9 +1272,27 @@ export interface Tags {
1213
1272
  // @public (undocumented)
1214
1273
  export type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
1215
1274
 
1275
+ // @public
1276
+ export const enum TelemetryUnloadReason {
1277
+ ManualTeardown = 0,
1278
+ PluginReplace = 2,
1279
+ PluginUnload = 1,
1280
+ SdkUnload = 50
1281
+ }
1282
+
1283
+ // @public
1284
+ export const enum TelemetryUpdateReason {
1285
+ PluginAdded = 16,
1286
+ PluginRemoved = 32,
1287
+ Unknown = 0
1288
+ }
1289
+
1216
1290
  // @public (undocumented)
1217
1291
  export function throwError(message: string): never;
1218
1292
 
1293
+ // @public
1294
+ export function _throwInternal(logger: IDiagnosticLogger, severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
1295
+
1219
1296
  // @public
1220
1297
  export function toISOString(date: Date): string;
1221
1298
 
@@ -1225,6 +1302,9 @@ export function uaDisallowsSameSiteNone(userAgent: string): boolean;
1225
1302
  // @public (undocumented)
1226
1303
  export const Undefined = "undefined";
1227
1304
 
1305
+ // @public (undocumented)
1306
+ export type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
1307
+
1228
1308
  // @public (undocumented)
1229
1309
  export function useXDomainRequest(): boolean | undefined;
1230
1310
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights Core Javascript SDK, 2.8.0-beta.2203-02
2
+ * Microsoft Application Insights Core Javascript SDK, 2.8.0-beta.2203-05
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -18,9 +18,11 @@ declare namespace ApplicationInsights {
18
18
  * Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by
19
19
  * applications to remove their own events
20
20
  * @param target - The EventTarget that has registered events
21
- * @param evtName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
21
+ * @param eventName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
22
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
23
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
22
24
  */
23
- function __getRegisteredEvents(target: any, evtName?: string): _IRegisteredEvents[];
25
+ function __getRegisteredEvents(target: any, eventName?: string, evtNamespace?: string | string[]): _IRegisteredEvents[];
24
26
 
25
27
  /**
26
28
  * Trys to add an event handler for the specified event to the window, body and document
@@ -189,12 +191,34 @@ declare namespace ApplicationInsights {
189
191
  * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
190
192
  */
191
193
  addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
194
+ /**
195
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
196
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
197
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
198
+ * approach is to create a new instance and initialize that instance.
199
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
200
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
201
+ */
202
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
192
203
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
204
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
193
205
  /**
194
206
  * Returns the unique event namespace that should be used
195
207
  */
196
208
  evtNamespace(): string;
209
+ /**
210
+ * Add an unload handler that will be called when the SDK is being unloaded
211
+ * @param handler - the handler
212
+ */
213
+ addUnloadCb(handler: UnloadHandler): void;
197
214
  protected releaseQueue(): void;
215
+ /**
216
+ * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
217
+ * @param updateCtx - The plugin update context
218
+ * @param updateState - The Update State
219
+ * @returns boolean - True means the extension class will call updateState otherwise the Core will
220
+ */
221
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
198
222
  }
199
223
 
200
224
  /**
@@ -251,6 +275,14 @@ declare namespace ApplicationInsights {
251
275
  * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
252
276
  */
253
277
  protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
278
+ /**
279
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
280
+ * @param updateCtx - This is the context that should be used during updating.
281
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
282
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async update operations.
283
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
284
+ */
285
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
254
286
  constructor();
255
287
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
256
288
  /**
@@ -263,6 +295,18 @@ declare namespace ApplicationInsights {
263
295
  */
264
296
  teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
265
297
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
298
+ /**
299
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
300
+ * @param updateCtx - This is the context that should be used during updating.
301
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
302
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
303
+ */
304
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
305
+ /**
306
+ * Add an unload handler that will be called when the SDK is being unloaded
307
+ * @param handler - the handler
308
+ */
309
+ protected _addUnloadCb(handler: UnloadHandler): void;
266
310
  /**
267
311
  * Add this hook so that it is automatically removed during unloading
268
312
  * @param hooks - The single hook or an array of IInstrumentHook objects
@@ -305,11 +349,17 @@ declare namespace ApplicationInsights {
305
349
  * @param plugins - The plugin instances that will be executed
306
350
  * @param config - The current config
307
351
  * @param core - The current core instance
352
+ * @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
353
  */
309
354
  function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
310
355
 
311
356
  function createUniqueNamespace(name: string, includeVersion?: boolean): string;
312
357
 
358
+ function createUnloadHandlerContainer(): {
359
+ add: (handler: UnloadHandler) => void;
360
+ run: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
361
+ };
362
+
313
363
  /**
314
364
  * 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
365
  * https://caniuse.com/#search=Date.now
@@ -781,15 +831,36 @@ declare namespace ApplicationInsights {
781
831
  * Return a new instance of the IProcessTelemetryContext for processing events
782
832
  */
783
833
  getProcessTelContext(): IProcessTelemetryContext;
834
+ /**
835
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
836
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
837
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
838
+ * approach is to create a new instance and initialize that instance.
839
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
840
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
841
+ */
842
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
784
843
  /**
785
844
  * Find and return the (first) plugin with the specified identifier if present
786
845
  * @param pluginIdentifier
787
846
  */
788
847
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
848
+ /**
849
+ * Add a new plugin to the installation
850
+ * @param plugin - The new plugin to add
851
+ * @param replaceExisting - should any existing plugin be replaced
852
+ * @param doAsync - Should the add be performed asynchronously
853
+ */
854
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
789
855
  /**
790
856
  * Returns the unique event namespace that should be used when registering events
791
857
  */
792
858
  evtNamespace(): string;
859
+ /**
860
+ * Add a handler that will be called when the SDK is being unloaded
861
+ * @param handler - the handler
862
+ */
863
+ addUnloadCb(handler: UnloadHandler): void;
793
864
  }
794
865
 
795
866
  interface IBaseProcessingContext {
@@ -1457,6 +1528,11 @@ declare namespace ApplicationInsights {
1457
1528
  * You must always supply the error callback
1458
1529
  */
1459
1530
  interface IInstrumentHooksCallbacks {
1531
+ /**
1532
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
1533
+ * identify the source of the instrumented hooks
1534
+ */
1535
+ ns?: string | string[];
1460
1536
  /**
1461
1537
  * The hook callback to call before the original function is called
1462
1538
  */
@@ -1491,6 +1567,7 @@ declare namespace ApplicationInsights {
1491
1567
  * (unless it's also been re-initialized)
1492
1568
  */
1493
1569
  setEnabled: (isEnabled: boolean) => void;
1570
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1494
1571
  }
1495
1572
 
1496
1573
  /**
@@ -1870,8 +1947,8 @@ declare namespace ApplicationInsights {
1870
1947
  }
1871
1948
 
1872
1949
  /**
1873
- * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1874
- * between multiple AppInsights instances
1950
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
1951
+ * or the SDK is being unloaded.
1875
1952
  */
1876
1953
  interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1877
1954
  /**
@@ -1890,6 +1967,27 @@ declare namespace ApplicationInsights {
1890
1967
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
1891
1968
  }
1892
1969
 
1970
+ /**
1971
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
1972
+ * for when plugins are added, removed or the configuration was changed.
1973
+ */
1974
+ interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1975
+ /**
1976
+ * This Plugin has finished unloading, so unload the next one
1977
+ * @param updateState - The update State
1978
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1979
+ */
1980
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1981
+ /**
1982
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1983
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1984
+ * then the current execution order will be copied.
1985
+ * @param startAt - The plugin to start processing from, if missing from the execution
1986
+ * order then the next plugin will be NOT set.
1987
+ */
1988
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
1989
+ }
1990
+
1893
1991
  interface _IRegisteredEvents {
1894
1992
  name: string;
1895
1993
  handler: any;
@@ -2094,6 +2192,15 @@ declare namespace ApplicationInsights {
2094
2192
  * to later plugins (vs appending items to the telemetry item)
2095
2193
  */
2096
2194
  processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2195
+ /**
2196
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
2197
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
2198
+ * the configuration has bee updated.
2199
+ * @param updateCtx - This is the context that should be used during updating.
2200
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
2201
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
2202
+ */
2203
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
2097
2204
  }
2098
2205
 
2099
2206
  interface ITelemetryUnloadState {
@@ -2102,6 +2209,32 @@ declare namespace ApplicationInsights {
2102
2209
  flushComplete?: boolean;
2103
2210
  }
2104
2211
 
2212
+ interface ITelemetryUpdateState {
2213
+ /**
2214
+ * Identifies the reason for the update notification, this is a bitwise numeric value
2215
+ */
2216
+ reason: TelemetryUpdateReason;
2217
+ /**
2218
+ * If this is a configuration update this was the previous configuration that was used
2219
+ */
2220
+ /**
2221
+ * If this is a configuration update is the new configuration that is being used
2222
+ */
2223
+ /**
2224
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2225
+ */
2226
+ added?: IPlugin[];
2227
+ /**
2228
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
2229
+ */
2230
+ removed?: IPlugin[];
2231
+ }
2232
+
2233
+ interface IUnloadHandlerContainer {
2234
+ add: (handler: UnloadHandler) => void;
2235
+ run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2236
+ }
2237
+
2105
2238
  /**
2106
2239
  * Helper to support backward compatibility for users that use the legacy cookie handling functions and the use the internal
2107
2240
  * CoreUtils._canUseCookies global flag to enable/disable cookies usage.
@@ -2223,7 +2356,9 @@ declare namespace ApplicationInsights {
2223
2356
  * @param obj5 - object to merge.
2224
2357
  * @returns The extended first object.
2225
2358
  */
2226
- function objExtend<T1, T2, T3, T4, T5, T6>(obj?: boolean | T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6;
2359
+ function objExtend<T2, T3, T4, T5, T6>(deepExtend?: boolean, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T2 & T3 & T4 & T5 & T6;
2360
+
2361
+ function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6;
2227
2362
 
2228
2363
  /**
2229
2364
  * This is a helper function for the equivalent of arForEach(objKeys(target), callbackFn), this is a
@@ -2522,6 +2657,10 @@ declare namespace ApplicationInsights {
2522
2657
  * The event(s) being sent as a retry
2523
2658
  */
2524
2659
  Retry = 5,
2660
+ /**
2661
+ * The SDK is unloading
2662
+ */
2663
+ SdkUnload = 6,
2525
2664
  /**
2526
2665
  * Maximum batch size would be exceeded
2527
2666
  */
@@ -2617,11 +2756,55 @@ declare namespace ApplicationInsights {
2617
2756
  /**
2618
2757
  * Teardown has been called without any context.
2619
2758
  */
2620
- ManualTeardown = 0
2759
+ ManualTeardown = 0,
2760
+ /**
2761
+ * Just this plugin is being removed
2762
+ */
2763
+ PluginUnload = 1,
2764
+ /**
2765
+ * This instance of the plugin is being removed and replaced
2766
+ */
2767
+ PluginReplace = 2,
2768
+ /**
2769
+ * The entire SDK is being unloaded
2770
+ */
2771
+ SdkUnload = 50
2772
+ }
2773
+
2774
+ /**
2775
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
2776
+ */
2777
+ const enum TelemetryUpdateReason {
2778
+ /**
2779
+ * Unknown.
2780
+ */
2781
+ Unknown = 0,
2782
+ /**
2783
+ * The configuration has ben updated or changed
2784
+ */
2785
+ /**
2786
+ * One or more plugins have been added
2787
+ */
2788
+ PluginAdded = 16,
2789
+ /**
2790
+ * One or more plugins have been removed
2791
+ */
2792
+ PluginRemoved = 32
2621
2793
  }
2622
2794
 
2623
2795
  function throwError(message: string): never;
2624
2796
 
2797
+ /**
2798
+ * This is a helper method which will call throwInternal on the passed logger, will throw exceptions in
2799
+ * debug mode or attempt to log the error as a console warning. This helper is provided mostly to better
2800
+ * support minification as logger.throwInternal() will not compress the publish "throwInternal" used throughout
2801
+ * the code.
2802
+ * @param logger - The Diagnostic Logger instance to use.
2803
+ * @param severity {LoggingSeverity} - The severity of the log message
2804
+ * @param message {_InternalLogMessage} - The log message.
2805
+ */
2806
+ function _throwInternal(logger: IDiagnosticLogger, severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
2807
+
2625
2808
  /**
2626
2809
  * Convert a date to I.S.O. format in IE8
2627
2810
  */
@@ -2631,6 +2814,8 @@ declare namespace ApplicationInsights {
2631
2814
 
2632
2815
  const Undefined = "undefined";
2633
2816
 
2817
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2818
+
2634
2819
  function useXDomainRequest(): boolean | undefined;
2635
2820
 
2636
2821