@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.
Files changed (80) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +197 -10
  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 +751 -33
  7. package/dist/applicationinsights-core-js.api.md +26 -0
  8. package/dist/applicationinsights-core-js.d.ts +73 -2
  9. package/dist/applicationinsights-core-js.js +197 -10
  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 +73 -2
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +183 -10
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +8 -2
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  19. package/dist-esm/JavaScriptSDK/ChannelController.js +1 -1
  20. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  21. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  22. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  23. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +1 -1
  24. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  25. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  26. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  27. package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
  28. package/dist-esm/JavaScriptSDK/HelperFuncs.js +2 -2
  29. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  31. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  32. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  33. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  34. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +16 -2
  35. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  37. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
  38. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
  39. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +32 -0
  40. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  41. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  42. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  43. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  44. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  45. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  46. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  62. package/dist-esm/applicationinsights-core-js.js +2 -1
  63. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/JavaScriptSDK/BaseCore.ts +233 -10
  66. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +16 -2
  67. package/src/JavaScriptSDK/HelperFuncs.ts +1 -1
  68. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +16 -2
  69. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +44 -0
  70. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  71. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +3 -3
  72. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +29 -2
  73. package/types/JavaScriptSDK/BaseCore.d.ts +17 -1
  74. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +6 -0
  75. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +2 -0
  76. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  77. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  78. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +13 -1
  79. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +24 -1
  80. package/types/applicationinsights-core-js.d.ts +1 -0
@@ -12,8 +12,9 @@ import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
12
12
  import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
13
13
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
14
14
  import { createProcessTelemetryContext, createProcessTelemetryUnloadContext } from "./ProcessTelemetryContext";
15
- import { arrForEach, isArray, isFunction, isNullOrUndefined, setValue } from "./HelperFuncs";
15
+ import { arrForEach, isArray, isFunction, isNullOrUndefined, proxyFunctionAs, setValue } from "./HelperFuncs";
16
16
  import { strExtensionConfig } from "./Constants";
17
+ import { createUnloadHandlerContainer, IUnloadHandlerContainer, UnloadHandler } from "./UnloadHandlerContainer";
17
18
  import { IInstrumentHook } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
18
19
  import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
19
20
  import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
@@ -93,6 +94,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
93
94
  let _isinitialized: boolean;
94
95
  let _rootCtx: IProcessTelemetryContext; // Used as the root context, holding the current config and initialized core
95
96
  let _nextPlugin: ITelemetryPlugin | ITelemetryPluginChain; // Used for backward compatibility where plugins don't call the main pipeline
97
+ let _unloadHandlerContainer: IUnloadHandlerContainer;
96
98
  let _hooks: IInstrumentHook[];
97
99
 
98
100
  _initDefaults();
@@ -120,11 +122,12 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
120
122
  isAsync: false
121
123
  };
122
124
 
123
-
124
125
  function _unloadCallback() {
125
126
  if (!unloadDone) {
126
127
  unloadDone = true;
127
128
 
129
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
130
+
128
131
  // Remove all instrumentation hooks
129
132
  arrForEach(_hooks, (fn) => {
130
133
  fn.rm();
@@ -158,6 +161,8 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
158
161
  }
159
162
  }
160
163
  };
164
+
165
+ proxyFunctionAs(_self, "_addUnloadCb", () => _unloadHandlerContainer, "add");
161
166
  });
162
167
 
163
168
  // These are added after the dynamicProto so that are not moved to the prototype
@@ -240,6 +245,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
240
245
  _rootCtx = null;
241
246
  _nextPlugin = null;
242
247
  _hooks = [];
248
+ _unloadHandlerContainer = createUnloadHandlerContainer();
243
249
  }
244
250
  }
245
251
 
@@ -262,6 +268,14 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
262
268
 
263
269
  public abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
264
270
 
271
+ /**
272
+ * Add an unload handler that will be called when the SDK is being unloaded
273
+ * @param handler - the handler
274
+ */
275
+ protected _addUnloadCb(handler: UnloadHandler): void {
276
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
277
+ }
278
+
265
279
  /**
266
280
  * Add this hook so that it is automatically removed during unloading
267
281
  * @param hooks - The single hook or an array of IInstrumentHook objects
@@ -836,7 +836,7 @@ export function createEnumStyle<T>(values: T) {
836
836
  enumClass[field] = value;
837
837
  // Add Reverse lookup
838
838
  if (!isUndefined(enumClass[value])) {
839
- throwError("Value: [" + value + "] already exists for " + field);
839
+ throwError("[" + value + "] exists for " + field);
840
840
  }
841
841
  enumClass[value] = field;
842
842
  });
@@ -55,12 +55,25 @@ function _getNextProxyStart(proxy: ITelemetryPluginChain, config: IConfiguration
55
55
  return createTelemetryProxyChain([startAt], config, core);
56
56
  }
57
57
 
58
+ /**
59
+ * @ignore
60
+ * @param telemetryChain
61
+ * @param config
62
+ * @param core
63
+ * @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
64
+ * @returns
65
+ */
58
66
  function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IInternalContext<T> {
59
67
  // We have a special case where we want to start execution from this specific plugin
60
68
  // or we simply reuse the existing telemetry plugin chain (normal execution case)
61
- let _nextProxy: ITelemetryPluginChain = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
69
+ let _nextProxy: ITelemetryPluginChain = null; // By Default set as no next plugin
62
70
  let _onComplete: OnCompleteCallback[] = [];
63
71
 
72
+ if (startAt !== null) {
73
+ // There is no next element (null) vs not defined (undefined) so use the full chain
74
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
75
+ }
76
+
64
77
  let context: IInternalContext<T> = {
65
78
  _next: _moveNext,
66
79
  ctx: {
@@ -192,9 +205,9 @@ function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain
192
205
  * @param plugins - The plugin instances that will be executed
193
206
  * @param config - The current config
194
207
  * @param core - The current core instance
208
+ * @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
195
209
  */
196
210
  export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext {
197
-
198
211
  let internalContext: IInternalContext<IProcessTelemetryContext> = _createInternalContext<IProcessTelemetryContext>(telemetryChain, config, core, startAt);
199
212
  let context = internalContext.ctx;
200
213
 
@@ -225,6 +238,7 @@ export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginCh
225
238
  * @param plugins - The plugin instances that will be executed
226
239
  * @param config - The current config
227
240
  * @param core - The current core instance
241
+ * @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
228
242
  */
229
243
  export function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUnloadContext {
230
244
  let internalContext: IInternalContext<IProcessTelemetryUnloadContext> = _createInternalContext<IProcessTelemetryUnloadContext>(telemetryChain, config, core, startAt);
@@ -0,0 +1,44 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { eLoggingSeverity, _eInternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
5
+ import { IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
+ import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
7
+ import { dumpObj } from "./EnvUtils";
8
+ import { arrForEach } from "./HelperFuncs";
9
+
10
+ export type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
11
+
12
+ export interface IUnloadHandlerContainer {
13
+ add: (handler: UnloadHandler) => void;
14
+ run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void
15
+ }
16
+
17
+ export function createUnloadHandlerContainer() {
18
+ let handlers: UnloadHandler[] = [];
19
+
20
+ function _addHandler(handler: UnloadHandler) {
21
+ if (handler) {
22
+ handlers.push(handler);
23
+ }
24
+ }
25
+
26
+ function _runHandlers(unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) {
27
+ arrForEach(handlers, (handler) => {
28
+ try {
29
+ handler(unloadCtx, unloadState);
30
+ } catch (e) {
31
+ unloadCtx.diagLog().throwInternal(
32
+ eLoggingSeverity.WARNING,
33
+ _eInternalMessageId.PluginException,
34
+ "Unexpected error calling unload handler - " + dumpObj(e));
35
+ }
36
+ });
37
+ handlers = [];
38
+ }
39
+
40
+ return {
41
+ add: _addHandler,
42
+ run: _runHandlers
43
+ }
44
+ }
@@ -38,6 +38,11 @@ export const enum SendRequestReason {
38
38
  * The event(s) being sent as a retry
39
39
  */
40
40
  Retry = 5,
41
+
42
+ /**
43
+ * The SDK is unloading
44
+ */
45
+ SdkUnload = 6,
41
46
 
42
47
  /**
43
48
  * Maximum batch size would be exceeded
@@ -13,15 +13,15 @@
13
13
  /**
14
14
  * Just this plugin is being removed
15
15
  */
16
- //PluginUnload = 1,
16
+ PluginUnload = 1,
17
17
 
18
18
  /**
19
19
  * This instance of the plugin is being removed and replaced
20
20
  */
21
- //PluginReplace = 2,
21
+ PluginReplace = 2,
22
22
 
23
23
  /**
24
24
  * The entire SDK is being unloaded
25
25
  */
26
- //SdkUnload = 50
26
+ SdkUnload = 50
27
27
  }
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
  import { ITelemetryItem } from "./ITelemetryItem";
4
4
  import { IChannelControls } from "./IChannelControls";
5
- import { IPlugin } from "./ITelemetryPlugin";
5
+ import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
6
6
  import { IConfiguration } from "./IConfiguration";
7
7
  import { INotificationManager } from "./INotificationManager";
8
8
  import { INotificationListener } from "./INotificationListener";
@@ -11,6 +11,7 @@ import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
11
11
  import { IPerfManagerProvider } from "./IPerfManager";
12
12
  import { ICookieMgr } from "./ICookieMgr";
13
13
  import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./ITelemetryInitializers";
14
+ import { UnloadHandler } from "../applicationinsights-core-js";
14
15
 
15
16
  export interface ILoadedPlugin<T extends IPlugin> {
16
17
  plugin: T;
@@ -29,6 +30,8 @@ export interface ILoadedPlugin<T extends IPlugin> {
29
30
  * (unless it's also been re-initialized)
30
31
  */
31
32
  setEnabled: (isEnabled: boolean) => void;
33
+
34
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
32
35
  }
33
36
 
34
37
  export interface IAppInsightsCore extends IPerfManagerProvider {
@@ -106,14 +109,38 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
106
109
  */
107
110
  getProcessTelContext() : IProcessTelemetryContext;
108
111
 
112
+ /**
113
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
114
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
115
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
116
+ * approach is to create a new instance and initialize that instance.
117
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
118
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
119
+ */
120
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
121
+
109
122
  /**
110
123
  * Find and return the (first) plugin with the specified identifier if present
111
124
  * @param pluginIdentifier
112
125
  */
113
126
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
114
127
 
128
+ /**
129
+ * Add a new plugin to the installation
130
+ * @param plugin - The new plugin to add
131
+ * @param replaceExisting - should any existing plugin be replaced
132
+ * @param doAsync - Should the add be performed asynchronously
133
+ */
134
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
135
+
115
136
  /**
116
137
  * Returns the unique event namespace that should be used when registering events
117
138
  */
118
139
  evtNamespace(): string;
119
- }
140
+
141
+ /**
142
+ * Add a handler that will be called when the SDK is being unloaded
143
+ * @param handler - the handler
144
+ */
145
+ addUnloadCb(handler: UnloadHandler): void;
146
+ }
@@ -1,6 +1,6 @@
1
1
  import { IAppInsightsCore, ILoadedPlugin } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
2
2
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
- import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
3
+ import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
4
4
  import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
6
  import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
@@ -10,6 +10,7 @@ import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTe
10
10
  import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
11
11
  import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
12
12
  import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
13
+ import { UnloadHandler } from "./UnloadHandlerContainer";
13
14
  export declare class BaseCore implements IAppInsightsCore {
14
15
  static defaultConfig: IConfiguration;
15
16
  config: IConfiguration;
@@ -60,10 +61,25 @@ export declare class BaseCore implements IAppInsightsCore {
60
61
  * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
61
62
  */
62
63
  addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
64
+ /**
65
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
66
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
67
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
68
+ * approach is to create a new instance and initialize that instance.
69
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
70
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
71
+ */
72
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
63
73
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
74
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
64
75
  /**
65
76
  * Returns the unique event namespace that should be used
66
77
  */
67
78
  evtNamespace(): string;
79
+ /**
80
+ * Add an unload handler that will be called when the SDK is being unloaded
81
+ * @param handler - the handler
82
+ */
83
+ addUnloadCb(handler: UnloadHandler): void;
68
84
  protected releaseQueue(): void;
69
85
  }
@@ -5,6 +5,7 @@ import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetr
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
6
  import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
+ import { UnloadHandler } from "./UnloadHandlerContainer";
8
9
  import { IInstrumentHook } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
9
10
  import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
10
11
  /**
@@ -73,6 +74,11 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
73
74
  */
74
75
  teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
75
76
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
77
+ /**
78
+ * Add an unload handler that will be called when the SDK is being unloaded
79
+ * @param handler - the handler
80
+ */
81
+ protected _addUnloadCb(handler: UnloadHandler): void;
76
82
  /**
77
83
  * Add this hook so that it is automatically removed during unloading
78
84
  * @param hooks - The single hook or an array of IInstrumentHook objects
@@ -10,6 +10,7 @@ import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger
10
10
  * @param plugins - The plugin instances that will be executed
11
11
  * @param config - The current config
12
12
  * @param core - The current core instance
13
+ * @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
13
14
  */
14
15
  export declare function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
15
16
  /**
@@ -17,6 +18,7 @@ export declare function createProcessTelemetryContext(telemetryChain: ITelemetry
17
18
  * @param plugins - The plugin instances that will be executed
18
19
  * @param config - The current config
19
20
  * @param core - The current core instance
21
+ * @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
20
22
  */
21
23
  export declare function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUnloadContext;
22
24
  /**
@@ -0,0 +1,11 @@
1
+ import { IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
2
+ import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
3
+ export declare type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
4
+ export interface IUnloadHandlerContainer {
5
+ add: (handler: UnloadHandler) => void;
6
+ run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
7
+ }
8
+ export declare function createUnloadHandlerContainer(): {
9
+ add: (handler: UnloadHandler) => void;
10
+ run: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
11
+ };
@@ -30,6 +30,10 @@ export declare const enum SendRequestReason {
30
30
  * The event(s) being sent as a retry
31
31
  */
32
32
  Retry = 5,
33
+ /**
34
+ * The SDK is unloading
35
+ */
36
+ SdkUnload = 6,
33
37
  /**
34
38
  * Maximum batch size would be exceeded
35
39
  */
@@ -5,5 +5,17 @@ export declare const enum TelemetryUnloadReason {
5
5
  /**
6
6
  * Teardown has been called without any context.
7
7
  */
8
- ManualTeardown = 0
8
+ ManualTeardown = 0,
9
+ /**
10
+ * Just this plugin is being removed
11
+ */
12
+ PluginUnload = 1,
13
+ /**
14
+ * This instance of the plugin is being removed and replaced
15
+ */
16
+ PluginReplace = 2,
17
+ /**
18
+ * The entire SDK is being unloaded
19
+ */
20
+ SdkUnload = 50
9
21
  }
@@ -1,6 +1,6 @@
1
1
  import { ITelemetryItem } from "./ITelemetryItem";
2
2
  import { IChannelControls } from "./IChannelControls";
3
- import { IPlugin } from "./ITelemetryPlugin";
3
+ import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
4
4
  import { IConfiguration } from "./IConfiguration";
5
5
  import { INotificationManager } from "./INotificationManager";
6
6
  import { INotificationListener } from "./INotificationListener";
@@ -9,6 +9,7 @@ import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
9
9
  import { IPerfManagerProvider } from "./IPerfManager";
10
10
  import { ICookieMgr } from "./ICookieMgr";
11
11
  import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./ITelemetryInitializers";
12
+ import { UnloadHandler } from "../applicationinsights-core-js";
12
13
  export interface ILoadedPlugin<T extends IPlugin> {
13
14
  plugin: T;
14
15
  /**
@@ -24,6 +25,7 @@ export interface ILoadedPlugin<T extends IPlugin> {
24
25
  * (unless it's also been re-initialized)
25
26
  */
26
27
  setEnabled: (isEnabled: boolean) => void;
28
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
27
29
  }
28
30
  export interface IAppInsightsCore extends IPerfManagerProvider {
29
31
  config: IConfiguration;
@@ -72,13 +74,34 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
72
74
  * Return a new instance of the IProcessTelemetryContext for processing events
73
75
  */
74
76
  getProcessTelContext(): IProcessTelemetryContext;
77
+ /**
78
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
79
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
80
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
81
+ * approach is to create a new instance and initialize that instance.
82
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
83
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
84
+ */
85
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
75
86
  /**
76
87
  * Find and return the (first) plugin with the specified identifier if present
77
88
  * @param pluginIdentifier
78
89
  */
79
90
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
91
+ /**
92
+ * Add a new plugin to the installation
93
+ * @param plugin - The new plugin to add
94
+ * @param replaceExisting - should any existing plugin be replaced
95
+ * @param doAsync - Should the add be performed asynchronously
96
+ */
97
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
80
98
  /**
81
99
  * Returns the unique event namespace that should be used when registering events
82
100
  */
83
101
  evtNamespace(): string;
102
+ /**
103
+ * Add a handler that will be called when the SDK is being unloaded
104
+ * @param handler - the handler
105
+ */
106
+ addUnloadCb(handler: UnloadHandler): void;
84
107
  }
@@ -36,4 +36,5 @@ export { IDbgExtension } from "./JavaScriptSDK.Interfaces/IDbgExtension";
36
36
  export { getDebugListener, getDebugExt } from "./JavaScriptSDK/DbgExtensionUtils";
37
37
  export { TelemetryInitializerFunction, ITelemetryInitializerHandler, ITelemetryInitializerContainer } from "./JavaScriptSDK.Interfaces/ITelemetryInitializers";
38
38
  export { createUniqueNamespace } from "./JavaScriptSDK/DataCacheHelper";
39
+ export { UnloadHandler, IUnloadHandlerContainer, createUnloadHandlerContainer } from "./JavaScriptSDK/UnloadHandlerContainer";
39
40
  export { ITelemetryUnloadState } from "./JavaScriptSDK.Interfaces/ITelemetryUnloadState";