@microsoft/applicationinsights-core-js 2.7.5-nightly.2203-02 → 2.7.5-nightly.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 (160) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1999 -793
  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 +15679 -8835
  7. package/dist/applicationinsights-core-js.api.md +425 -48
  8. package/dist/applicationinsights-core-js.d.ts +784 -123
  9. package/dist/applicationinsights-core-js.js +1999 -793
  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 +784 -123
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +496 -99
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +120 -21
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +202 -87
  21. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js +4 -4
  24. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js +7 -148
  26. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  27. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
  28. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
  29. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  30. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +25 -12
  31. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/EnvUtils.js +13 -12
  33. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/EventHelpers.js +477 -0
  35. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
  36. package/dist-esm/JavaScriptSDK/HelperFuncs.js +89 -86
  37. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
  39. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  40. package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
  41. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
  42. package/dist-esm/JavaScriptSDK/NotificationManager.js +37 -42
  43. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  44. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  45. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +430 -119
  46. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  47. package/dist-esm/JavaScriptSDK/RandomHelper.js +30 -4
  48. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  49. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +60 -14
  50. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  51. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +81 -0
  52. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
  53. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +33 -0
  54. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  55. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  57. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  58. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  60. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  61. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +8 -0
  62. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +1 -0
  63. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
  64. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  75. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
  77. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
  78. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  79. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  80. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  81. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  82. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  83. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  84. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +8 -0
  85. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +1 -0
  86. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +6 -0
  87. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -0
  88. package/dist-esm/applicationinsights-core-js.js +12 -7
  89. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  90. package/package.json +2 -2
  91. package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
  92. package/src/JavaScriptSDK/BaseCore.ts +696 -120
  93. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +205 -31
  94. package/src/JavaScriptSDK/ChannelController.ts +242 -103
  95. package/src/JavaScriptSDK/CookieMgr.ts +7 -5
  96. package/src/JavaScriptSDK/CoreUtils.ts +8 -172
  97. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  98. package/src/JavaScriptSDK/DiagnosticLogger.ts +27 -12
  99. package/src/JavaScriptSDK/EnvUtils.ts +13 -12
  100. package/src/JavaScriptSDK/EventHelpers.ts +550 -0
  101. package/src/JavaScriptSDK/HelperFuncs.ts +123 -97
  102. package/src/JavaScriptSDK/InstrumentHooks.ts +4 -2
  103. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  104. package/src/JavaScriptSDK/NotificationManager.ts +34 -37
  105. package/src/JavaScriptSDK/PerfManager.ts +4 -7
  106. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +543 -134
  107. package/src/JavaScriptSDK/RandomHelper.ts +35 -3
  108. package/src/JavaScriptSDK/TelemetryHelpers.ts +83 -21
  109. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +111 -0
  110. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +46 -0
  111. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
  112. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  113. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  114. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +27 -0
  115. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +82 -2
  116. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +16 -5
  117. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +16 -6
  118. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +94 -14
  119. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
  120. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +28 -10
  121. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  122. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  123. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +34 -0
  124. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +17 -0
  125. package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
  126. package/types/JavaScriptSDK/BaseCore.d.ts +81 -3
  127. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +53 -10
  128. package/types/JavaScriptSDK/ChannelController.d.ts +16 -17
  129. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -48
  130. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  131. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +10 -0
  132. package/types/JavaScriptSDK/EventHelpers.d.ts +154 -0
  133. package/types/JavaScriptSDK/HelperFuncs.d.ts +33 -32
  134. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  135. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  136. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +69 -6
  137. package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
  138. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +23 -3
  139. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +16 -0
  140. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  141. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
  142. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  143. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
  144. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +20 -0
  145. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +72 -1
  146. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +16 -5
  147. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +9 -0
  148. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +82 -11
  149. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
  150. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +25 -8
  151. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  152. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  153. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +22 -0
  154. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +13 -0
  155. package/types/applicationinsights-core-js.d.ts +18 -9
  156. package/types/tsdoc-metadata.json +1 -1
  157. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
  158. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
  159. package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
  160. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
@@ -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
@@ -0,0 +1,27 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ /**
5
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
6
+ */
7
+ export const enum TelemetryUnloadReason {
8
+ /**
9
+ * Teardown has been called without any context.
10
+ */
11
+ ManualTeardown = 0,
12
+
13
+ /**
14
+ * Just this plugin is being removed
15
+ */
16
+ PluginUnload = 1,
17
+
18
+ /**
19
+ * This instance of the plugin is being removed and replaced
20
+ */
21
+ PluginReplace = 2,
22
+
23
+ /**
24
+ * The entire SDK is being unloaded
25
+ */
26
+ SdkUnload = 50
27
+ }
@@ -0,0 +1,27 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ /**
5
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
6
+ */
7
+ export const enum TelemetryUpdateReason {
8
+ /**
9
+ * Unknown.
10
+ */
11
+ Unknown = 0,
12
+
13
+ /**
14
+ * The configuration has ben updated or changed
15
+ */
16
+ //ConfigurationChanged = 0x01,
17
+
18
+ /**
19
+ * One or more plugins have been added
20
+ */
21
+ PluginAdded = 0x10,
22
+
23
+ /**
24
+ * One or more plugins have been removed
25
+ */
26
+ PluginRemoved = 0x20,
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";
@@ -10,8 +10,31 @@ import { IDiagnosticLogger } from "./IDiagnosticLogger";
10
10
  import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
11
11
  import { IPerfManagerProvider } from "./IPerfManager";
12
12
  import { ICookieMgr } from "./ICookieMgr";
13
+ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./ITelemetryInitializers";
14
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
15
+ import { UnloadHandler } from "../JavaScriptSDK/UnloadHandlerContainer";
16
+ import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
13
17
 
14
- "use strict";
18
+ export interface ILoadedPlugin<T extends IPlugin> {
19
+ plugin: T;
20
+
21
+ /**
22
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
23
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
24
+ * @returns boolean = true if the plugin is in a state where it is operational.
25
+ */
26
+ isEnabled: () => boolean;
27
+
28
+ /**
29
+ * You can optionally enable / disable a plugin from processing events.
30
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
31
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
32
+ * (unless it's also been re-initialized)
33
+ */
34
+ setEnabled: (isEnabled: boolean) => void;
35
+
36
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
37
+ }
15
38
 
16
39
  export interface IAppInsightsCore extends IPerfManagerProvider {
17
40
 
@@ -72,6 +95,13 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
72
95
  */
73
96
  removeNotificationListener?(listener: INotificationListener): void;
74
97
 
98
+ /**
99
+ * Add a telemetry processor to decorate or drop telemetry events.
100
+ * @param telemetryInitializer - The Telemetry Initializer function
101
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
102
+ */
103
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
104
+
75
105
  pollInternalLogs?(eventName?: string): number;
76
106
 
77
107
  stopPollingInternalLogs?(): void;
@@ -80,4 +110,54 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
80
110
  * Return a new instance of the IProcessTelemetryContext for processing events
81
111
  */
82
112
  getProcessTelContext() : IProcessTelemetryContext;
113
+
114
+ /**
115
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
116
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
117
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
118
+ * approach is to create a new instance and initialize that instance.
119
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
120
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
121
+ * @param isAsync - Can the unload be performed asynchronously (default)
122
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
123
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
124
+ */
125
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
126
+
127
+ /**
128
+ * Find and return the (first) plugin with the specified identifier if present
129
+ * @param pluginIdentifier
130
+ */
131
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
132
+
133
+ /**
134
+ * Add a new plugin to the installation
135
+ * @param plugin - The new plugin to add
136
+ * @param replaceExisting - should any existing plugin be replaced, default is false
137
+ * @param doAsync - Should the add be performed asynchronously
138
+ * @param addCb - [Optional] callback to call after the plugin has been added
139
+ */
140
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
141
+
142
+ /**
143
+ * Returns the unique event namespace that should be used when registering events
144
+ */
145
+ evtNamespace(): string;
146
+
147
+ /**
148
+ * Add a handler that will be called when the SDK is being unloaded
149
+ * @param handler - the handler
150
+ */
151
+ addUnloadCb(handler: UnloadHandler): void;
152
+
153
+ /**
154
+ * Flush and send any batched / cached data immediately
155
+ * @param async - send data asynchronously when true (defaults to true)
156
+ * @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.
157
+ * If the caller doesn't return true the caller should assume that it may never be called.
158
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
159
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
160
+ * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
161
+ */
162
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
83
163
  }
@@ -1,6 +1,9 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
+ import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
4
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
3
5
  import { ITelemetryPlugin } from "./ITelemetryPlugin";
6
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
4
7
 
5
8
  "use strict";
6
9
 
@@ -20,16 +23,24 @@ export interface IChannelControls extends ITelemetryPlugin {
20
23
  resume(): void;
21
24
 
22
25
  /**
23
- * Tear down transmission pipeline
26
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
27
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
28
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
29
+ * @param unloadCtx - This is the context that should be used during unloading.
30
+ * @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.
31
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
24
32
  */
25
- teardown(): void;
33
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
26
34
 
27
35
  /**
28
36
  * Flush to send data immediately; channel should default to sending data asynchronously
29
- * @param async: send data asynchronously when true
30
- * @param callBack: if specified, notify caller when send is complete
37
+ * @param async - send data asynchronously when true
38
+ * @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.
39
+ * If the caller doesn't return true the caller should assume that it may never be called.
40
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
41
+ * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
31
42
  */
32
- flush(async: boolean, callBack?: () => void): void;
43
+ flush(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void;
33
44
  }
34
45
 
35
46
  export const MinChannelPriorty: number = 100;
@@ -12,6 +12,11 @@ export type InstrumentorHooksCallback = (funcArgs:IInstrumentCallDetails, ...org
12
12
  * You must always supply the error callback
13
13
  */
14
14
  export interface IInstrumentHooksCallbacks {
15
+ /**
16
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
17
+ * identify the source of the instrumented hooks
18
+ */
19
+ ns?: string | string[];
15
20
 
16
21
  /**
17
22
  * The hook callback to call before the original function is called
@@ -40,20 +45,20 @@ export interface IInstrumentHooksCallbacks {
40
45
  */
41
46
  export interface IInstrumentHook {
42
47
  /** Unique Id for this callback on the hooked method */
43
- id:number;
48
+ id: number;
44
49
 
45
50
  /** Holds the callbacks */
46
- cbks:IInstrumentHooksCallbacks;
51
+ cbks: IInstrumentHooksCallbacks;
47
52
 
48
53
  /** Remove this hook from the function */
49
54
  rm: () => void;
50
55
  }
51
56
 
52
57
  export interface IInstrumentHooks {
53
- i:number; // Used to create unique ids
54
- n:string; // Function name
55
- f:any; // Original Function
56
- h:IInstrumentHook[]; // The hook
58
+ i: number; // Used to create unique ids
59
+ n: string; // Function name
60
+ f: any; // Original Function
61
+ h: IInstrumentHook[]; // The hook
57
62
  }
58
63
 
59
64
  export interface IInstrumentCallDetails {
@@ -85,4 +90,9 @@ export interface IInstrumentCallDetails {
85
90
  * The error (exception) which occurred while executing the original method
86
91
  */
87
92
  err?: Error;
93
+
94
+ /**
95
+ * The Event object from (window.event) at the start of the original call
96
+ */
97
+ evt?: Event;
88
98
  }
@@ -3,17 +3,21 @@
3
3
  "use strict";
4
4
 
5
5
  import { IAppInsightsCore } from "./IAppInsightsCore";
6
- import { IDiagnosticLogger } from "./IDiagnosticLogger";
7
6
  import { IConfiguration } from "./IConfiguration";
7
+ import { IDiagnosticLogger } from "./IDiagnosticLogger";
8
8
  import { ITelemetryItem } from "./ITelemetryItem";
9
- import { IPlugin } from "./ITelemetryPlugin";
9
+ import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
10
10
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
11
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
12
+ import { ITelemetryUpdateState } from "./ITelemetryUpdateState";
11
13
 
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 {
14
+ export const enum GetExtCfgMergeType {
15
+ None = 0,
16
+ MergeDefaultOnly = 1,
17
+ MergeDefaultFromRootOrDefault = 2,
18
+ }
19
+
20
+ export interface IBaseProcessingContext {
17
21
  /**
18
22
  * The current core instance for the request
19
23
  */
@@ -27,12 +31,12 @@ export interface IProcessTelemetryContext {
27
31
  /**
28
32
  * Gets the current core config instance
29
33
  */
30
- getCfg: ()=> IConfiguration;
34
+ getCfg: () => IConfiguration;
31
35
 
32
36
  /**
33
37
  * Gets the named extension config
34
38
  */
35
- getExtCfg: <T>(identifier: string, defaultValue?:T|any) => T;
39
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
36
40
 
37
41
  /**
38
42
  * Gets the named config from either the named identifier extension or core config if neither exist then the
@@ -41,7 +45,7 @@ export interface IProcessTelemetryContext {
41
45
  * @param field The config field name
42
46
  * @param defaultValue The default value to return if no defined config exists
43
47
  */
44
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
48
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
45
49
 
46
50
  /**
47
51
  * Helper to allow plugins to check and possibly shortcut executing code only
@@ -57,20 +61,96 @@ export interface IProcessTelemetryContext {
57
61
  /**
58
62
  * Helper to set the next plugin proxy
59
63
  */
60
- setNext: (nextCtx:ITelemetryPluginChain) => void;
64
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
65
+
66
+ /**
67
+ * Synchronously iterate over the context chain running the callback for each plugin, once
68
+ * every plugin has been executed via the callback, any associated onComplete will be called.
69
+ * @param callback - The function call for each plugin in the context chain
70
+ */
71
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
72
+
73
+ /**
74
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
75
+ * @param onComplete - The onComplete to call
76
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
77
+ * @param args - Any additional arguments to pass to the onComplete function
78
+ */
79
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
61
80
 
81
+ /**
82
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
83
+ * @param plugins - The execution order to process the plugins, if null or not supplied
84
+ * then the current execution order will be copied.
85
+ * @param startAt - The plugin to start processing from, if missing from the execution
86
+ * order then the next plugin will be NOT set.
87
+ */
88
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
89
+ }
90
+
91
+ /**
92
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
93
+ * between multiple AppInsights instances
94
+ */
95
+ export interface IProcessTelemetryContext extends IBaseProcessingContext {
62
96
  /**
63
97
  * Call back for telemetry processing before it it is sent
64
98
  * @param env - This is the current event being reported
99
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
100
+ */
101
+ processNext: (env: ITelemetryItem) => boolean | void;
102
+
103
+ /**
104
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
105
+ * @param plugins - The execution order to process the plugins, if null or not supplied
106
+ * then the current execution order will be copied.
107
+ * @param startAt - The plugin to start processing from, if missing from the execution
108
+ * order then the next plugin will be NOT set.
109
+ */
110
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
111
+ }
112
+
113
+ /**
114
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
115
+ * or the SDK is being unloaded.
116
+ */
117
+ export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
118
+
119
+ /**
120
+ * This Plugin has finished unloading, so unload the next one
121
+ * @param uploadState - The state of the unload process
122
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
123
+ */
124
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
125
+
126
+ /**
127
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
128
+ * @param plugins - The execution order to process the plugins, if null or not supplied
129
+ * then the current execution order will be copied.
130
+ * @param startAt - The plugin to start processing from, if missing from the execution
131
+ * order then the next plugin will be NOT set.
132
+ */
133
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
134
+ }
135
+
136
+ /**
137
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
138
+ * for when plugins are added, removed or the configuration was changed.
139
+ */
140
+ export interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
141
+ /**
142
+ * This Plugin has finished unloading, so unload the next one
143
+ * @param updateState - The update State
144
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
65
145
  */
66
- processNext: (env: ITelemetryItem) => void;
146
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
67
147
 
68
148
  /**
69
- * Create a new context using the core and config from the current instance
149
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
70
150
  * @param plugins - The execution order to process the plugins, if null or not supplied
71
151
  * then the current execution order will be copied.
72
152
  * @param startAt - The plugin to start processing from, if missing from the execution
73
153
  * order then the next plugin will be NOT set.
74
154
  */
75
- createNew: (plugins?:IPlugin[]|ITelemetryPluginChain, startAt?:IPlugin) => IProcessTelemetryContext;
155
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
76
156
  }
@@ -0,0 +1,16 @@
1
+ import { ITelemetryItem } from "./ITelemetryItem";
2
+
3
+ export declare type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
4
+
5
+ export interface ITelemetryInitializerHandler {
6
+ remove(): void;
7
+ }
8
+
9
+ export interface ITelemetryInitializerContainer {
10
+ /**
11
+ * Add a telemetry processor to decorate or drop telemetry events.
12
+ * @param telemetryInitializer - The Telemetry Initializer function
13
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
14
+ */
15
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
16
+ }
@@ -5,13 +5,12 @@
5
5
  import { ITelemetryItem } from "./ITelemetryItem";
6
6
  import { IConfiguration } from "./IConfiguration";
7
7
  import { IAppInsightsCore } from "./IAppInsightsCore";
8
- import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
8
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext } from "./IProcessTelemetryContext";
9
9
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
10
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
11
+ import { ITelemetryUpdateState } from "./ITelemetryUpdateState";
10
12
 
11
- /**
12
- * Configuration provided to SDK core
13
- */
14
- export interface ITelemetryPlugin extends IPlugin {
13
+ export interface ITelemetryProcessor {
15
14
  /**
16
15
  * Call back for telemetry processing before it it is sent
17
16
  * @param env - This is the current event being reported
@@ -20,7 +19,22 @@ export interface ITelemetryPlugin extends IPlugin {
20
19
  * to later plugins (vs appending items to the telemetry item)
21
20
  */
22
21
  processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
23
-
22
+
23
+ /**
24
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
25
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
26
+ * the configuration has bee updated.
27
+ * @param updateCtx - This is the context that should be used during updating.
28
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
29
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
30
+ */
31
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
32
+ }
33
+
34
+ /**
35
+ * Configuration provided to SDK core
36
+ */
37
+ export interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
24
38
  /**
25
39
  * Set next extension for telemetry processing, this is not optional as plugins should use the
26
40
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -43,7 +57,7 @@ export interface IPlugin {
43
57
  * @param pluginChain - [Optional] specifies the current plugin chain which identifies the
44
58
  * set of plugins and the order they should be executed for the current request.
45
59
  */
46
- initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => void;
60
+ initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => void;
47
61
 
48
62
  /**
49
63
  * Returns a value that indicates whether the plugin has already been previously initialized.
@@ -52,10 +66,14 @@ export interface IPlugin {
52
66
  isInitialized?: () => boolean;
53
67
 
54
68
  /**
55
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
56
- * therefore can be re-initialized after being torn down.
69
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
70
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
71
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
72
+ * @param unloadCtx - This is the context that should be used during unloading.
73
+ * @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.
74
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
57
75
  */
58
- teardown?: () => void;
76
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
59
77
 
60
78
  /**
61
79
  * Extension name
@@ -1,15 +1,14 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
- "use strict";
4
3
 
5
- import { ITelemetryItem } from "./ITelemetryItem";
6
- import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
7
- import { ITelemetryPlugin } from "./ITelemetryPlugin";
4
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
5
+ import { ITelemetryPlugin, ITelemetryProcessor } from "./ITelemetryPlugin";
6
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
8
7
 
9
8
  /**
10
9
  * Configuration provided to SDK core
11
10
  */
12
- export interface ITelemetryPluginChain {
11
+ export interface ITelemetryPluginChain extends ITelemetryProcessor {
13
12
 
14
13
  /**
15
14
  * Returns the underlying plugin that is being proxied for the processTelemetry call
@@ -22,11 +21,10 @@ export interface ITelemetryPluginChain {
22
21
  getNext: () => ITelemetryPluginChain;
23
22
 
24
23
  /**
25
- * Call back for telemetry processing before it it is sent
26
- * @param env - This is the current event being reported
27
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
28
- * can optionally use this to access the current core instance or define / pass additional information
29
- * to later plugins (vs appending items to the telemetry item)
24
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
25
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
26
+ * @param unloadCtx - The unload context to use for this call.
27
+ * @param unloadState - The details of the unload operation
30
28
  */
31
- processTelemetry: (env: ITelemetryItem, itemCtx:IProcessTelemetryContext) => void;
29
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
32
30
  }
@@ -0,0 +1,10 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
5
+
6
+ export interface ITelemetryUnloadState {
7
+ reason: TelemetryUnloadReason;
8
+ isAsync: boolean;
9
+ flushComplete?: boolean;
10
+ }
@@ -0,0 +1,34 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
5
+ //import { IConfiguration } from "./IConfiguration";
6
+ import { IPlugin } from "./ITelemetryPlugin";
7
+
8
+ export interface ITelemetryUpdateState {
9
+
10
+ /**
11
+ * Identifies the reason for the update notification, this is a bitwise numeric value
12
+ */
13
+ reason: TelemetryUpdateReason;
14
+
15
+ /**
16
+ * If this is a configuration update this was the previous configuration that was used
17
+ */
18
+ //prvCfg?: IConfiguration,
19
+
20
+ /**
21
+ * If this is a configuration update is the new configuration that is being used
22
+ */
23
+ //newCfg?: IConfiguration,
24
+
25
+ /**
26
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
27
+ */
28
+ added?: IPlugin[];
29
+
30
+ /**
31
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
32
+ */
33
+ removed?: IPlugin[]
34
+ }
@@ -0,0 +1,17 @@
1
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
2
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
3
+
4
+ // Copyright (c) Microsoft Corporation. All rights reserved.
5
+ // Licensed under the MIT License.
6
+
7
+ export interface IUnloadableComponent {
8
+ /**
9
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
10
+ * finishes it's removal.
11
+ * @param unloadCtx - This is the context that should be used during unloading.
12
+ * @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.
13
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.
14
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
15
+ */
16
+ _doUnload?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
17
+ }
@@ -3,31 +3,10 @@ import { BaseCore } from "./BaseCore";
3
3
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
4
4
  import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
- import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
7
6
  import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
8
7
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
9
8
  export declare class AppInsightsCore extends BaseCore implements IAppInsightsCore {
10
9
  constructor();
11
10
  initialize(config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
12
11
  track(telemetryItem: ITelemetryItem): void;
13
- /**
14
- * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
15
- * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
16
- * called.
17
- * @param {INotificationListener} listener - An INotificationListener object.
18
- */
19
- addNotificationListener(listener: INotificationListener): void;
20
- /**
21
- * Removes all instances of the listener.
22
- * @param {INotificationListener} listener - INotificationListener to remove.
23
- */
24
- removeNotificationListener(listener: INotificationListener): void;
25
- /**
26
- * Periodically check logger.queue for
27
- */
28
- pollInternalLogs(eventName?: string): number;
29
- /**
30
- * Periodically check logger.queue for
31
- */
32
- stopPollingInternalLogs(): void;
33
12
  }