@microsoft/applicationinsights-core-js 2.8.0-beta.2203-01 → 2.8.0-beta.2203-04

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 (128) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1137 -484
  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 +6529 -2784
  7. package/dist/applicationinsights-core-js.api.md +290 -30
  8. package/dist/applicationinsights-core-js.d.ts +481 -89
  9. package/dist/applicationinsights-core-js.js +1137 -484
  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 +481 -89
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +248 -32
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +50 -5
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  19. package/dist-esm/JavaScriptSDK/ChannelController.js +105 -73
  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 -4
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +6 -122
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  26. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
  27. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
  28. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  29. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +12 -12
  30. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  31. package/dist-esm/JavaScriptSDK/EnvUtils.js +8 -7
  32. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  33. package/dist-esm/JavaScriptSDK/EventHelpers.js +472 -0
  34. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
  35. package/dist-esm/JavaScriptSDK/HelperFuncs.js +32 -59
  36. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  37. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  38. package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
  39. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
  40. package/dist-esm/JavaScriptSDK/NotificationManager.js +8 -11
  41. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  42. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  43. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +195 -107
  44. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/RandomHelper.js +3 -2
  46. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  47. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +32 -13
  48. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  49. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +4 -6
  50. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
  51. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +32 -0
  52. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  53. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  55. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  56. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  58. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  59. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  75. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  77. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  78. package/dist-esm/applicationinsights-core-js.js +9 -4
  79. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/JavaScriptSDK/BaseCore.ts +312 -33
  82. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +90 -5
  83. package/src/JavaScriptSDK/ChannelController.ts +107 -61
  84. package/src/JavaScriptSDK/CookieMgr.ts +4 -4
  85. package/src/JavaScriptSDK/CoreUtils.ts +6 -143
  86. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  87. package/src/JavaScriptSDK/DiagnosticLogger.ts +12 -11
  88. package/src/JavaScriptSDK/EnvUtils.ts +7 -6
  89. package/src/JavaScriptSDK/EventHelpers.ts +542 -0
  90. package/src/JavaScriptSDK/HelperFuncs.ts +35 -54
  91. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  92. package/src/JavaScriptSDK/NotificationManager.ts +7 -11
  93. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +248 -121
  94. package/src/JavaScriptSDK/RandomHelper.ts +2 -1
  95. package/src/JavaScriptSDK/TelemetryHelpers.ts +47 -15
  96. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +5 -15
  97. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +44 -0
  98. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
  99. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  100. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  101. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +49 -2
  102. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +9 -2
  103. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +55 -16
  104. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +16 -9
  105. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  106. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  107. package/types/JavaScriptSDK/BaseCore.d.ts +21 -1
  108. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +26 -1
  109. package/types/JavaScriptSDK/ChannelController.d.ts +4 -0
  110. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -42
  111. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  112. package/types/JavaScriptSDK/EventHelpers.d.ts +152 -0
  113. package/types/JavaScriptSDK/HelperFuncs.d.ts +8 -17
  114. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  115. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +12 -3
  116. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +8 -0
  117. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -7
  118. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  119. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
  120. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  121. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
  122. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +41 -1
  123. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +9 -2
  124. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +49 -14
  125. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +15 -8
  126. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  127. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  128. package/types/applicationinsights-core-js.d.ts +7 -3
@@ -2,7 +2,7 @@ import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
2
2
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
3
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
4
4
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
- import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
5
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
6
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
7
7
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
8
8
  /**
@@ -10,8 +10,17 @@ 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;
16
+ /**
17
+ * Creates a new Telemetry Item context with the current config, core and plugin execution chain for handling the unloading of the chain
18
+ * @param plugins - The plugin instances that will be executed
19
+ * @param config - The current config
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
22
+ */
23
+ export declare function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUnloadContext;
15
24
  /**
16
25
  * Creates an execution chain from the array of plugins
17
26
  * @param plugins - The array of plugins that will be executed in this order
@@ -70,15 +79,15 @@ export declare class ProcessTelemetryContext implements IProcessTelemetryContext
70
79
  * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
71
80
  * can optionally use this to access the current core instance or define / pass additional information
72
81
  * to later plugins (vs appending items to the telemetry item)
82
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
73
83
  */
74
- processNext: (env: ITelemetryItem) => void;
84
+ processNext: (env: ITelemetryItem) => boolean | void;
75
85
  /**
76
86
  * Synchronously iterate over the context chain running the callback for each plugin, once
77
87
  * every plugin has been executed via the callback, any associated onComplete will be called.
78
88
  * @param callback - The function call for each plugin in the context chain
79
89
  */
80
90
  iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
81
- /**
82
91
  /**
83
92
  * Create a new context using the core and config from the current instance
84
93
  * @param plugins - The execution order to process the plugins, if null or not supplied
@@ -1,5 +1,13 @@
1
1
  import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
2
2
  import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
3
+ import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
4
+ export interface IPluginState {
5
+ core?: IAppInsightsCore;
6
+ isInitialized?: boolean;
7
+ tearDown?: boolean;
8
+ disabled?: boolean;
9
+ }
10
+ export declare function _getPluginState(plugin: IPlugin): IPluginState;
3
11
  /**
4
12
  * Initialize the queue of plugins
5
13
  * @param plugins - The array of plugins to initialize and setting of the next plugin
@@ -13,11 +13,4 @@ export declare class TelemetryInitializerPlugin extends BaseTelemetryPlugin impl
13
13
  */
14
14
  addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler;
15
15
  processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
16
- /**
17
- * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
18
- * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
19
- * @param itemCtx - This is the context that should be used during unloading if required to flush any cached events.
20
- * @param isAsync - Should the plugin attempt to unload synchronously or can it complete asynchronously
21
- */
22
- unload(itemCtx: IProcessTelemetryContext, isAsync: boolean): void;
23
16
  }
@@ -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
+ };
@@ -1,4 +1,4 @@
1
- export declare enum LoggingSeverity {
1
+ export declare const enum eLoggingSeverity {
2
2
  /**
3
3
  * Error will be sent as internal telemetry
4
4
  */
@@ -8,6 +8,95 @@ export declare enum LoggingSeverity {
8
8
  */
9
9
  WARNING = 2
10
10
  }
11
+ export declare const LoggingSeverity: {
12
+ CRITICAL: number;
13
+ WARNING: number;
14
+ };
15
+ export declare type LoggingSeverity = number | eLoggingSeverity;
16
+ export declare const enum _eInternalMessageId {
17
+ BrowserDoesNotSupportLocalStorage = 0,
18
+ BrowserCannotReadLocalStorage = 1,
19
+ BrowserCannotReadSessionStorage = 2,
20
+ BrowserCannotWriteLocalStorage = 3,
21
+ BrowserCannotWriteSessionStorage = 4,
22
+ BrowserFailedRemovalFromLocalStorage = 5,
23
+ BrowserFailedRemovalFromSessionStorage = 6,
24
+ CannotSendEmptyTelemetry = 7,
25
+ ClientPerformanceMathError = 8,
26
+ ErrorParsingAISessionCookie = 9,
27
+ ErrorPVCalc = 10,
28
+ ExceptionWhileLoggingError = 11,
29
+ FailedAddingTelemetryToBuffer = 12,
30
+ FailedMonitorAjaxAbort = 13,
31
+ FailedMonitorAjaxDur = 14,
32
+ FailedMonitorAjaxOpen = 15,
33
+ FailedMonitorAjaxRSC = 16,
34
+ FailedMonitorAjaxSend = 17,
35
+ FailedMonitorAjaxGetCorrelationHeader = 18,
36
+ FailedToAddHandlerForOnBeforeUnload = 19,
37
+ FailedToSendQueuedTelemetry = 20,
38
+ FailedToReportDataLoss = 21,
39
+ FlushFailed = 22,
40
+ MessageLimitPerPVExceeded = 23,
41
+ MissingRequiredFieldSpecification = 24,
42
+ NavigationTimingNotSupported = 25,
43
+ OnError = 26,
44
+ SessionRenewalDateIsZero = 27,
45
+ SenderNotInitialized = 28,
46
+ StartTrackEventFailed = 29,
47
+ StopTrackEventFailed = 30,
48
+ StartTrackFailed = 31,
49
+ StopTrackFailed = 32,
50
+ TelemetrySampledAndNotSent = 33,
51
+ TrackEventFailed = 34,
52
+ TrackExceptionFailed = 35,
53
+ TrackMetricFailed = 36,
54
+ TrackPVFailed = 37,
55
+ TrackPVFailedCalc = 38,
56
+ TrackTraceFailed = 39,
57
+ TransmissionFailed = 40,
58
+ FailedToSetStorageBuffer = 41,
59
+ FailedToRestoreStorageBuffer = 42,
60
+ InvalidBackendResponse = 43,
61
+ FailedToFixDepricatedValues = 44,
62
+ InvalidDurationValue = 45,
63
+ TelemetryEnvelopeInvalid = 46,
64
+ CreateEnvelopeError = 47,
65
+ CannotSerializeObject = 48,
66
+ CannotSerializeObjectNonSerializable = 49,
67
+ CircularReferenceDetected = 50,
68
+ ClearAuthContextFailed = 51,
69
+ ExceptionTruncated = 52,
70
+ IllegalCharsInName = 53,
71
+ ItemNotInArray = 54,
72
+ MaxAjaxPerPVExceeded = 55,
73
+ MessageTruncated = 56,
74
+ NameTooLong = 57,
75
+ SampleRateOutOfRange = 58,
76
+ SetAuthContextFailed = 59,
77
+ SetAuthContextFailedAccountName = 60,
78
+ StringValueTooLong = 61,
79
+ StartCalledMoreThanOnce = 62,
80
+ StopCalledWithoutStart = 63,
81
+ TelemetryInitializerFailed = 64,
82
+ TrackArgumentsNotSpecified = 65,
83
+ UrlTooLong = 66,
84
+ SessionStorageBufferFull = 67,
85
+ CannotAccessCookie = 68,
86
+ IdTooLong = 69,
87
+ InvalidEvent = 70,
88
+ FailedMonitorAjaxSetRequestHeader = 71,
89
+ SendBrowserInfoOnUserInit = 72,
90
+ PluginException = 73,
91
+ NotificationException = 74,
92
+ SnippetScriptLoadFailure = 99,
93
+ InvalidInstrumentationKey = 100,
94
+ CannotParseAiBlobValue = 101,
95
+ InvalidContentBlob = 102,
96
+ TrackPageActionEventFailed = 103,
97
+ FailedAddingCustomDefinedRequestContext = 104,
98
+ InMemoryStorageBufferFull = 105
99
+ }
11
100
  /**
12
101
  * Internal message ID. Please create a new one for every conceptually different message. Please keep alphabetically ordered
13
102
  */
@@ -95,4 +184,4 @@ export declare const _InternalMessageId: {
95
184
  FailedAddingCustomDefinedRequestContext: number;
96
185
  InMemoryStorageBufferFull: number;
97
186
  };
98
- export declare type _InternalMessageId = number | typeof _InternalMessageId;
187
+ export declare type _InternalMessageId = number | _eInternalMessageId;
@@ -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
  */
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
3
+ */
4
+ export declare const enum TelemetryUnloadReason {
5
+ /**
6
+ * Teardown has been called without any context.
7
+ */
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
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,8 +9,23 @@ 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;
15
+ /**
16
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
17
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
18
+ * @returns boolean = true if the plugin is in a state where it is operational.
19
+ */
20
+ isEnabled: () => boolean;
21
+ /**
22
+ * You can optionally enable / disable a plugin from processing events.
23
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
24
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
25
+ * (unless it's also been re-initialized)
26
+ */
27
+ setEnabled: (isEnabled: boolean) => void;
28
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
14
29
  }
15
30
  export interface IAppInsightsCore extends IPerfManagerProvider {
16
31
  config: IConfiguration;
@@ -59,9 +74,34 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
59
74
  * Return a new instance of the IProcessTelemetryContext for processing events
60
75
  */
61
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;
62
86
  /**
63
87
  * Find and return the (first) plugin with the specified identifier if present
64
88
  * @param pluginIdentifier
65
89
  */
66
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;
98
+ /**
99
+ * Returns the unique event namespace that should be used when registering events
100
+ */
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;
67
107
  }
@@ -1,5 +1,7 @@
1
1
  import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
2
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
2
3
  import { ITelemetryPlugin } from "./ITelemetryPlugin";
4
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
3
5
  /**
4
6
  * Provides data transmission capabilities
5
7
  */
@@ -13,9 +15,14 @@ export interface IChannelControls extends ITelemetryPlugin {
13
15
  */
14
16
  resume(): void;
15
17
  /**
16
- * Tear down transmission pipeline
18
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
19
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
20
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
21
+ * @param unloadCtx - This is the context that should be used during unloading.
22
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
23
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
17
24
  */
18
- teardown(): void;
25
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
19
26
  /**
20
27
  * Flush to send data immediately; channel should default to sending data asynchronously
21
28
  * @param async - send data asynchronously when true
@@ -1,19 +1,16 @@
1
1
  import { IAppInsightsCore } from "./IAppInsightsCore";
2
- import { IDiagnosticLogger } from "./IDiagnosticLogger";
3
2
  import { IConfiguration } from "./IConfiguration";
3
+ import { IDiagnosticLogger } from "./IDiagnosticLogger";
4
4
  import { ITelemetryItem } from "./ITelemetryItem";
5
5
  import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
6
6
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
7
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
7
8
  export declare const enum GetExtCfgMergeType {
8
9
  None = 0,
9
10
  MergeDefaultOnly = 1,
10
11
  MergeDefaultFromRootOrDefault = 2
11
12
  }
12
- /**
13
- * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
14
- * between multiple AppInsights instances
15
- */
16
- export interface IProcessTelemetryContext {
13
+ export interface IBaseProcessingContext {
17
14
  /**
18
15
  * The current core instance for the request
19
16
  */
@@ -51,11 +48,6 @@ export interface IProcessTelemetryContext {
51
48
  * Helper to set the next plugin proxy
52
49
  */
53
50
  setNext: (nextCtx: ITelemetryPluginChain) => void;
54
- /**
55
- * Call back for telemetry processing before it it is sent
56
- * @param env - This is the current event being reported
57
- */
58
- processNext: (env: ITelemetryItem) => void;
59
51
  /**
60
52
  * Synchronously iterate over the context chain running the callback for each plugin, once
61
53
  * every plugin has been executed via the callback, any associated onComplete will be called.
@@ -63,15 +55,58 @@ export interface IProcessTelemetryContext {
63
55
  */
64
56
  iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
65
57
  /**
66
- * Create a new context using the core and config from the current instance
58
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
59
+ * @param onComplete - The onComplete to call
60
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
61
+ * @param args - Any additional arguments to pass to the onComplete function
62
+ */
63
+ onComplete: (onComplete: Function, that?: any, ...args: any[]) => void;
64
+ /**
65
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
66
+ * @param plugins - The execution order to process the plugins, if null or not supplied
67
+ * then the current execution order will be copied.
68
+ * @param startAt - The plugin to start processing from, if missing from the execution
69
+ * order then the next plugin will be NOT set.
70
+ */
71
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
72
+ }
73
+ /**
74
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
75
+ * between multiple AppInsights instances
76
+ */
77
+ export interface IProcessTelemetryContext extends IBaseProcessingContext {
78
+ /**
79
+ * Call back for telemetry processing before it it is sent
80
+ * @param env - This is the current event being reported
81
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
82
+ */
83
+ processNext: (env: ITelemetryItem) => boolean | void;
84
+ /**
85
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
67
86
  * @param plugins - The execution order to process the plugins, if null or not supplied
68
87
  * then the current execution order will be copied.
69
88
  * @param startAt - The plugin to start processing from, if missing from the execution
70
89
  * order then the next plugin will be NOT set.
71
90
  */
72
91
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
92
+ }
93
+ /**
94
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
95
+ * between multiple AppInsights instances
96
+ */
97
+ export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
73
98
  /**
74
- * Set the function to call when the current chain has executed all processNext or unloadNext items.
99
+ * This Plugin has finished unloading, so unload the next one
100
+ * @param uploadState - The state of the unload process
101
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
102
+ */
103
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
104
+ /**
105
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
106
+ * @param plugins - The execution order to process the plugins, if null or not supplied
107
+ * then the current execution order will be copied.
108
+ * @param startAt - The plugin to start processing from, if missing from the execution
109
+ * order then the next plugin will be NOT set.
75
110
  */
76
- onComplete: (onComplete: () => void) => void;
111
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
77
112
  }
@@ -1,12 +1,10 @@
1
1
  import { ITelemetryItem } from "./ITelemetryItem";
2
2
  import { IConfiguration } from "./IConfiguration";
3
3
  import { IAppInsightsCore } from "./IAppInsightsCore";
4
- import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
4
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
5
5
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
6
- /**
7
- * Configuration provided to SDK core
8
- */
9
- export interface ITelemetryPlugin extends IPlugin {
6
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
7
+ export interface ITelemetryProcessor {
10
8
  /**
11
9
  * Call back for telemetry processing before it it is sent
12
10
  * @param env - This is the current event being reported
@@ -15,6 +13,11 @@ export interface ITelemetryPlugin extends IPlugin {
15
13
  * to later plugins (vs appending items to the telemetry item)
16
14
  */
17
15
  processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
16
+ }
17
+ /**
18
+ * Configuration provided to SDK core
19
+ */
20
+ export interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
18
21
  /**
19
22
  * Set next extension for telemetry processing, this is not optional as plugins should use the
20
23
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -42,10 +45,14 @@ export interface IPlugin {
42
45
  */
43
46
  isInitialized?: () => boolean;
44
47
  /**
45
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
46
- * therefore can be re-initialized after being torn down.
48
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
49
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
50
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
51
+ * @param unloadCtx - This is the context that should be used during unloading.
52
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
53
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
47
54
  */
48
- teardown?: () => void;
55
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
49
56
  /**
50
57
  * Extension name
51
58
  */
@@ -1,10 +1,10 @@
1
- import { ITelemetryItem } from "./ITelemetryItem";
2
- import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
3
- import { ITelemetryPlugin } from "./ITelemetryPlugin";
1
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
2
+ import { ITelemetryPlugin, ITelemetryProcessor } from "./ITelemetryPlugin";
3
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
4
4
  /**
5
5
  * Configuration provided to SDK core
6
6
  */
7
- export interface ITelemetryPluginChain {
7
+ export interface ITelemetryPluginChain extends ITelemetryProcessor {
8
8
  /**
9
9
  * Returns the underlying plugin that is being proxied for the processTelemetry call
10
10
  */
@@ -14,11 +14,10 @@ export interface ITelemetryPluginChain {
14
14
  */
15
15
  getNext: () => ITelemetryPluginChain;
16
16
  /**
17
- * Call back for telemetry processing before it it is sent
18
- * @param env - This is the current event being reported
19
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
20
- * can optionally use this to access the current core instance or define / pass additional information
21
- * to later plugins (vs appending items to the telemetry item)
17
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
18
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
19
+ * @param unloadCtx - The unload context to use for this call.
20
+ * @param unloadState - The details of the unload operation
22
21
  */
23
- processTelemetry: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
22
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
24
23
  }
@@ -0,0 +1,6 @@
1
+ import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
2
+ export interface ITelemetryUnloadState {
3
+ reason: TelemetryUnloadReason;
4
+ isAsync: boolean;
5
+ flushComplete?: boolean;
6
+ }
@@ -14,8 +14,9 @@ export { AppInsightsCore } from "./JavaScriptSDK/AppInsightsCore";
14
14
  export { BaseCore } from "./JavaScriptSDK/BaseCore";
15
15
  export { BaseTelemetryPlugin } from "./JavaScriptSDK/BaseTelemetryPlugin";
16
16
  export { randomValue, random32, mwcRandomSeed, mwcRandom32, newId } from "./JavaScriptSDK/RandomHelper";
17
- export { CoreUtils, ICoreUtils, EventHelper, IEventHelper, Undefined, addEventHandler, newGuid, perfNow, generateW3CId, disableCookies, canUseCookies, getCookie, setCookie, deleteCookie, _legacyCookieMgr, addEventListeners, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener } from "./JavaScriptSDK/CoreUtils";
18
- export { isTypeof, isUndefined, isNullOrUndefined, hasOwnProperty, isObject, isFunction, attachEvent, detachEvent, normalizeJsName, objForEachKey, strEndsWith, strStartsWith, isDate, isArray, isError, isString, isNumber, isBoolean, toISOString, arrForEach, arrIndexOf, arrMap, arrReduce, strTrim, objKeys, objDefineAccessors, dateNow, getExceptionName, throwError, strContains, isSymbol, setValue, getSetValue, isNotTruthy, isTruthy, proxyAssign, createClassFromInterface, optimizeObject, isNotUndefined, isNotNullOrUndefined, objFreeze, objSeal } from "./JavaScriptSDK/HelperFuncs";
17
+ export { CoreUtils, ICoreUtils, EventHelper, IEventHelper, Undefined, newGuid, perfNow, generateW3CId, disableCookies, canUseCookies, getCookie, setCookie, deleteCookie, _legacyCookieMgr } from "./JavaScriptSDK/CoreUtils";
18
+ export { isTypeof, isUndefined, isNullOrUndefined, hasOwnProperty, isObject, isFunction, normalizeJsName, objForEachKey, strEndsWith, strStartsWith, isDate, isArray, isError, isString, isNumber, isBoolean, toISOString, arrForEach, arrIndexOf, arrMap, arrReduce, strTrim, objKeys, objDefineAccessors, dateNow, getExceptionName, throwError, strContains, isSymbol, setValue, getSetValue, isNotTruthy, isTruthy, proxyAssign, proxyFunctions, proxyFunctionAs, createClassFromInterface, optimizeObject, isNotUndefined, isNotNullOrUndefined, objFreeze, objSeal, createEnumStyle, objExtend } from "./JavaScriptSDK/HelperFuncs";
19
+ export { attachEvent, detachEvent, addEventHandler, addEventListeners, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, removeEventHandler, removeEventListeners, removePageUnloadEventListener, removePageHideEventListener, eventOn, eventOff, mergeEvtNamespace, _IRegisteredEvents, __getRegisteredEvents } from "./JavaScriptSDK/EventHelpers";
19
20
  export { getGlobalInst, hasWindow, getWindow, hasDocument, getDocument, getCrypto, getMsCrypto, hasNavigator, getNavigator, hasHistory, getHistory, getLocation, getPerformance, hasJSON, getJSON, isReactNative, getConsole, dumpObj, isIE, getIEVersion, isSafari, setEnableEnvMocks, isBeaconsSupported, isFetchSupported, useXDomainRequest, isXhrSupported } from "./JavaScriptSDK/EnvUtils";
20
21
  export { getGlobal, objCreateFn as objCreate, strShimPrototype as strPrototype, strShimFunction as strFunction, strShimUndefined as strUndefined, strShimObject as strObject } from "@microsoft/applicationinsights-shims";
21
22
  export { NotificationManager } from "./JavaScriptSDK/NotificationManager";
@@ -26,7 +27,7 @@ export { PerfEvent, PerfManager, doPerf, getGblPerfMgr, setGblPerfMgr } from "./
26
27
  export { safeGetLogger, DiagnosticLogger, _InternalLogMessage } from "./JavaScriptSDK/DiagnosticLogger";
27
28
  export { ProcessTelemetryContext, createProcessTelemetryContext } from "./JavaScriptSDK/ProcessTelemetryContext";
28
29
  export { initializePlugins, sortPlugins } from "./JavaScriptSDK/TelemetryHelpers";
29
- export { _InternalMessageId, LoggingSeverity } from "./JavaScriptSDK.Enums/LoggingEnums";
30
+ export { _InternalMessageId, _eInternalMessageId, LoggingSeverity, eLoggingSeverity } from "./JavaScriptSDK.Enums/LoggingEnums";
30
31
  export { InstrumentProto, InstrumentProtos, InstrumentFunc, InstrumentFuncs } from "./JavaScriptSDK/InstrumentHooks";
31
32
  export { ICookieMgr, ICookieMgrConfig } from "./JavaScriptSDK.Interfaces/ICookieMgr";
32
33
  export { createCookieMgr, safeGetCookieMgr, uaDisallowsSameSiteNone, areCookiesSupported } from "./JavaScriptSDK/CookieMgr";
@@ -34,3 +35,6 @@ export { strIKey, strExtensionConfig } from "./JavaScriptSDK/Constants";
34
35
  export { IDbgExtension } from "./JavaScriptSDK.Interfaces/IDbgExtension";
35
36
  export { getDebugListener, getDebugExt } from "./JavaScriptSDK/DbgExtensionUtils";
36
37
  export { TelemetryInitializerFunction, ITelemetryInitializerHandler, ITelemetryInitializerContainer } from "./JavaScriptSDK.Interfaces/ITelemetryInitializers";
38
+ export { createUniqueNamespace } from "./JavaScriptSDK/DataCacheHelper";
39
+ export { UnloadHandler, IUnloadHandlerContainer, createUnloadHandlerContainer } from "./JavaScriptSDK/UnloadHandlerContainer";
40
+ export { ITelemetryUnloadState } from "./JavaScriptSDK.Interfaces/ITelemetryUnloadState";