@microsoft/applicationinsights-core-js 3.0.0-beta.2211-03 → 3.0.0-beta.2212-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 (102) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1156 -1345
  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 +85 -85
  7. package/dist/applicationinsights-core-js.api.md +8 -8
  8. package/dist/applicationinsights-core-js.d.ts +7 -7
  9. package/dist/applicationinsights-core-js.js +1156 -1345
  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 +7 -7
  14. package/dist-esm/Config/ConfigDefaults.js +1 -1
  15. package/dist-esm/Config/DynamicConfig.js +1 -1
  16. package/dist-esm/Config/DynamicProperty.js +1 -1
  17. package/dist-esm/Config/DynamicState.js +1 -1
  18. package/dist-esm/Config/DynamicSupport.js +1 -1
  19. package/dist-esm/Config/IConfigDefaults.js +1 -1
  20. package/dist-esm/Config/IDynamicConfigHandler.js +1 -1
  21. package/dist-esm/Config/IDynamicPropertyHandler.js +1 -1
  22. package/dist-esm/Config/IDynamicWatcher.js +1 -1
  23. package/dist-esm/Config/_IDynamicConfigHandlerState.js +1 -1
  24. package/dist-esm/JavaScriptSDK/AggregationError.js +1 -1
  25. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +93 -63
  26. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  27. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
  28. package/dist-esm/JavaScriptSDK/Constants.js +8 -0
  29. package/dist-esm/JavaScriptSDK/Constants.js.map +1 -0
  30. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  31. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  32. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
  33. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  35. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  36. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  37. package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
  38. package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
  39. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  40. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  41. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  42. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  43. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +5 -5
  44. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  46. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +5 -8
  47. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  48. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
  49. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
  50. package/dist-esm/JavaScriptSDK/W3cTraceParent.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
  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/IDistributedTraceContext.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  75. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
  77. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js +1 -1
  78. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
  79. package/dist-esm/__DynamicConstants.js +15 -17
  80. package/dist-esm/__DynamicConstants.js.map +1 -1
  81. package/dist-esm/applicationinsights-core-js.js +1 -1
  82. package/package.json +2 -2
  83. package/src/JavaScriptSDK/AppInsightsCore.ts +98 -66
  84. package/src/JavaScriptSDK/Constants.ts +4 -0
  85. package/src/JavaScriptSDK/TelemetryHelpers.ts +5 -6
  86. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +2 -2
  87. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +4 -4
  88. package/types/Config/IConfigDefaults.d.ts +3 -3
  89. package/types/Config/IDynamicWatcher.d.ts +1 -1
  90. package/types/JavaScriptSDK/AppInsightsCore.d.ts +1 -1
  91. package/types/JavaScriptSDK/Constants.d.ts +1 -0
  92. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +1 -1
  93. package/types/JavaScriptSDK.Enums/EventsDiscardedReason.d.ts +1 -1
  94. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +2 -2
  95. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +1 -1
  96. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +4 -4
  97. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +1 -1
  98. package/types/__DynamicConstants.d.ts +2 -4
  99. package/dist-esm/JavaScriptSDK/ChannelController.js +0 -217
  100. package/dist-esm/JavaScriptSDK/ChannelController.js.map +0 -1
  101. package/src/JavaScriptSDK/ChannelController.ts +0 -274
  102. package/types/JavaScriptSDK/ChannelController.d.ts +0 -19
@@ -1,217 +0,0 @@
1
- /*
2
- * Application Insights JavaScript SDK - Core, 3.0.0-beta.2211-03
3
- * Copyright (c) Microsoft and contributors. All rights reserved.
4
- */
5
-
6
- //
7
- import { arrForEach, isArray, objFreeze, scheduleTimeout, throwError } from "@nevware21/ts-utils";
8
- import { _DYN_CANCEL, _DYN_CONFIG, _DYN_CREATE_NEW, _DYN_FLUSH, _DYN_IDENTIFIER, _DYN_LENGTH, _DYN_ON_COMPLETE, _DYN_PROCESS_NEXT, _DYN_PUSH } from "../__DynamicConstants";
9
- import { STR_PRIORITY } from "./InternalConstants";
10
- import { createProcessTelemetryContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
11
- import { initializePlugins } from "./TelemetryHelpers";
12
- export var ChannelControllerPriority = 500;
13
- var ChannelValidationMessage = "Channel has invalid priority - ";
14
- function _addChannelQueue(channelQueue, queue, core) {
15
- if (queue && isArray(queue) && queue[_DYN_LENGTH /* @min:%2elength */] > 0) {
16
- queue = queue.sort(function (a, b) {
17
- return a[STR_PRIORITY /* @min:%2epriority */] - b[STR_PRIORITY /* @min:%2epriority */];
18
- });
19
- arrForEach(queue, function (queueItem) {
20
- if (queueItem[STR_PRIORITY /* @min:%2epriority */] < ChannelControllerPriority) {
21
- throwError(ChannelValidationMessage + queueItem[_DYN_IDENTIFIER /* @min:%2eidentifier */]);
22
- }
23
- });
24
- channelQueue[_DYN_PUSH /* @min:%2epush */]({
25
- queue: objFreeze(queue),
26
- chain: createTelemetryProxyChain(queue, core[_DYN_CONFIG /* @min:%2econfig */], core)
27
- });
28
- }
29
- }
30
- export function createChannelControllerPlugin(channelQueue, core) {
31
- function _getTelCtx() {
32
- return createProcessTelemetryContext(null, core[_DYN_CONFIG /* @min:%2econfig */], core, null);
33
- }
34
- function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
35
- var waiting = theChannels ? (theChannels[_DYN_LENGTH /* @min:%2elength */] + 1) : 1;
36
- function _runChainOnComplete() {
37
- waiting--;
38
- if (waiting === 0) {
39
- onComplete && onComplete();
40
- onComplete = null;
41
- }
42
- }
43
- if (waiting > 0) {
44
- arrForEach(theChannels, function (channels) {
45
- // pass on to first item in queue
46
- if (channels && channels.queue[_DYN_LENGTH /* @min:%2elength */] > 0) {
47
- var channelChain = channels.chain;
48
- var chainCtx = itemCtx[_DYN_CREATE_NEW /* @min:%2ecreateNew */](channelChain);
49
- chainCtx[_DYN_ON_COMPLETE /* @min:%2eonComplete */](_runChainOnComplete);
50
- // Cause this chain to start processing
51
- processFn(chainCtx);
52
- }
53
- else {
54
- waiting--;
55
- }
56
- });
57
- }
58
- _runChainOnComplete();
59
- }
60
- function _doUpdate(updateCtx, updateState) {
61
- var theUpdateState = updateState || {
62
- reason: 0 /* TelemetryUpdateReason.Unknown */
63
- };
64
- _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
65
- chainCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUpdateState);
66
- }, function () {
67
- updateCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUpdateState);
68
- });
69
- return true;
70
- }
71
- function _doTeardown(unloadCtx, unloadState) {
72
- var theUnloadState = unloadState || {
73
- reason: 0 /* TelemetryUnloadReason.ManualTeardown */,
74
- isAsync: false
75
- };
76
- _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
77
- chainCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUnloadState);
78
- }, function () {
79
- unloadCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUnloadState);
80
- isInitialized = false;
81
- });
82
- return true;
83
- }
84
- function _getChannel(pluginIdentifier) {
85
- var thePlugin = null;
86
- if (channelQueue && channelQueue[_DYN_LENGTH /* @min:%2elength */] > 0) {
87
- arrForEach(channelQueue, function (channels) {
88
- // pass on to first item in queue
89
- if (channels && channels.queue[_DYN_LENGTH /* @min:%2elength */] > 0) {
90
- arrForEach(channels.queue, function (ext) {
91
- if (ext[_DYN_IDENTIFIER /* @min:%2eidentifier */] === pluginIdentifier) {
92
- thePlugin = ext;
93
- // Cause arrForEach to stop iterating
94
- return -1;
95
- }
96
- });
97
- if (thePlugin) {
98
- // Cause arrForEach to stop iterating
99
- return -1;
100
- }
101
- }
102
- });
103
- }
104
- return thePlugin;
105
- }
106
- var isInitialized = false;
107
- var channelController = {
108
- identifier: "ChannelControllerPlugin",
109
- priority: ChannelControllerPriority,
110
- initialize: function (config, core, extensions, pluginChain) {
111
- isInitialized = true;
112
- arrForEach(channelQueue, function (channels) {
113
- if (channels && channels.queue[_DYN_LENGTH /* @min:%2elength */] > 0) {
114
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
115
- }
116
- });
117
- },
118
- isInitialized: function () {
119
- return isInitialized;
120
- },
121
- processTelemetry: function (item, itemCtx) {
122
- _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
123
- chainCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](item);
124
- }, function () {
125
- itemCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](item);
126
- });
127
- },
128
- update: _doUpdate,
129
- pause: function () {
130
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
131
- chainCtx.iterate(function (plugin) {
132
- plugin.pause && plugin.pause();
133
- });
134
- }, null);
135
- },
136
- resume: function () {
137
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
138
- chainCtx.iterate(function (plugin) {
139
- plugin.resume && plugin.resume();
140
- });
141
- }, null);
142
- },
143
- teardown: _doTeardown,
144
- getChannel: _getChannel,
145
- flush: function (isAsync, callBack, sendReason, cbTimeout) {
146
- // Setting waiting to one so that we don't call the callBack until we finish iterating
147
- var waiting = 1;
148
- var doneIterating = false;
149
- var cbTimer = null;
150
- cbTimeout = cbTimeout || 5000;
151
- function doCallback() {
152
- waiting--;
153
- if (doneIterating && waiting === 0) {
154
- cbTimer && cbTimer[_DYN_CANCEL /* @min:%2ecancel */]();
155
- cbTimer = null;
156
- callBack && callBack(doneIterating);
157
- callBack = null;
158
- }
159
- }
160
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
161
- chainCtx.iterate(function (plugin) {
162
- if (plugin[_DYN_FLUSH /* @min:%2eflush */]) {
163
- waiting++;
164
- var handled_1 = false;
165
- // Not all channels will call this callback for every scenario
166
- if (!plugin[_DYN_FLUSH /* @min:%2eflush */](isAsync, function () {
167
- handled_1 = true;
168
- doCallback();
169
- }, sendReason)) {
170
- if (!handled_1) {
171
- // If any channel doesn't return true and it didn't call the callback, then we should assume that the callback
172
- // will never be called, so use a timeout to allow the channel(s) some time to "finish" before triggering any
173
- // followup function (such as unloading)
174
- if (isAsync && cbTimer == null) {
175
- cbTimer = scheduleTimeout(function () {
176
- cbTimer = null;
177
- doCallback();
178
- }, cbTimeout);
179
- }
180
- else {
181
- doCallback();
182
- }
183
- }
184
- }
185
- }
186
- });
187
- }, function () {
188
- doneIterating = true;
189
- doCallback();
190
- });
191
- return true;
192
- },
193
- _setQueue: function (queue) {
194
- channelQueue = queue;
195
- }
196
- };
197
- return channelController;
198
- }
199
- export function createChannelQueues(channels, extensions, core) {
200
- var channelQueue = [];
201
- if (channels) {
202
- // Add and sort the configuration channel queues
203
- arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, core); });
204
- }
205
- if (extensions) {
206
- // Create a new channel queue for any extensions with a priority > the ChannelControllerPriority
207
- var extensionQueue_1 = [];
208
- arrForEach(extensions, function (plugin) {
209
- if (plugin[STR_PRIORITY /* @min:%2epriority */] > ChannelControllerPriority) {
210
- extensionQueue_1[_DYN_PUSH /* @min:%2epush */](plugin);
211
- }
212
- });
213
- _addChannelQueue(channelQueue, extensionQueue_1, core);
214
- }
215
- return channelQueue;
216
- }
217
- //# sourceMappingURL=ChannelController.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChannelController.js.map","sources":["ChannelController.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// // Licensed under the MIT License.\r\nimport { arrForEach, isArray, objFreeze, scheduleTimeout, throwError } from \"@nevware21/ts-utils\";\r\nimport { _DYN_CANCEL, _DYN_CONFIG, _DYN_CREATE_NEW, _DYN_FLUSH, _DYN_IDENTIFIER, _DYN_LENGTH, _DYN_ON_COMPLETE, _DYN_PROCESS_NEXT, _DYN_PUSH } from \"../__DynamicConstants\";\r\nimport { STR_PRIORITY } from \"./InternalConstants\";\r\nimport { createProcessTelemetryContext, createTelemetryProxyChain } from \"./ProcessTelemetryContext\";\r\nimport { initializePlugins } from \"./TelemetryHelpers\";\r\nexport var ChannelControllerPriority = 500;\r\nvar ChannelValidationMessage = \"Channel has invalid priority - \";\r\nfunction _addChannelQueue(channelQueue, queue, core) {\r\n if (queue && isArray(queue) && queue[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n queue = queue.sort(function (a, b) {\r\n return a[STR_PRIORITY /* @min:%2epriority */] - b[STR_PRIORITY /* @min:%2epriority */];\r\n });\r\n arrForEach(queue, function (queueItem) {\r\n if (queueItem[STR_PRIORITY /* @min:%2epriority */] < ChannelControllerPriority) {\r\n throwError(ChannelValidationMessage + queueItem[_DYN_IDENTIFIER /* @min:%2eidentifier */]);\r\n }\r\n });\r\n channelQueue[_DYN_PUSH /* @min:%2epush */]({\r\n queue: objFreeze(queue),\r\n chain: createTelemetryProxyChain(queue, core[_DYN_CONFIG /* @min:%2econfig */], core)\r\n });\r\n }\r\n}\r\nexport function createChannelControllerPlugin(channelQueue, core) {\r\n function _getTelCtx() {\r\n return createProcessTelemetryContext(null, core[_DYN_CONFIG /* @min:%2econfig */], core, null);\r\n }\r\n function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {\r\n var waiting = theChannels ? (theChannels[_DYN_LENGTH /* @min:%2elength */] + 1) : 1;\r\n function _runChainOnComplete() {\r\n waiting--;\r\n if (waiting === 0) {\r\n onComplete && onComplete();\r\n onComplete = null;\r\n }\r\n }\r\n if (waiting > 0) {\r\n arrForEach(theChannels, function (channels) {\r\n // pass on to first item in queue\r\n if (channels && channels.queue[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n var channelChain = channels.chain;\r\n var chainCtx = itemCtx[_DYN_CREATE_NEW /* @min:%2ecreateNew */](channelChain);\r\n chainCtx[_DYN_ON_COMPLETE /* @min:%2eonComplete */](_runChainOnComplete);\r\n // Cause this chain to start processing\r\n processFn(chainCtx);\r\n }\r\n else {\r\n waiting--;\r\n }\r\n });\r\n }\r\n _runChainOnComplete();\r\n }\r\n function _doUpdate(updateCtx, updateState) {\r\n var theUpdateState = updateState || {\r\n reason: 0 /* TelemetryUpdateReason.Unknown */\r\n };\r\n _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {\r\n chainCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUpdateState);\r\n }, function () {\r\n updateCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUpdateState);\r\n });\r\n return true;\r\n }\r\n function _doTeardown(unloadCtx, unloadState) {\r\n var theUnloadState = unloadState || {\r\n reason: 0 /* TelemetryUnloadReason.ManualTeardown */,\r\n isAsync: false\r\n };\r\n _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {\r\n chainCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUnloadState);\r\n }, function () {\r\n unloadCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](theUnloadState);\r\n isInitialized = false;\r\n });\r\n return true;\r\n }\r\n function _getChannel(pluginIdentifier) {\r\n var thePlugin = null;\r\n if (channelQueue && channelQueue[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n arrForEach(channelQueue, function (channels) {\r\n // pass on to first item in queue\r\n if (channels && channels.queue[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n arrForEach(channels.queue, function (ext) {\r\n if (ext[_DYN_IDENTIFIER /* @min:%2eidentifier */] === pluginIdentifier) {\r\n thePlugin = ext;\r\n // Cause arrForEach to stop iterating\r\n return -1;\r\n }\r\n });\r\n if (thePlugin) {\r\n // Cause arrForEach to stop iterating\r\n return -1;\r\n }\r\n }\r\n });\r\n }\r\n return thePlugin;\r\n }\r\n var isInitialized = false;\r\n var channelController = {\r\n identifier: \"ChannelControllerPlugin\",\r\n priority: ChannelControllerPriority,\r\n initialize: function (config, core, extensions, pluginChain) {\r\n isInitialized = true;\r\n arrForEach(channelQueue, function (channels) {\r\n if (channels && channels.queue[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);\r\n }\r\n });\r\n },\r\n isInitialized: function () {\r\n return isInitialized;\r\n },\r\n processTelemetry: function (item, itemCtx) {\r\n _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {\r\n chainCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](item);\r\n }, function () {\r\n itemCtx[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](item);\r\n });\r\n },\r\n update: _doUpdate,\r\n pause: function () {\r\n _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {\r\n chainCtx.iterate(function (plugin) {\r\n plugin.pause && plugin.pause();\r\n });\r\n }, null);\r\n },\r\n resume: function () {\r\n _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {\r\n chainCtx.iterate(function (plugin) {\r\n plugin.resume && plugin.resume();\r\n });\r\n }, null);\r\n },\r\n teardown: _doTeardown,\r\n getChannel: _getChannel,\r\n flush: function (isAsync, callBack, sendReason, cbTimeout) {\r\n // Setting waiting to one so that we don't call the callBack until we finish iterating\r\n var waiting = 1;\r\n var doneIterating = false;\r\n var cbTimer = null;\r\n cbTimeout = cbTimeout || 5000;\r\n function doCallback() {\r\n waiting--;\r\n if (doneIterating && waiting === 0) {\r\n cbTimer && cbTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n cbTimer = null;\r\n callBack && callBack(doneIterating);\r\n callBack = null;\r\n }\r\n }\r\n _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {\r\n chainCtx.iterate(function (plugin) {\r\n if (plugin[_DYN_FLUSH /* @min:%2eflush */]) {\r\n waiting++;\r\n var handled_1 = false;\r\n // Not all channels will call this callback for every scenario\r\n if (!plugin[_DYN_FLUSH /* @min:%2eflush */](isAsync, function () {\r\n handled_1 = true;\r\n doCallback();\r\n }, sendReason)) {\r\n if (!handled_1) {\r\n // If any channel doesn't return true and it didn't call the callback, then we should assume that the callback\r\n // will never be called, so use a timeout to allow the channel(s) some time to \"finish\" before triggering any\r\n // followup function (such as unloading)\r\n if (isAsync && cbTimer == null) {\r\n cbTimer = scheduleTimeout(function () {\r\n cbTimer = null;\r\n doCallback();\r\n }, cbTimeout);\r\n }\r\n else {\r\n doCallback();\r\n }\r\n }\r\n }\r\n }\r\n });\r\n }, function () {\r\n doneIterating = true;\r\n doCallback();\r\n });\r\n return true;\r\n },\r\n _setQueue: function (queue) {\r\n channelQueue = queue;\r\n }\r\n };\r\n return channelController;\r\n}\r\nexport function createChannelQueues(channels, extensions, core) {\r\n var channelQueue = [];\r\n if (channels) {\r\n // Add and sort the configuration channel queues\r\n arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, core); });\r\n }\r\n if (extensions) {\r\n // Create a new channel queue for any extensions with a priority > the ChannelControllerPriority\r\n var extensionQueue_1 = [];\r\n arrForEach(extensions, function (plugin) {\r\n if (plugin[STR_PRIORITY /* @min:%2epriority */] > ChannelControllerPriority) {\r\n extensionQueue_1[_DYN_PUSH /* @min:%2epush */](plugin);\r\n }\r\n });\r\n _addChannelQueue(channelQueue, extensionQueue_1, core);\r\n }\r\n return channelQueue;\r\n}\r\n//# sourceMappingURL=ChannelController.js.map"],"names":[],"mappings":";;;;AAA4D;AAC5D,GAAqC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1,274 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // // Licensed under the MIT License.
3
-
4
- import { ITimerHandler, arrForEach, isArray, objFreeze, scheduleTimeout, throwError } from "@nevware21/ts-utils";
5
- import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
6
- import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
7
- import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
8
- import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
9
- import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
10
- import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
11
- import {
12
- IBaseProcessingContext, IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext
13
- } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
14
- import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
15
- import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
16
- import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
17
- import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
18
- import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
19
- import { createProcessTelemetryContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
20
- import { initializePlugins } from "./TelemetryHelpers";
21
-
22
- export const ChannelControllerPriority = 500;
23
-
24
- const ChannelValidationMessage = "Channel has invalid priority - ";
25
-
26
- export interface IChannelController extends IChannelControls {
27
- flush(isAsync: boolean, callBack: (flushComplete?: boolean) => void, sendReason: SendRequestReason, cbTimeout?: number): void;
28
-
29
- getChannel<T extends IPlugin = IPlugin>(pluginIdentifier: string): T;
30
- }
31
-
32
- export interface IInternalChannelController extends IChannelController {
33
- _setQueue: (channels: _IInternalChannels[]) => void;
34
- }
35
-
36
- export interface _IInternalChannels {
37
- queue: IChannelControls[];
38
- chain: ITelemetryPluginChain;
39
- }
40
-
41
- function _addChannelQueue(channelQueue: _IInternalChannels[], queue: IChannelControls[], core: IAppInsightsCore) {
42
- if (queue && isArray(queue) && queue.length > 0) {
43
- queue = queue.sort((a, b) => { // sort based on priority within each queue
44
- return a.priority - b.priority;
45
- });
46
-
47
- arrForEach(queue, queueItem => {
48
- if (queueItem.priority < ChannelControllerPriority) {
49
- throwError(ChannelValidationMessage + queueItem.identifier);
50
- }
51
- });
52
-
53
- channelQueue.push({
54
- queue: objFreeze(queue),
55
- chain: createTelemetryProxyChain(queue, core.config, core)
56
- });
57
- }
58
- }
59
-
60
- export function createChannelControllerPlugin(channelQueue: _IInternalChannels[], core: IAppInsightsCore): IChannelController {
61
-
62
- function _getTelCtx() {
63
- return createProcessTelemetryContext(null, core.config, core, null)
64
- }
65
-
66
- function _processChannelQueue<T extends IBaseProcessingContext>(theChannels: _IInternalChannels[], itemCtx: T, processFn: (chainCtx: T) => void, onComplete: (() => void) | null) {
67
- let waiting = theChannels ? (theChannels.length + 1) : 1;
68
-
69
- function _runChainOnComplete() {
70
- waiting --;
71
-
72
- if (waiting === 0) {
73
- onComplete && onComplete();
74
- onComplete = null;
75
- }
76
- }
77
-
78
- if (waiting > 0) {
79
- arrForEach(theChannels, (channels) => {
80
- // pass on to first item in queue
81
- if (channels && channels.queue.length > 0) {
82
- let channelChain = channels.chain;
83
- let chainCtx = itemCtx.createNew(channelChain) as T;
84
- chainCtx.onComplete(_runChainOnComplete);
85
-
86
- // Cause this chain to start processing
87
- processFn(chainCtx);
88
- } else {
89
- waiting --;
90
- }
91
- });
92
- }
93
-
94
- _runChainOnComplete();
95
- }
96
-
97
- function _doUpdate(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) {
98
- let theUpdateState: ITelemetryUpdateState = updateState || {
99
- reason: TelemetryUpdateReason.Unknown
100
- };
101
-
102
- _processChannelQueue(channelQueue, updateCtx, (chainCtx: IProcessTelemetryUpdateContext) => {
103
- chainCtx.processNext(theUpdateState);
104
- }, () => {
105
- updateCtx.processNext(theUpdateState);
106
- });
107
-
108
- return true;
109
- }
110
-
111
- function _doTeardown(unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) {
112
- let theUnloadState: ITelemetryUnloadState = unloadState || {
113
- reason: TelemetryUnloadReason.ManualTeardown,
114
- isAsync: false
115
- };
116
-
117
- _processChannelQueue(channelQueue, unloadCtx, (chainCtx: IProcessTelemetryUnloadContext) => {
118
- chainCtx.processNext(theUnloadState);
119
- }, () => {
120
- unloadCtx.processNext(theUnloadState);
121
- isInitialized = false;
122
- });
123
-
124
- return true;
125
- }
126
-
127
- function _getChannel<T extends IPlugin = IPlugin>(pluginIdentifier: string): T {
128
- let thePlugin: T = null;
129
-
130
- if (channelQueue && channelQueue.length > 0) {
131
- arrForEach(channelQueue, (channels) => {
132
- // pass on to first item in queue
133
- if (channels && channels.queue.length > 0) {
134
- arrForEach(channels.queue, (ext: any) => {
135
- if (ext.identifier === pluginIdentifier) {
136
- thePlugin = ext;
137
- // Cause arrForEach to stop iterating
138
- return -1;
139
- }
140
- });
141
-
142
- if (thePlugin) {
143
- // Cause arrForEach to stop iterating
144
- return -1;
145
- }
146
- }
147
- });
148
- }
149
-
150
- return thePlugin;
151
- }
152
-
153
- let isInitialized = false;
154
- let channelController: IInternalChannelController = {
155
- identifier: "ChannelControllerPlugin",
156
- priority: ChannelControllerPriority,
157
- initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => {
158
- isInitialized = true;
159
- arrForEach(channelQueue, (channels) => {
160
- if (channels && channels.queue.length > 0) {
161
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
162
- }
163
- });
164
- },
165
- isInitialized: () => {
166
- return isInitialized
167
- },
168
- processTelemetry: (item: ITelemetryItem, itemCtx: IProcessTelemetryContext) => {
169
- _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), (chainCtx: IProcessTelemetryContext) => {
170
- chainCtx.processNext(item);
171
- }, () => {
172
- itemCtx.processNext(item);
173
- });
174
- },
175
- update: _doUpdate,
176
- pause: () => {
177
- _processChannelQueue(channelQueue, _getTelCtx(), (chainCtx: IProcessTelemetryContext) => {
178
- chainCtx.iterate<IChannelControls>((plugin) => {
179
- plugin.pause && plugin.pause();
180
- });
181
- }, null);
182
- },
183
- resume: () => {
184
- _processChannelQueue(channelQueue, _getTelCtx(), (chainCtx: IProcessTelemetryContext) => {
185
- chainCtx.iterate<IChannelControls>((plugin) => {
186
- plugin.resume && plugin.resume();
187
- });
188
- }, null);
189
- },
190
- teardown: _doTeardown,
191
- getChannel: _getChannel,
192
- flush: (isAsync: boolean, callBack: (flushComplete?: boolean) => void, sendReason: SendRequestReason, cbTimeout?: number) => {
193
- // Setting waiting to one so that we don't call the callBack until we finish iterating
194
- let waiting = 1;
195
- let doneIterating = false;
196
- let cbTimer: ITimerHandler = null;
197
-
198
- cbTimeout = cbTimeout || 5000;
199
-
200
- function doCallback() {
201
- waiting--;
202
- if (doneIterating && waiting === 0) {
203
- cbTimer && cbTimer.cancel();
204
- cbTimer = null;
205
-
206
- callBack && callBack(doneIterating);
207
- callBack = null;
208
- }
209
- }
210
-
211
- _processChannelQueue(channelQueue, _getTelCtx(), (chainCtx: IProcessTelemetryContext) => {
212
- chainCtx.iterate<IChannelControls>((plugin) => {
213
- if (plugin.flush) {
214
- waiting ++;
215
-
216
- let handled = false;
217
- // Not all channels will call this callback for every scenario
218
- if (!plugin.flush(isAsync, () => {
219
- handled = true;
220
- doCallback();
221
- }, sendReason)) {
222
- if (!handled) {
223
- // If any channel doesn't return true and it didn't call the callback, then we should assume that the callback
224
- // will never be called, so use a timeout to allow the channel(s) some time to "finish" before triggering any
225
- // followup function (such as unloading)
226
- if (isAsync && cbTimer == null) {
227
- cbTimer = scheduleTimeout(() => {
228
- cbTimer = null;
229
- doCallback();
230
- }, cbTimeout);
231
- } else {
232
- doCallback();
233
- }
234
- }
235
- }
236
- }
237
- });
238
- }, () => {
239
- doneIterating = true;
240
- doCallback();
241
- });
242
-
243
- return true;
244
- },
245
- _setQueue: (queue: _IInternalChannels[]) => {
246
- channelQueue = queue;
247
- }
248
- };
249
-
250
- return channelController;
251
- }
252
-
253
- export function createChannelQueues(channels: IChannelControls[][], extensions: IPlugin[], core: IAppInsightsCore) {
254
- let channelQueue: _IInternalChannels[] = [];
255
-
256
- if (channels) {
257
- // Add and sort the configuration channel queues
258
- arrForEach(channels, queue => _addChannelQueue(channelQueue, queue, core));
259
- }
260
-
261
- if (extensions) {
262
- // Create a new channel queue for any extensions with a priority > the ChannelControllerPriority
263
- let extensionQueue: IChannelControls[] = [];
264
- arrForEach(extensions as IChannelControls[], plugin => {
265
- if (plugin.priority > ChannelControllerPriority) {
266
- extensionQueue.push(plugin);
267
- }
268
- });
269
-
270
- _addChannelQueue(channelQueue, extensionQueue, core);
271
- }
272
-
273
- return channelQueue;
274
- }
@@ -1,19 +0,0 @@
1
- import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
2
- import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
3
- import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
4
- import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
- import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
6
- export declare const ChannelControllerPriority = 500;
7
- export interface IChannelController extends IChannelControls {
8
- flush(isAsync: boolean, callBack: (flushComplete?: boolean) => void, sendReason: SendRequestReason, cbTimeout?: number): void;
9
- getChannel<T extends IPlugin = IPlugin>(pluginIdentifier: string): T;
10
- }
11
- export interface IInternalChannelController extends IChannelController {
12
- _setQueue: (channels: _IInternalChannels[]) => void;
13
- }
14
- export interface _IInternalChannels {
15
- queue: IChannelControls[];
16
- chain: ITelemetryPluginChain;
17
- }
18
- export declare function createChannelControllerPlugin(channelQueue: _IInternalChannels[], core: IAppInsightsCore): IChannelController;
19
- export declare function createChannelQueues(channels: IChannelControls[][], extensions: IPlugin[], core: IAppInsightsCore): _IInternalChannels[];