@microsoft/applicationinsights-core-js 2.7.5-nightly.2204-03 → 2.7.5-nightly.2204-23

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 +766 -1967
  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 +9840 -16439
  7. package/dist/applicationinsights-core-js.api.md +48 -425
  8. package/dist/applicationinsights-core-js.d.ts +123 -784
  9. package/dist/applicationinsights-core-js.js +766 -1967
  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 +123 -784
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +69 -3
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +99 -496
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +21 -120
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +87 -202
  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 +148 -7
  26. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  27. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  28. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +14 -27
  29. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/EnvUtils.js +12 -13
  31. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/HelperFuncs.js +86 -89
  33. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -3
  35. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/NotificationManager.js +42 -37
  37. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  39. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +119 -430
  40. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/RandomHelper.js +4 -30
  42. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  43. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +14 -60
  44. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +76 -0
  46. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +1 -0
  47. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +96 -90
  49. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  50. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +2 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +2 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  68. package/dist-esm/applicationinsights-core-js.js +7 -12
  69. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  70. package/package.json +3 -3
  71. package/src/JavaScriptSDK/AppInsightsCore.ts +101 -2
  72. package/src/JavaScriptSDK/BaseCore.ts +120 -696
  73. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +31 -205
  74. package/src/JavaScriptSDK/ChannelController.ts +103 -242
  75. package/src/JavaScriptSDK/CookieMgr.ts +5 -7
  76. package/src/JavaScriptSDK/CoreUtils.ts +172 -8
  77. package/src/JavaScriptSDK/DiagnosticLogger.ts +14 -29
  78. package/src/JavaScriptSDK/EnvUtils.ts +12 -13
  79. package/src/JavaScriptSDK/HelperFuncs.ts +97 -123
  80. package/src/JavaScriptSDK/InstrumentHooks.ts +2 -4
  81. package/src/JavaScriptSDK/NotificationManager.ts +37 -34
  82. package/src/JavaScriptSDK/PerfManager.ts +7 -4
  83. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +134 -543
  84. package/src/JavaScriptSDK/RandomHelper.ts +3 -35
  85. package/src/JavaScriptSDK/TelemetryHelpers.ts +21 -83
  86. package/src/JavaScriptSDK/TelemetryPluginChain.ts +120 -0
  87. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +87 -184
  88. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -5
  89. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +2 -82
  90. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +5 -16
  91. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +6 -16
  92. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +14 -94
  93. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +10 -28
  94. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +11 -9
  95. package/types/JavaScriptSDK/AppInsightsCore.d.ts +21 -0
  96. package/types/JavaScriptSDK/BaseCore.d.ts +3 -81
  97. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +10 -53
  98. package/types/JavaScriptSDK/ChannelController.d.ts +17 -16
  99. package/types/JavaScriptSDK/CoreUtils.d.ts +48 -1
  100. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +0 -10
  101. package/types/JavaScriptSDK/HelperFuncs.d.ts +32 -33
  102. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  103. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +6 -69
  104. package/types/JavaScriptSDK/RandomHelper.d.ts +0 -6
  105. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -23
  106. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +32 -0
  107. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +2 -91
  108. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +0 -4
  109. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +1 -72
  110. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +5 -16
  111. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +0 -9
  112. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +11 -82
  113. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +8 -25
  114. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +10 -9
  115. package/types/applicationinsights-core-js.d.ts +9 -18
  116. package/types/tsdoc-metadata.json +1 -1
  117. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +0 -93
  118. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +0 -1
  119. package/dist-esm/JavaScriptSDK/EventHelpers.js +0 -477
  120. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +0 -1
  121. package/dist-esm/JavaScriptSDK/InternalConstants.js +0 -28
  122. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +0 -1
  123. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +0 -81
  124. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +0 -1
  125. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +0 -33
  126. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +0 -1
  127. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +0 -8
  128. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +0 -1
  129. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +0 -8
  130. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +0 -1
  131. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +0 -6
  132. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +0 -1
  133. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +0 -8
  134. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +0 -1
  135. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +0 -8
  136. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +0 -1
  137. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +0 -6
  138. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +0 -1
  139. package/src/JavaScriptSDK/DataCacheHelper.ts +0 -106
  140. package/src/JavaScriptSDK/EventHelpers.ts +0 -550
  141. package/src/JavaScriptSDK/InternalConstants.ts +0 -26
  142. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -111
  143. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -46
  144. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
  145. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
  146. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -16
  147. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
  148. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -34
  149. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
  150. package/types/JavaScriptSDK/DataCacheHelper.d.ts +0 -13
  151. package/types/JavaScriptSDK/EventHelpers.d.ts +0 -154
  152. package/types/JavaScriptSDK/InternalConstants.d.ts +0 -20
  153. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -16
  154. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +0 -11
  155. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +0 -21
  156. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +0 -20
  157. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +0 -13
  158. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +0 -6
  159. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +0 -22
  160. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +0 -13
@@ -2,7 +2,6 @@
2
2
  // Licensed under the MIT License.
3
3
  import { getCrypto, getMsCrypto, isIE } from "./EnvUtils";
4
4
  import { dateNow } from "./HelperFuncs";
5
- import { strEmpty } from "./InternalConstants";
6
5
 
7
6
  const UInt32Mask = 0x100000000;
8
7
  const MaxUInt32 = 0xffffffff;
@@ -53,14 +52,12 @@ export function randomValue(maxValue: number) {
53
52
  * @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)
54
53
  */
55
54
  export function random32(signed?: boolean) {
56
- let value = 0;
55
+ let value;
57
56
  let c = getCrypto() || getMsCrypto();
58
57
  if (c && c.getRandomValues) {
59
58
  // Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
60
59
  value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
61
- }
62
-
63
- if (value === 0 && isIE()) {
60
+ } else if (isIE()) {
64
61
  // For IE 6, 7, 8 (especially on XP) Math.random is not very random
65
62
  if (!_mwcSeeded) {
66
63
  // Set the seed for the Mwc algorithm
@@ -70,9 +67,7 @@ export function random32(signed?: boolean) {
70
67
  // Don't use Math.random for IE
71
68
  // Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
72
69
  value = mwcRandom32() & MaxUInt32;
73
- }
74
-
75
- if (value === 0) {
70
+ } else {
76
71
  // Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
77
72
  value = Math.floor((UInt32Mask * Math.random()) | 0);
78
73
  }
@@ -117,30 +112,3 @@ export function mwcRandom32(signed?: boolean) {
117
112
  return value;
118
113
  }
119
114
 
120
- /**
121
- * Generate random base64 id string.
122
- * The default length is 22 which is 132-bits so almost the same as a GUID but as base64 (the previous default was 5)
123
- * @param maxLength - Optional value to specify the length of the id to be generated, defaults to 22
124
- */
125
- export function newId(maxLength = 22): string {
126
- const base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
127
-
128
- // Start with an initial random number, consuming the value in reverse byte order
129
- let number = random32() >>> 0; // Make sure it's a +ve number
130
- let chars = 0;
131
- let result = strEmpty;
132
- while (result.length < maxLength) {
133
- chars ++;
134
- result += base64chars.charAt(number & 0x3F);
135
- number >>>= 6; // Zero fill with right shift
136
- if (chars === 5) {
137
- // 5 base64 characters === 30 bits so we don't have enough bits for another base64 char
138
- // So add on another 30 bits and make sure it's +ve
139
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
140
- chars = 0; // We need to reset the number every 5 chars (30 bits)
141
- }
142
- }
143
-
144
- return result;
145
- }
146
-
@@ -3,28 +3,16 @@
3
3
  "use strict";
4
4
 
5
5
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
6
- import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
+ import { _InternalLogMessage } from "./DiagnosticLogger";
7
+ import { _InternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
8
+ import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
7
9
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
10
  import { arrForEach, isFunction } from "./HelperFuncs";
9
- import { strCore, strDoTeardown, strIsInitialized, strPriority, strProcessTelemetry, strSetNextPlugin, strTeardown } from "./InternalConstants";
10
- import { createElmNodeData } from "./DataCacheHelper";
11
- import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
12
- import { IUnloadableComponent } from "../JavaScriptSDK.Interfaces/IUnloadableComponent";
13
- import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
14
11
 
15
- const strDoUnload = "_doUnload";
16
- export interface IPluginState {
17
- core?: IAppInsightsCore;
18
- isInitialized?: boolean;
19
- tearDown?: boolean;
20
- disabled?: boolean;
21
- }
22
-
23
- const pluginStateData = createElmNodeData("plugin");
24
-
25
- export function _getPluginState(plugin: IPlugin): IPluginState {
26
- return pluginStateData.get<IPluginState>(plugin, "state", {}, true)
27
- }
12
+ let processTelemetry = "processTelemetry";
13
+ let priority = "priority";
14
+ let setNextPlugin = "setNextPlugin";
15
+ let isInitialized = "isInitialized";
28
16
 
29
17
  /**
30
18
  * Initialize the queue of plugins
@@ -33,32 +21,23 @@ export function _getPluginState(plugin: IPlugin): IPluginState {
33
21
  * @param core THe current core instance
34
22
  * @param extensions The extensions
35
23
  */
36
- export function initializePlugins(processContext: IProcessTelemetryContext, extensions: IPlugin[]) {
24
+ export function initializePlugins(processContext:ProcessTelemetryContext, extensions: IPlugin[]) {
37
25
 
38
26
  // Set the next plugin and identified the uninitialized plugins
39
- let initPlugins: ITelemetryPlugin[] = [];
40
- let lastPlugin: ITelemetryPlugin = null;
41
- let proxy: ITelemetryPluginChain = processContext.getNext();
42
- let pluginState: IPluginState;
27
+ let initPlugins:ITelemetryPlugin[] = [];
28
+ let lastPlugin:ITelemetryPlugin = null;
29
+ let proxy:ITelemetryPluginChain = processContext.getNext();
43
30
  while (proxy) {
44
31
  let thePlugin = proxy.getPlugin();
45
32
  if (thePlugin) {
46
33
  if (lastPlugin &&
47
- isFunction(lastPlugin[strSetNextPlugin]) &&
48
- isFunction(thePlugin[strProcessTelemetry])) {
34
+ isFunction(lastPlugin[setNextPlugin]) &&
35
+ isFunction(thePlugin[processTelemetry])) {
49
36
  // Set this plugin as the next for the previous one
50
- lastPlugin[strSetNextPlugin](thePlugin);
51
- }
52
-
53
- let isInitialized = false;
54
- if (isFunction(thePlugin[strIsInitialized])) {
55
- isInitialized = thePlugin[strIsInitialized]();
56
- } else {
57
- pluginState = _getPluginState(thePlugin);
58
- isInitialized = pluginState[strIsInitialized];
37
+ lastPlugin[setNextPlugin](thePlugin);
59
38
  }
60
39
 
61
- if (!isInitialized) {
40
+ if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
62
41
  initPlugins.push(thePlugin);
63
42
  }
64
43
 
@@ -67,35 +46,23 @@ export function initializePlugins(processContext: IProcessTelemetryContext, exte
67
46
  }
68
47
  }
69
48
 
70
- // Now initialize the plugins
49
+ // Now initiatilize the plugins
71
50
  arrForEach(initPlugins, thePlugin => {
72
- let core = processContext.core();
73
-
74
51
  thePlugin.initialize(
75
52
  processContext.getCfg(),
76
- core,
53
+ processContext.core(),
77
54
  extensions,
78
55
  processContext.getNext());
79
-
80
- pluginState = _getPluginState(thePlugin);
81
-
82
- // Only add the core to the state if the plugin didn't set it (doesn't extent from BaseTelemetryPlugin)
83
- if (!thePlugin[strCore] && !pluginState[strCore]) {
84
- pluginState[strCore] = core;
85
- }
86
-
87
- pluginState[strIsInitialized] = true;
88
- delete pluginState[strTeardown];
89
56
  });
90
57
  }
91
58
 
92
- export function sortPlugins<T = IPlugin>(plugins:T[]) {
59
+ export function sortPlugins(plugins:IPlugin[]) {
93
60
  // Sort by priority
94
61
  return plugins.sort((extA, extB) => {
95
62
  let result = 0;
96
- let bHasProcess = isFunction(extB[strProcessTelemetry]);
97
- if (isFunction(extA[strProcessTelemetry])) {
98
- result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
63
+ let bHasProcess = isFunction(extB[processTelemetry]);
64
+ if (isFunction(extA[processTelemetry])) {
65
+ result = bHasProcess ? extA[priority] - extB[priority] : 1;
99
66
  } else if (bHasProcess) {
100
67
  result = -1;
101
68
  }
@@ -103,33 +70,4 @@ export function sortPlugins<T = IPlugin>(plugins:T[]) {
103
70
  return result;
104
71
  });
105
72
  // sort complete
106
- }
107
-
108
- /**
109
- * Teardown / Unload helper to perform teardown/unloading operations for the provided components synchronously or asynchronously, this will call any
110
- * _doTeardown() or _doUnload() functions on the provided components to allow them to finish removal.
111
- * @param components - The components you want to unload
112
- * @param unloadCtx - This is the context that should be used during unloading.
113
- * @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.
114
- * @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.
115
- * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
116
- */
117
- export function unloadComponents(components: any | IUnloadableComponent[], unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean {
118
- let idx = 0;
119
-
120
- function _doUnload(): void | boolean {
121
- while (idx < components.length) {
122
- let component = components[idx++];
123
- if (component) {
124
- let func = component[strDoUnload] || component[strDoTeardown];
125
- if (isFunction(func)) {
126
- if (func.call(component, unloadCtx, unloadState, _doUnload) === true) {
127
- return true;
128
- }
129
- }
130
- }
131
- }
132
- }
133
-
134
- return _doUnload();
135
73
  }
@@ -0,0 +1,120 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+ "use strict";
4
+
5
+ import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
+ import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
+ import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
+ import { ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
9
+ import { _InternalLogMessage } from "./DiagnosticLogger";
10
+ import { doPerf } from "./PerfManager";
11
+ import { LoggingSeverity, _InternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
12
+ import { isFunction } from "./HelperFuncs";
13
+ import { dumpObj } from "./EnvUtils";
14
+
15
+ export class TelemetryPluginChain implements ITelemetryPluginChain {
16
+
17
+ /**
18
+ * Returns the underlying plugin that is being proxied for the processTelemetry call
19
+ */
20
+ getPlugin: () => ITelemetryPlugin;
21
+
22
+ /**
23
+ * Returns the next plugin
24
+ */
25
+ getNext: () => ITelemetryPluginChain;
26
+
27
+ /**
28
+ * Sets the next proxy to be executed as the next plugin
29
+ * (Should only be used during initialization, which is why it's not defined on the interface)
30
+ */
31
+ setNext: (nextPlugin:ITelemetryPluginChain) => void;
32
+
33
+ /**
34
+ * Call back for telemetry processing before it it is sent
35
+ * @param env - This is the current event being reported
36
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
37
+ * can optionally use this to access the current core instance or define / pass additional information
38
+ * to later plugins (vs appending items to the telemetry item)
39
+ */
40
+ processTelemetry: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
41
+
42
+ /**
43
+ * Internal flag used to try and identify root cause failures
44
+ */
45
+ private _hasRun: boolean;
46
+
47
+ constructor(plugin:ITelemetryPlugin, defItemCtx:IProcessTelemetryContext) {
48
+ let _self = this;
49
+ let _nextProxy:ITelemetryPluginChain = null;
50
+ let _hasProcessTelemetry = isFunction(plugin.processTelemetry);
51
+ let _hasSetNext = isFunction(plugin.setNextPlugin);
52
+
53
+ _self._hasRun = false;
54
+
55
+ _self.getPlugin = () => {
56
+ return plugin;
57
+ };
58
+
59
+ _self.getNext = () => {
60
+ return _nextProxy;
61
+ };
62
+
63
+ _self.setNext = (nextPlugin:ITelemetryPluginChain) => {
64
+ _nextProxy = nextPlugin;
65
+ }
66
+
67
+ _self.processTelemetry = (env: ITelemetryItem, itemCtx:IProcessTelemetryContext) => {
68
+ if (!itemCtx) {
69
+ // Looks like a plugin didn't pass the (optional) context, so restore to the default
70
+ itemCtx = defItemCtx;
71
+ }
72
+
73
+ let identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
74
+
75
+ doPerf(itemCtx ? itemCtx.core() : null, () => identifier + ":processTelemetry", () => {
76
+ if (plugin && _hasProcessTelemetry) {
77
+ _self._hasRun = true;
78
+ try {
79
+
80
+ // Ensure that we keep the context in sync (for processNext()), just in case a plugin
81
+ // doesn't calls processTelemetry() instead of itemContext.processNext() or some
82
+ // other form of error occurred
83
+ itemCtx.setNext(_nextProxy);
84
+ if (_hasSetNext) {
85
+ // Backward compatibility setting the next plugin on the instance
86
+ plugin.setNextPlugin(_nextProxy);
87
+ }
88
+
89
+ // Set a flag on the next plugin so we know if it was attempted to be executed
90
+ _nextProxy && ((_nextProxy as TelemetryPluginChain)._hasRun = false);
91
+
92
+ plugin.processTelemetry(env, itemCtx);
93
+ } catch (error) {
94
+ let hasRun = _nextProxy && (_nextProxy as TelemetryPluginChain)._hasRun;
95
+ if (!_nextProxy || !hasRun) {
96
+ // Either we have no next plugin or the current one did not attempt to call the next plugin
97
+ // Which means the current one is the root of the failure so log/report this failure
98
+ itemCtx.diagLog().throwInternal(
99
+ LoggingSeverity.CRITICAL,
100
+ _InternalMessageId.PluginException,
101
+ "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
102
+ }
103
+
104
+ if (_nextProxy && !hasRun) {
105
+ // As part of the failure the current plugin did not attempt to call the next plugin in the cahin
106
+ // So rather than leave the pipeline dead in the water we call the next plugin
107
+ _nextProxy.processTelemetry(env, itemCtx);
108
+ }
109
+ }
110
+ } else if (_nextProxy) {
111
+ _self._hasRun = true;
112
+
113
+ // The underlying plugin is either not defined or does not have a processTelemetry implementation
114
+ // so we still want the next plugin to be executed.
115
+ _nextProxy.processTelemetry(env, itemCtx);
116
+ }
117
+ }, () => ({ item: env }), !((env as any).sync));
118
+ };
119
+ }
120
+ }
@@ -1,9 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
-
4
- import { createEnumStyle } from "../JavaScriptSDK/HelperFuncs";
5
-
6
- export const enum eLoggingSeverity {
3
+ export enum LoggingSeverity {
7
4
  /**
8
5
  * Error will be sent as internal telemetry
9
6
  */
@@ -12,191 +9,97 @@ export const enum eLoggingSeverity {
12
9
  /**
13
10
  * Error will NOT be sent as internal telemetry, and will only be shown in browser console
14
11
  */
15
- WARNING = 2
16
- }
17
-
18
-
19
- export const LoggingSeverity = createEnumStyle<{ [key in (keyof typeof eLoggingSeverity)]: number; }>({
20
- CRITICAL: eLoggingSeverity.CRITICAL,
21
- WARNING: eLoggingSeverity.WARNING
22
- });
23
- export type LoggingSeverity = number | eLoggingSeverity;
24
-
25
- export const enum _eInternalMessageId {
26
- BrowserDoesNotSupportLocalStorage = 0,
27
- BrowserCannotReadLocalStorage = 1,
28
- BrowserCannotReadSessionStorage = 2,
29
- BrowserCannotWriteLocalStorage = 3,
30
- BrowserCannotWriteSessionStorage = 4,
31
- BrowserFailedRemovalFromLocalStorage = 5,
32
- BrowserFailedRemovalFromSessionStorage = 6,
33
- CannotSendEmptyTelemetry = 7,
34
- ClientPerformanceMathError = 8,
35
- ErrorParsingAISessionCookie = 9,
36
- ErrorPVCalc = 10,
37
- ExceptionWhileLoggingError = 11,
38
- FailedAddingTelemetryToBuffer = 12,
39
- FailedMonitorAjaxAbort = 13,
40
- FailedMonitorAjaxDur = 14,
41
- FailedMonitorAjaxOpen = 15,
42
- FailedMonitorAjaxRSC = 16,
43
- FailedMonitorAjaxSend = 17,
44
- FailedMonitorAjaxGetCorrelationHeader = 18,
45
- FailedToAddHandlerForOnBeforeUnload = 19,
46
- FailedToSendQueuedTelemetry = 20,
47
- FailedToReportDataLoss = 21,
48
- FlushFailed = 22,
49
- MessageLimitPerPVExceeded = 23,
50
- MissingRequiredFieldSpecification = 24,
51
- NavigationTimingNotSupported = 25,
52
- OnError = 26,
53
- SessionRenewalDateIsZero = 27,
54
- SenderNotInitialized = 28,
55
- StartTrackEventFailed = 29,
56
- StopTrackEventFailed = 30,
57
- StartTrackFailed = 31,
58
- StopTrackFailed = 32,
59
- TelemetrySampledAndNotSent = 33,
60
- TrackEventFailed = 34,
61
- TrackExceptionFailed = 35,
62
- TrackMetricFailed = 36,
63
- TrackPVFailed = 37,
64
- TrackPVFailedCalc = 38,
65
- TrackTraceFailed = 39,
66
- TransmissionFailed = 40,
67
- FailedToSetStorageBuffer = 41,
68
- FailedToRestoreStorageBuffer = 42,
69
- InvalidBackendResponse = 43,
70
- FailedToFixDepricatedValues = 44,
71
- InvalidDurationValue = 45,
72
- TelemetryEnvelopeInvalid = 46,
73
- CreateEnvelopeError = 47,
74
-
75
- // User actionable
76
- CannotSerializeObject = 48,
77
- CannotSerializeObjectNonSerializable = 49,
78
- CircularReferenceDetected = 50,
79
- ClearAuthContextFailed = 51,
80
- ExceptionTruncated = 52,
81
- IllegalCharsInName = 53,
82
- ItemNotInArray = 54,
83
- MaxAjaxPerPVExceeded = 55,
84
- MessageTruncated = 56,
85
- NameTooLong = 57,
86
- SampleRateOutOfRange = 58,
87
- SetAuthContextFailed = 59,
88
- SetAuthContextFailedAccountName = 60,
89
- StringValueTooLong = 61,
90
- StartCalledMoreThanOnce = 62,
91
- StopCalledWithoutStart = 63,
92
- TelemetryInitializerFailed = 64,
93
- TrackArgumentsNotSpecified = 65,
94
- UrlTooLong = 66,
95
- SessionStorageBufferFull = 67,
96
- CannotAccessCookie = 68,
97
- IdTooLong = 69,
98
- InvalidEvent = 70,
99
- FailedMonitorAjaxSetRequestHeader = 71,
100
- SendBrowserInfoOnUserInit = 72,
101
- PluginException = 73,
102
- NotificationException = 74,
103
- SnippetScriptLoadFailure = 99,
104
- InvalidInstrumentationKey = 100,
105
- CannotParseAiBlobValue = 101,
106
- InvalidContentBlob = 102,
107
- TrackPageActionEventFailed = 103,
108
- FailedAddingCustomDefinedRequestContext = 104,
109
- InMemoryStorageBufferFull = 105
12
+ WARNING = 2,
110
13
  }
111
14
 
112
15
  /**
113
16
  * Internal message ID. Please create a new one for every conceptually different message. Please keep alphabetically ordered
114
17
  */
115
- export const _InternalMessageId = createEnumStyle<{ [key in (keyof typeof _eInternalMessageId)]: number; }>({
18
+ export const _InternalMessageId = {
116
19
  // Non user actionable
117
- BrowserDoesNotSupportLocalStorage: _eInternalMessageId.BrowserDoesNotSupportLocalStorage,
118
- BrowserCannotReadLocalStorage: _eInternalMessageId.BrowserCannotReadLocalStorage,
119
- BrowserCannotReadSessionStorage: _eInternalMessageId.BrowserCannotReadSessionStorage,
120
- BrowserCannotWriteLocalStorage: _eInternalMessageId.BrowserCannotWriteLocalStorage,
121
- BrowserCannotWriteSessionStorage: _eInternalMessageId.BrowserCannotWriteSessionStorage,
122
- BrowserFailedRemovalFromLocalStorage: _eInternalMessageId.BrowserFailedRemovalFromLocalStorage,
123
- BrowserFailedRemovalFromSessionStorage: _eInternalMessageId.BrowserFailedRemovalFromSessionStorage,
124
- CannotSendEmptyTelemetry: _eInternalMessageId.CannotSendEmptyTelemetry,
125
- ClientPerformanceMathError: _eInternalMessageId.ClientPerformanceMathError,
126
- ErrorParsingAISessionCookie: _eInternalMessageId.ErrorParsingAISessionCookie,
127
- ErrorPVCalc: _eInternalMessageId.ErrorPVCalc,
128
- ExceptionWhileLoggingError: _eInternalMessageId.ExceptionWhileLoggingError,
129
- FailedAddingTelemetryToBuffer: _eInternalMessageId.FailedAddingTelemetryToBuffer,
130
- FailedMonitorAjaxAbort: _eInternalMessageId.FailedMonitorAjaxAbort,
131
- FailedMonitorAjaxDur: _eInternalMessageId.FailedMonitorAjaxDur,
132
- FailedMonitorAjaxOpen: _eInternalMessageId.FailedMonitorAjaxOpen,
133
- FailedMonitorAjaxRSC: _eInternalMessageId.FailedMonitorAjaxRSC,
134
- FailedMonitorAjaxSend: _eInternalMessageId.FailedMonitorAjaxSend,
135
- FailedMonitorAjaxGetCorrelationHeader: _eInternalMessageId.FailedMonitorAjaxGetCorrelationHeader,
136
- FailedToAddHandlerForOnBeforeUnload: _eInternalMessageId.FailedToAddHandlerForOnBeforeUnload,
137
- FailedToSendQueuedTelemetry: _eInternalMessageId.FailedToSendQueuedTelemetry,
138
- FailedToReportDataLoss: _eInternalMessageId.FailedToReportDataLoss,
139
- FlushFailed: _eInternalMessageId.FlushFailed,
140
- MessageLimitPerPVExceeded: _eInternalMessageId.MessageLimitPerPVExceeded,
141
- MissingRequiredFieldSpecification: _eInternalMessageId.MissingRequiredFieldSpecification,
142
- NavigationTimingNotSupported: _eInternalMessageId.NavigationTimingNotSupported,
143
- OnError: _eInternalMessageId.OnError,
144
- SessionRenewalDateIsZero: _eInternalMessageId.SessionRenewalDateIsZero,
145
- SenderNotInitialized: _eInternalMessageId.SenderNotInitialized,
146
- StartTrackEventFailed: _eInternalMessageId.StartTrackEventFailed,
147
- StopTrackEventFailed: _eInternalMessageId.StopTrackEventFailed,
148
- StartTrackFailed: _eInternalMessageId.StartTrackFailed,
149
- StopTrackFailed: _eInternalMessageId.StopTrackFailed,
150
- TelemetrySampledAndNotSent: _eInternalMessageId.TelemetrySampledAndNotSent,
151
- TrackEventFailed: _eInternalMessageId.TrackEventFailed,
152
- TrackExceptionFailed: _eInternalMessageId.TrackExceptionFailed,
153
- TrackMetricFailed: _eInternalMessageId.TrackMetricFailed,
154
- TrackPVFailed: _eInternalMessageId.TrackPVFailed,
155
- TrackPVFailedCalc: _eInternalMessageId.TrackPVFailedCalc,
156
- TrackTraceFailed: _eInternalMessageId.TrackTraceFailed,
157
- TransmissionFailed: _eInternalMessageId.TransmissionFailed,
158
- FailedToSetStorageBuffer: _eInternalMessageId.FailedToSetStorageBuffer,
159
- FailedToRestoreStorageBuffer: _eInternalMessageId.FailedToRestoreStorageBuffer,
160
- InvalidBackendResponse: _eInternalMessageId.InvalidBackendResponse,
161
- FailedToFixDepricatedValues: _eInternalMessageId.FailedToFixDepricatedValues,
162
- InvalidDurationValue: _eInternalMessageId.InvalidDurationValue,
163
- TelemetryEnvelopeInvalid: _eInternalMessageId.TelemetryEnvelopeInvalid,
164
- CreateEnvelopeError: _eInternalMessageId.CreateEnvelopeError,
20
+ BrowserDoesNotSupportLocalStorage: 0,
21
+ BrowserCannotReadLocalStorage: 1,
22
+ BrowserCannotReadSessionStorage: 2,
23
+ BrowserCannotWriteLocalStorage: 3,
24
+ BrowserCannotWriteSessionStorage: 4,
25
+ BrowserFailedRemovalFromLocalStorage: 5,
26
+ BrowserFailedRemovalFromSessionStorage: 6,
27
+ CannotSendEmptyTelemetry: 7,
28
+ ClientPerformanceMathError: 8,
29
+ ErrorParsingAISessionCookie: 9,
30
+ ErrorPVCalc: 10,
31
+ ExceptionWhileLoggingError: 11,
32
+ FailedAddingTelemetryToBuffer: 12,
33
+ FailedMonitorAjaxAbort: 13,
34
+ FailedMonitorAjaxDur: 14,
35
+ FailedMonitorAjaxOpen: 15,
36
+ FailedMonitorAjaxRSC: 16,
37
+ FailedMonitorAjaxSend: 17,
38
+ FailedMonitorAjaxGetCorrelationHeader: 18,
39
+ FailedToAddHandlerForOnBeforeUnload: 19,
40
+ FailedToSendQueuedTelemetry: 20,
41
+ FailedToReportDataLoss: 21,
42
+ FlushFailed: 22,
43
+ MessageLimitPerPVExceeded: 23,
44
+ MissingRequiredFieldSpecification: 24,
45
+ NavigationTimingNotSupported: 25,
46
+ OnError: 26,
47
+ SessionRenewalDateIsZero: 27,
48
+ SenderNotInitialized: 28,
49
+ StartTrackEventFailed: 29,
50
+ StopTrackEventFailed: 30,
51
+ StartTrackFailed: 31,
52
+ StopTrackFailed: 32,
53
+ TelemetrySampledAndNotSent: 33,
54
+ TrackEventFailed: 34,
55
+ TrackExceptionFailed: 35,
56
+ TrackMetricFailed: 36,
57
+ TrackPVFailed: 37,
58
+ TrackPVFailedCalc: 38,
59
+ TrackTraceFailed: 39,
60
+ TransmissionFailed: 40,
61
+ FailedToSetStorageBuffer: 41,
62
+ FailedToRestoreStorageBuffer: 42,
63
+ InvalidBackendResponse: 43,
64
+ FailedToFixDepricatedValues: 44,
65
+ InvalidDurationValue: 45,
66
+ TelemetryEnvelopeInvalid: 46,
67
+ CreateEnvelopeError: 47,
165
68
 
166
69
  // User actionable
167
- CannotSerializeObject: _eInternalMessageId.CannotSerializeObject,
168
- CannotSerializeObjectNonSerializable: _eInternalMessageId.CannotSerializeObjectNonSerializable,
169
- CircularReferenceDetected: _eInternalMessageId.CircularReferenceDetected,
170
- ClearAuthContextFailed: _eInternalMessageId.ClearAuthContextFailed,
171
- ExceptionTruncated: _eInternalMessageId.ExceptionTruncated,
172
- IllegalCharsInName: _eInternalMessageId.IllegalCharsInName,
173
- ItemNotInArray: _eInternalMessageId.ItemNotInArray,
174
- MaxAjaxPerPVExceeded: _eInternalMessageId.MaxAjaxPerPVExceeded,
175
- MessageTruncated: _eInternalMessageId.MessageTruncated,
176
- NameTooLong: _eInternalMessageId.NameTooLong,
177
- SampleRateOutOfRange: _eInternalMessageId.SampleRateOutOfRange,
178
- SetAuthContextFailed: _eInternalMessageId.SetAuthContextFailed,
179
- SetAuthContextFailedAccountName: _eInternalMessageId.SetAuthContextFailedAccountName,
180
- StringValueTooLong: _eInternalMessageId.StringValueTooLong,
181
- StartCalledMoreThanOnce: _eInternalMessageId.StartCalledMoreThanOnce,
182
- StopCalledWithoutStart: _eInternalMessageId.StopCalledWithoutStart,
183
- TelemetryInitializerFailed: _eInternalMessageId.TelemetryInitializerFailed,
184
- TrackArgumentsNotSpecified: _eInternalMessageId.TrackArgumentsNotSpecified,
185
- UrlTooLong: _eInternalMessageId.UrlTooLong,
186
- SessionStorageBufferFull: _eInternalMessageId.SessionStorageBufferFull,
187
- CannotAccessCookie: _eInternalMessageId.CannotAccessCookie,
188
- IdTooLong: _eInternalMessageId.IdTooLong,
189
- InvalidEvent: _eInternalMessageId.InvalidEvent,
190
- FailedMonitorAjaxSetRequestHeader: _eInternalMessageId.FailedMonitorAjaxSetRequestHeader,
191
- SendBrowserInfoOnUserInit: _eInternalMessageId.SendBrowserInfoOnUserInit,
192
- PluginException: _eInternalMessageId.PluginException,
193
- NotificationException: _eInternalMessageId.NotificationException,
194
- SnippetScriptLoadFailure: _eInternalMessageId.SnippetScriptLoadFailure,
195
- InvalidInstrumentationKey: _eInternalMessageId.InvalidInstrumentationKey,
196
- CannotParseAiBlobValue: _eInternalMessageId.CannotParseAiBlobValue,
197
- InvalidContentBlob: _eInternalMessageId.InvalidContentBlob,
198
- TrackPageActionEventFailed: _eInternalMessageId.TrackPageActionEventFailed,
199
- FailedAddingCustomDefinedRequestContext: _eInternalMessageId.FailedAddingCustomDefinedRequestContext,
200
- InMemoryStorageBufferFull: _eInternalMessageId.InMemoryStorageBufferFull
201
- });
202
- export type _InternalMessageId = number | _eInternalMessageId;
70
+ CannotSerializeObject: 48,
71
+ CannotSerializeObjectNonSerializable: 49,
72
+ CircularReferenceDetected: 50,
73
+ ClearAuthContextFailed: 51,
74
+ ExceptionTruncated: 52,
75
+ IllegalCharsInName: 53,
76
+ ItemNotInArray: 54,
77
+ MaxAjaxPerPVExceeded: 55,
78
+ MessageTruncated: 56,
79
+ NameTooLong: 57,
80
+ SampleRateOutOfRange: 58,
81
+ SetAuthContextFailed: 59,
82
+ SetAuthContextFailedAccountName: 60,
83
+ StringValueTooLong: 61,
84
+ StartCalledMoreThanOnce: 62,
85
+ StopCalledWithoutStart: 63,
86
+ TelemetryInitializerFailed: 64,
87
+ TrackArgumentsNotSpecified: 65,
88
+ UrlTooLong: 66,
89
+ SessionStorageBufferFull: 67,
90
+ CannotAccessCookie: 68,
91
+ IdTooLong: 69,
92
+ InvalidEvent: 70,
93
+ FailedMonitorAjaxSetRequestHeader: 71,
94
+ SendBrowserInfoOnUserInit: 72,
95
+ PluginException: 73,
96
+ NotificationException: 74,
97
+ SnippetScriptLoadFailure: 99,
98
+ InvalidInstrumentationKey:100,
99
+ CannotParseAiBlobValue: 101,
100
+ InvalidContentBlob: 102,
101
+ TrackPageActionEventFailed: 103,
102
+ FailedAddingCustomDefinedRequestContext: 104,
103
+ InMemoryStorageBufferFull: 105
104
+ };
105
+ export type _InternalMessageId = number | typeof _InternalMessageId;
@@ -38,11 +38,6 @@ 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,
46
41
 
47
42
  /**
48
43
  * Maximum batch size would be exceeded