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

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 (122) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +945 -479
  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 +3904 -877
  7. package/dist/applicationinsights-core-js.api.md +264 -30
  8. package/dist/applicationinsights-core-js.d.ts +410 -89
  9. package/dist/applicationinsights-core-js.js +945 -479
  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 +410 -89
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +66 -23
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +44 -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 +184 -110
  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.Enums/EventsDiscardedReason.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  53. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  54. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  56. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  57. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  73. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  75. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  76. package/dist-esm/applicationinsights-core-js.js +8 -4
  77. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  78. package/package.json +1 -1
  79. package/src/JavaScriptSDK/BaseCore.ts +80 -24
  80. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +76 -5
  81. package/src/JavaScriptSDK/ChannelController.ts +107 -61
  82. package/src/JavaScriptSDK/CookieMgr.ts +4 -4
  83. package/src/JavaScriptSDK/CoreUtils.ts +6 -143
  84. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  85. package/src/JavaScriptSDK/DiagnosticLogger.ts +12 -11
  86. package/src/JavaScriptSDK/EnvUtils.ts +7 -6
  87. package/src/JavaScriptSDK/EventHelpers.ts +542 -0
  88. package/src/JavaScriptSDK/HelperFuncs.ts +35 -54
  89. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  90. package/src/JavaScriptSDK/NotificationManager.ts +7 -11
  91. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +237 -124
  92. package/src/JavaScriptSDK/RandomHelper.ts +2 -1
  93. package/src/JavaScriptSDK/TelemetryHelpers.ts +47 -15
  94. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +5 -15
  95. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
  96. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  97. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +20 -0
  98. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +9 -2
  99. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +55 -16
  100. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +16 -9
  101. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  102. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  103. package/types/JavaScriptSDK/BaseCore.d.ts +4 -0
  104. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +20 -1
  105. package/types/JavaScriptSDK/ChannelController.d.ts +4 -0
  106. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -42
  107. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  108. package/types/JavaScriptSDK/EventHelpers.d.ts +152 -0
  109. package/types/JavaScriptSDK/HelperFuncs.d.ts +8 -17
  110. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  111. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +10 -3
  112. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +8 -0
  113. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -7
  114. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
  115. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +9 -0
  116. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +17 -0
  117. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +9 -2
  118. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +49 -14
  119. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +15 -8
  120. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  121. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  122. package/types/applicationinsights-core-js.d.ts +6 -3
@@ -6,11 +6,22 @@ import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetr
6
6
  import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
8
  import { arrForEach, isFunction } from "./HelperFuncs";
9
+ import { strCore, strIsInitialized, strPriority, strProcessTelemetry, strSetNextPlugin, strTeardown } from "./InternalConstants";
10
+ import { createElmNodeData } from "./DataCacheHelper";
11
+ import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
9
12
 
10
- let processTelemetry = "processTelemetry";
11
- let priority = "priority";
12
- let setNextPlugin = "setNextPlugin";
13
- let isInitialized = "isInitialized";
13
+ export interface IPluginState {
14
+ core?: IAppInsightsCore;
15
+ isInitialized?: boolean;
16
+ tearDown?: boolean;
17
+ disabled?: boolean;
18
+ }
19
+
20
+ const pluginStateData = createElmNodeData("plugin");
21
+
22
+ export function _getPluginState(plugin: IPlugin): IPluginState {
23
+ return pluginStateData.get<IPluginState>(plugin, "state", {}, true)
24
+ }
14
25
 
15
26
  /**
16
27
  * Initialize the queue of plugins
@@ -22,20 +33,29 @@ let isInitialized = "isInitialized";
22
33
  export function initializePlugins(processContext: IProcessTelemetryContext, extensions: IPlugin[]) {
23
34
 
24
35
  // Set the next plugin and identified the uninitialized plugins
25
- let initPlugins:ITelemetryPlugin[] = [];
26
- let lastPlugin:ITelemetryPlugin = null;
27
- let proxy:ITelemetryPluginChain = processContext.getNext();
36
+ let initPlugins: ITelemetryPlugin[] = [];
37
+ let lastPlugin: ITelemetryPlugin = null;
38
+ let proxy: ITelemetryPluginChain = processContext.getNext();
39
+ let pluginState: IPluginState;
28
40
  while (proxy) {
29
41
  let thePlugin = proxy.getPlugin();
30
42
  if (thePlugin) {
31
43
  if (lastPlugin &&
32
- isFunction(lastPlugin[setNextPlugin]) &&
33
- isFunction(thePlugin[processTelemetry])) {
44
+ isFunction(lastPlugin[strSetNextPlugin]) &&
45
+ isFunction(thePlugin[strProcessTelemetry])) {
34
46
  // Set this plugin as the next for the previous one
35
- lastPlugin[setNextPlugin](thePlugin);
47
+ lastPlugin[strSetNextPlugin](thePlugin);
48
+ }
49
+
50
+ let isInitialized = false;
51
+ if (isFunction(thePlugin[strIsInitialized])) {
52
+ isInitialized = thePlugin[strIsInitialized]();
53
+ } else {
54
+ pluginState = _getPluginState(thePlugin);
55
+ isInitialized = pluginState[strIsInitialized];
36
56
  }
37
57
 
38
- if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
58
+ if (!isInitialized) {
39
59
  initPlugins.push(thePlugin);
40
60
  }
41
61
 
@@ -46,11 +66,23 @@ export function initializePlugins(processContext: IProcessTelemetryContext, exte
46
66
 
47
67
  // Now initialize the plugins
48
68
  arrForEach(initPlugins, thePlugin => {
69
+ let core = processContext.core();
70
+
49
71
  thePlugin.initialize(
50
72
  processContext.getCfg(),
51
- processContext.core(),
73
+ core,
52
74
  extensions,
53
75
  processContext.getNext());
76
+
77
+ pluginState = _getPluginState(thePlugin);
78
+
79
+ // Only add the core to the state if the plugin didn't set it (doesn't extent from BaseTelemetryPlugin)
80
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
81
+ pluginState[strCore] = core;
82
+ }
83
+
84
+ pluginState[strIsInitialized] = true;
85
+ delete pluginState[strTeardown];
54
86
  });
55
87
  }
56
88
 
@@ -58,9 +90,9 @@ export function sortPlugins<T = IPlugin>(plugins:T[]) {
58
90
  // Sort by priority
59
91
  return plugins.sort((extA, extB) => {
60
92
  let result = 0;
61
- let bHasProcess = isFunction(extB[processTelemetry]);
62
- if (isFunction(extA[processTelemetry])) {
63
- result = bHasProcess ? extA[priority] - extB[priority] : 1;
93
+ let bHasProcess = isFunction(extB[strProcessTelemetry]);
94
+ if (isFunction(extA[strProcessTelemetry])) {
95
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
64
96
  } else if (bHasProcess) {
65
97
  result = -1;
66
98
  }
@@ -2,13 +2,14 @@
2
2
  // // Licensed under the MIT License.
3
3
 
4
4
  import dynamicProto from "@microsoft/dynamicproto-js";
5
- import { LoggingSeverity, _InternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
5
+ import { eLoggingSeverity, _eInternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
6
6
  import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryInitializerContainer, ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
8
8
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
9
9
  import { BaseTelemetryPlugin } from "./BaseTelemetryPlugin";
10
10
  import { dumpObj } from "./EnvUtils";
11
11
  import { arrForEach, getExceptionName } from "./HelperFuncs";
12
+ import { strDoTeardown } from "./InternalConstants";
12
13
 
13
14
  interface _IInternalTelemetryInitializerHandler {
14
15
  id: number;
@@ -68,8 +69,8 @@ export class TelemetryInitializerPlugin extends BaseTelemetryPlugin implements I
68
69
  // log error but dont stop executing rest of the telemetry initializers
69
70
  // doNotSendItem = true;
70
71
  itemCtx.diagLog().throwInternal(
71
- LoggingSeverity.CRITICAL,
72
- _InternalMessageId.TelemetryInitializerFailed,
72
+ eLoggingSeverity.CRITICAL,
73
+ _eInternalMessageId.TelemetryInitializerFailed,
73
74
  "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e),
74
75
  { exception: dumpObj(e) }, true);
75
76
  }
@@ -81,8 +82,7 @@ export class TelemetryInitializerPlugin extends BaseTelemetryPlugin implements I
81
82
  }
82
83
  };
83
84
 
84
- _self.unload = (itemCtx: IProcessTelemetryContext, isAsync: boolean): void => {
85
- _base.unload(itemCtx, isAsync);
85
+ _self[strDoTeardown] = () => {
86
86
  _initDefaults();
87
87
  };
88
88
  });
@@ -106,14 +106,4 @@ export class TelemetryInitializerPlugin extends BaseTelemetryPlugin implements I
106
106
  public processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void {
107
107
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
108
108
  }
109
-
110
- /**
111
- * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
112
- * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
113
- * @param itemCtx - This is the context that should be used during unloading if required to flush any cached events.
114
- * @param isAsync - Should the plugin attempt to unload synchronously or can it complete asynchronously
115
- */
116
- public unload(itemCtx: IProcessTelemetryContext, isAsync: boolean): void {
117
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
118
- }
119
109
  }
@@ -1,6 +1,9 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
- export enum LoggingSeverity {
3
+
4
+ import { createEnumStyle } from "../JavaScriptSDK/HelperFuncs";
5
+
6
+ export const enum eLoggingSeverity {
4
7
  /**
5
8
  * Error will be sent as internal telemetry
6
9
  */
@@ -9,97 +12,191 @@ export enum LoggingSeverity {
9
12
  /**
10
13
  * Error will NOT be sent as internal telemetry, and will only be shown in browser console
11
14
  */
12
- WARNING = 2,
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
13
110
  }
14
111
 
15
112
  /**
16
113
  * Internal message ID. Please create a new one for every conceptually different message. Please keep alphabetically ordered
17
114
  */
18
- export const _InternalMessageId = {
115
+ export const _InternalMessageId = createEnumStyle<{ [key in (keyof typeof _eInternalMessageId)]: number; }>({
19
116
  // Non user actionable
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,
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,
68
165
 
69
166
  // User actionable
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;
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;
@@ -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
+ }
@@ -14,6 +14,21 @@ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./IT
14
14
 
15
15
  export interface ILoadedPlugin<T extends IPlugin> {
16
16
  plugin: T;
17
+
18
+ /**
19
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
20
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
21
+ * @returns boolean = true if the plugin is in a state where it is operational.
22
+ */
23
+ isEnabled: () => boolean;
24
+
25
+ /**
26
+ * You can optionally enable / disable a plugin from processing events.
27
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
28
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
29
+ * (unless it's also been re-initialized)
30
+ */
31
+ setEnabled: (isEnabled: boolean) => void;
17
32
  }
18
33
 
19
34
  export interface IAppInsightsCore extends IPerfManagerProvider {
@@ -96,4 +111,9 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
96
111
  * @param pluginIdentifier
97
112
  */
98
113
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
114
+
115
+ /**
116
+ * Returns the unique event namespace that should be used when registering events
117
+ */
118
+ evtNamespace(): string;
99
119
  }
@@ -1,7 +1,9 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
3
  import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
4
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
4
5
  import { ITelemetryPlugin } from "./ITelemetryPlugin";
6
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
5
7
 
6
8
  "use strict";
7
9
 
@@ -21,9 +23,14 @@ export interface IChannelControls extends ITelemetryPlugin {
21
23
  resume(): void;
22
24
 
23
25
  /**
24
- * 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.
25
32
  */
26
- teardown(): void;
33
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
27
34
 
28
35
  /**
29
36
  * Flush to send data immediately; channel should default to sending data asynchronously
@@ -3,11 +3,12 @@
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
9
  import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
10
10
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
11
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
11
12
 
12
13
  export const enum GetExtCfgMergeType {
13
14
  None = 0,
@@ -15,11 +16,7 @@ export const enum GetExtCfgMergeType {
15
16
  MergeDefaultFromRootOrDefault = 2,
16
17
  }
17
18
 
18
- /**
19
- * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
20
- * between multiple AppInsights instances
21
- */
22
- export interface IProcessTelemetryContext {
19
+ export interface IBaseProcessingContext {
23
20
  /**
24
21
  * The current core instance for the request
25
22
  */
@@ -65,12 +62,6 @@ export interface IProcessTelemetryContext {
65
62
  */
66
63
  setNext: (nextCtx: ITelemetryPluginChain) => void;
67
64
 
68
- /**
69
- * Call back for telemetry processing before it it is sent
70
- * @param env - This is the current event being reported
71
- */
72
- processNext: (env: ITelemetryItem) => void;
73
-
74
65
  /**
75
66
  * Synchronously iterate over the context chain running the callback for each plugin, once
76
67
  * every plugin has been executed via the callback, any associated onComplete will be called.
@@ -79,16 +70,64 @@ export interface IProcessTelemetryContext {
79
70
  iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
80
71
 
81
72
  /**
82
- * Create a new context using the core and config from the current instance
73
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
74
+ * @param onComplete - The onComplete to call
75
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
76
+ * @param args - Any additional arguments to pass to the onComplete function
77
+ */
78
+ onComplete: (onComplete: Function, that?: any, ...args: any[]) => void;
79
+
80
+ /**
81
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
83
82
  * @param plugins - The execution order to process the plugins, if null or not supplied
84
83
  * then the current execution order will be copied.
85
84
  * @param startAt - The plugin to start processing from, if missing from the execution
86
85
  * order then the next plugin will be NOT set.
87
86
  */
88
- createNew: (plugins?:IPlugin[]|ITelemetryPluginChain, startAt?:IPlugin) => IProcessTelemetryContext;
87
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
88
+ }
89
89
 
90
+ /**
91
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
92
+ * between multiple AppInsights instances
93
+ */
94
+ export interface IProcessTelemetryContext extends IBaseProcessingContext {
90
95
  /**
91
- * Set the function to call when the current chain has executed all processNext or unloadNext items.
96
+ * Call back for telemetry processing before it it is sent
97
+ * @param env - This is the current event being reported
98
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
99
+ */
100
+ processNext: (env: ITelemetryItem) => boolean | void;
101
+
102
+ /**
103
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
104
+ * @param plugins - The execution order to process the plugins, if null or not supplied
105
+ * then the current execution order will be copied.
106
+ * @param startAt - The plugin to start processing from, if missing from the execution
107
+ * order then the next plugin will be NOT set.
108
+ */
109
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
110
+ }
111
+
112
+ /**
113
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
114
+ * between multiple AppInsights instances
115
+ */
116
+ export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
117
+
118
+ /**
119
+ * This Plugin has finished unloading, so unload the next one
120
+ * @param uploadState - The state of the unload process
121
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
122
+ */
123
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
124
+
125
+ /**
126
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
127
+ * @param plugins - The execution order to process the plugins, if null or not supplied
128
+ * then the current execution order will be copied.
129
+ * @param startAt - The plugin to start processing from, if missing from the execution
130
+ * order then the next plugin will be NOT set.
92
131
  */
93
- onComplete: (onComplete: () => void) => void;
132
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
94
133
  }