@microsoft/1ds-post-js 3.1.9 → 3.2.0
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.
- package/README.md +124 -5
- package/bundle/{ms.post-3.1.9.gbl.js → ms.post-3.2.0.gbl.js} +1706 -825
- package/bundle/ms.post-3.2.0.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.0.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.0.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.0.integrity.json +46 -0
- package/bundle/{ms.post-3.1.9.js → ms.post-3.2.0.js} +1706 -825
- package/bundle/ms.post-3.2.0.js.map +1 -0
- package/bundle/ms.post-3.2.0.min.js +7 -0
- package/bundle/ms.post-3.2.0.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1705 -824
- package/bundle/ms.post.gbl.js.map +1 -1
- package/bundle/ms.post.gbl.min.js +2 -2
- package/bundle/ms.post.gbl.min.js.map +1 -1
- package/bundle/ms.post.integrity.json +17 -17
- package/bundle/ms.post.js +1705 -824
- package/bundle/ms.post.js.map +1 -1
- package/bundle/ms.post.min.js +2 -2
- package/bundle/ms.post.min.js.map +1 -1
- package/dist/ms.post.js +395 -212
- package/dist/ms.post.js.map +1 -1
- package/dist/ms.post.min.js +2 -2
- package/dist/ms.post.min.js.map +1 -1
- package/dist-esm/src/BatchNotificationActions.js +1 -1
- package/dist-esm/src/ClockSkewManager.js +1 -1
- package/dist-esm/src/Constants.d.ts +25 -0
- package/dist-esm/src/Constants.js +31 -0
- package/dist-esm/src/Constants.js.map +1 -0
- package/dist-esm/src/DataModels.d.ts +55 -0
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.d.ts +5 -2
- package/dist-esm/src/EventBatch.js +35 -15
- package/dist-esm/src/EventBatch.js.map +1 -1
- package/dist-esm/src/HttpManager.d.ts +2 -2
- package/dist-esm/src/HttpManager.js +186 -94
- package/dist-esm/src/HttpManager.js.map +1 -1
- package/dist-esm/src/Index.js +1 -1
- package/dist-esm/src/KillSwitch.js +1 -1
- package/dist-esm/src/PostChannel.d.ts +0 -4
- package/dist-esm/src/PostChannel.js +175 -107
- package/dist-esm/src/PostChannel.js.map +1 -1
- package/dist-esm/src/RetryPolicy.d.ts +20 -25
- package/dist-esm/src/RetryPolicy.js +35 -44
- package/dist-esm/src/RetryPolicy.js.map +1 -1
- package/dist-esm/src/Serializer.js +1 -1
- package/dist-esm/src/typings/XDomainRequest.js +1 -1
- package/package.json +3 -3
- package/src/Constants.ts +28 -0
- package/src/DataModels.ts +68 -0
- package/src/EventBatch.ts +47 -14
- package/src/HttpManager.ts +216 -98
- package/src/PostChannel.ts +207 -130
- package/src/RetryPolicy.ts +33 -38
- package/bundle/ms.post-3.1.9.gbl.js.map +0 -1
- package/bundle/ms.post-3.1.9.gbl.min.js +0 -7
- package/bundle/ms.post-3.1.9.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.1.9.integrity.json +0 -46
- package/bundle/ms.post-3.1.9.js.map +0 -1
- package/bundle/ms.post-3.1.9.min.js +0 -7
- package/bundle/ms.post-3.1.9.min.js.map +0 -1
package/src/PostChannel.ts
CHANGED
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import {
|
|
7
7
|
BaseTelemetryPlugin, IChannelControls, IExtendedConfiguration, IExtendedAppInsightsCore,
|
|
8
|
-
|
|
9
|
-
IAppInsightsCore, isValueAssigned,
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
EventLatencyValue, NotificationManager, EventsDiscardedReason, IPlugin, ITelemetryItem,
|
|
9
|
+
IAppInsightsCore, isValueAssigned, setProcessTelemetryTimings, isWindowObjectAvailable,
|
|
10
|
+
IProcessTelemetryContext, SendRequestReason, arrForEach, eLoggingSeverity, _eExtendedInternalMessageId,
|
|
11
|
+
doPerf, objForEachKey, optimizeObject, isChromium, getWindow, EventSendType, isNumber, mergeEvtNamespace,
|
|
12
|
+
createUniqueNamespace, IProcessTelemetryUnloadContext, ITelemetryUnloadState,
|
|
13
|
+
addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener,
|
|
14
|
+
removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener,
|
|
15
|
+
_throwInternal,
|
|
16
|
+
_eInternalMessageId
|
|
12
17
|
} from "@microsoft/1ds-core-js";
|
|
13
18
|
import {
|
|
14
19
|
IChannelConfiguration, RT_PROFILE, NRT_PROFILE, IPostChannel,
|
|
@@ -16,22 +21,29 @@ import {
|
|
|
16
21
|
EventBatchNotificationReason,
|
|
17
22
|
} from "./DataModels";
|
|
18
23
|
import { EventBatch } from "./EventBatch";
|
|
19
|
-
import HttpManager from "./HttpManager";
|
|
20
|
-
import
|
|
24
|
+
import { HttpManager } from "./HttpManager";
|
|
25
|
+
import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
|
|
21
26
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
27
|
+
import { strMsaDeviceTicket } from "./Constants";
|
|
22
28
|
|
|
23
29
|
const FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
|
|
24
30
|
const MaxNumberEventPerBatch = 500;
|
|
25
31
|
const EventsDroppedAtOneTime = 20;
|
|
26
32
|
const MaxSendAttempts = 6;
|
|
33
|
+
const MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
|
|
27
34
|
const MaxBackoffCount = 4;
|
|
28
35
|
const globalContext = isWindowObjectAvailable ? window : this;
|
|
29
36
|
const MaxConnections = 2;
|
|
30
|
-
const
|
|
37
|
+
const MaxRequestRetriesBeforeBackoff = 1;
|
|
31
38
|
|
|
32
39
|
const strEventsDiscarded = "eventsDiscarded";
|
|
33
40
|
const strOverrideInstrumentationKey = "overrideInstrumentationKey";
|
|
34
41
|
|
|
42
|
+
const strMaxEventRetryAttempts = "maxEventRetryAttempts";
|
|
43
|
+
const strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
|
|
44
|
+
|
|
45
|
+
const strAddUnloadCb = "addUnloadCb";
|
|
46
|
+
|
|
35
47
|
interface IPostChannelBatchQueue {
|
|
36
48
|
/**
|
|
37
49
|
* This is the actual queue of event batches
|
|
@@ -85,20 +97,13 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
85
97
|
let _delayedBatchReason: SendRequestReason;
|
|
86
98
|
let _optimizeObject: boolean = true;
|
|
87
99
|
let _isPageUnloadTriggered = false;
|
|
100
|
+
let _disableXhrSync = false;
|
|
101
|
+
let _maxEventSendAttempts: number = MaxSendAttempts;
|
|
102
|
+
let _maxUnloadEventSendAttempts: number = MaxSyncUnloadSendAttempts;
|
|
103
|
+
let _evtNamespace: string | string[];
|
|
88
104
|
|
|
89
105
|
dynamicProto(PostChannel, this, (_self, _base) => {
|
|
90
|
-
|
|
91
|
-
_clearQueues();
|
|
92
|
-
_setAutoLimits();
|
|
93
|
-
|
|
94
|
-
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
|
|
95
|
-
requeue: _requeueEvents,
|
|
96
|
-
send: _sendingEvent,
|
|
97
|
-
sent: _eventsSentEvent,
|
|
98
|
-
drop: _eventsDropped,
|
|
99
|
-
rspFail: _eventsResponseFail,
|
|
100
|
-
oth: _otherEvent
|
|
101
|
-
});
|
|
106
|
+
_initDefaults();
|
|
102
107
|
|
|
103
108
|
// Special internal method to allow the DebugPlugin to hook embedded objects
|
|
104
109
|
_self["_getDbgPlgTargets"] = () => {
|
|
@@ -109,76 +114,69 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
109
114
|
doPerf(core, () => "PostChannel:initialize", () => {
|
|
110
115
|
let extendedCore = core as IExtendedAppInsightsCore;
|
|
111
116
|
_base.initialize(coreConfig, core, extensions);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
try {
|
|
118
|
+
let hasAddUnloadCb = !!core[strAddUnloadCb];
|
|
119
|
+
_evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
|
|
120
|
+
|
|
121
|
+
let ctx = _self._getTelCtx();
|
|
122
|
+
coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
|
|
123
|
+
_config = ctx.getExtCfg(_self.identifier);
|
|
124
|
+
_self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
|
|
125
|
+
_self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
|
|
126
|
+
|
|
127
|
+
// Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
|
|
128
|
+
_optimizeObject = !_config.disableOptimizeObj && isChromium();
|
|
129
|
+
|
|
130
|
+
_hookWParam(extendedCore);
|
|
131
|
+
|
|
132
|
+
if (_config.eventsLimitInMem > 0) {
|
|
133
|
+
_queueSizeLimit = _config.eventsLimitInMem;
|
|
127
134
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (_config.eventsLimitInMem > 0) {
|
|
132
|
-
_queueSizeLimit = _config.eventsLimitInMem;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (_config.immediateEventLimit > 0) {
|
|
136
|
-
_immediateQueueSizeLimit = _config.immediateEventLimit;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (_config.autoFlushEventsLimit > 0) {
|
|
140
|
-
_autoFlushEventsLimit = _config.autoFlushEventsLimit;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
_setAutoLimits();
|
|
144
|
-
|
|
145
|
-
if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
|
|
146
|
-
_xhrOverride = _config.httpXHROverride;
|
|
147
|
-
}
|
|
148
|
-
if (isValueAssigned(coreConfig.anonCookieName)) {
|
|
149
|
-
_httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
|
|
150
|
-
}
|
|
151
|
-
_httpManager.sendHook = _config.payloadPreprocessor;
|
|
152
|
-
_httpManager.sendListener = _config.payloadListener;
|
|
153
|
-
|
|
154
|
-
// Override endpointUrl if provided in Post config
|
|
155
|
-
let endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
|
|
156
|
-
_self._notificationManager = coreConfig.extensionConfig.NotificationManager;
|
|
157
|
-
_httpManager.initialize(endpointUrl, _self.core as IExtendedAppInsightsCore, _self, _xhrOverride, _config);
|
|
158
|
-
|
|
159
|
-
function _handleUnloadEvents(evt: any) {
|
|
160
|
-
let theEvt = evt || getWindow().event; // IE 8 does not pass the event
|
|
161
|
-
if (theEvt.type !== "beforeunload") {
|
|
162
|
-
// Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
|
|
163
|
-
_isPageUnloadTriggered = true;
|
|
164
|
-
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
135
|
+
|
|
136
|
+
if (_config.immediateEventLimit > 0) {
|
|
137
|
+
_immediateQueueSizeLimit = _config.immediateEventLimit;
|
|
165
138
|
}
|
|
166
|
-
|
|
167
|
-
|
|
139
|
+
|
|
140
|
+
if (_config.autoFlushEventsLimit > 0) {
|
|
141
|
+
_autoFlushEventsLimit = _config.autoFlushEventsLimit;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
_disableXhrSync = _config.disableXhrSync;
|
|
145
|
+
if (isNumber(_config[strMaxEventRetryAttempts])) {
|
|
146
|
+
_maxEventSendAttempts = _config[strMaxEventRetryAttempts];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
|
|
150
|
+
_maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
_setAutoLimits();
|
|
154
|
+
|
|
155
|
+
if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
|
|
156
|
+
_xhrOverride = _config.httpXHROverride;
|
|
157
|
+
}
|
|
158
|
+
if (isValueAssigned(coreConfig.anonCookieName)) {
|
|
159
|
+
_httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
|
|
160
|
+
}
|
|
161
|
+
_httpManager.sendHook = _config.payloadPreprocessor;
|
|
162
|
+
_httpManager.sendListener = _config.payloadListener;
|
|
163
|
+
|
|
164
|
+
// Override endpointUrl if provided in Post config
|
|
165
|
+
let endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
|
|
166
|
+
_self._notificationManager = coreConfig.extensionConfig.NotificationManager;
|
|
167
|
+
_httpManager.initialize(endpointUrl, _self.core as IExtendedAppInsightsCore, _self, _xhrOverride, _config);
|
|
168
|
+
|
|
169
|
+
let excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
|
|
170
|
+
|
|
171
|
+
// When running in Web browsers try to send all telemetry if page is unloaded
|
|
172
|
+
addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
|
|
173
|
+
addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
|
|
174
|
+
addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
|
|
175
|
+
} catch (e) {
|
|
176
|
+
// resetting the initialized state because of failure
|
|
177
|
+
_self.setInitialized(false);
|
|
178
|
+
throw e;
|
|
168
179
|
}
|
|
169
|
-
|
|
170
|
-
let excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
|
|
171
|
-
|
|
172
|
-
// When running in Web browsers try to send all telemetry if page is unloaded
|
|
173
|
-
addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
|
|
174
|
-
addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
|
|
175
|
-
addPageShowEventListener((evt) => {
|
|
176
|
-
// Handle the page becoming visible again
|
|
177
|
-
_isPageUnloadTriggered = false;
|
|
178
|
-
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
179
|
-
}, coreConfig.disablePageShowEvents);
|
|
180
|
-
|
|
181
|
-
_self.setInitialized(true);
|
|
182
180
|
}, () => ({ coreConfig, core, extensions }));
|
|
183
181
|
};
|
|
184
182
|
|
|
@@ -221,6 +219,48 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
221
219
|
_self.processNext(event, itemCtx);
|
|
222
220
|
};
|
|
223
221
|
|
|
222
|
+
_self._doTeardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => {
|
|
223
|
+
_releaseAllQueues(EventSendType.SendBeacon, SendRequestReason.Unload);
|
|
224
|
+
_isTeardownCalled = true;
|
|
225
|
+
_httpManager.teardown();
|
|
226
|
+
|
|
227
|
+
removePageUnloadEventListener(null, _evtNamespace);
|
|
228
|
+
removePageHideEventListener(null, _evtNamespace);
|
|
229
|
+
removePageShowEventListener(null, _evtNamespace);
|
|
230
|
+
|
|
231
|
+
// Just register to remove all events associated with this namespace
|
|
232
|
+
_initDefaults();
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
function _hookWParam(extendedCore: IExtendedAppInsightsCore) {
|
|
236
|
+
var existingGetWParamMethod = extendedCore.getWParam;
|
|
237
|
+
extendedCore.getWParam = () => {
|
|
238
|
+
var wparam = 0;
|
|
239
|
+
if (_config.ignoreMc1Ms0CookieProcessing) {
|
|
240
|
+
wparam = wparam | 2;
|
|
241
|
+
}
|
|
242
|
+
return wparam | existingGetWParamMethod();
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Moving event handlers out from the initialize closure so that any local variables can be garbage collected
|
|
247
|
+
function _handleUnloadEvents(evt: any) {
|
|
248
|
+
let theEvt = evt || getWindow().event; // IE 8 does not pass the event
|
|
249
|
+
if (theEvt.type !== "beforeunload") {
|
|
250
|
+
// Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
|
|
251
|
+
_isPageUnloadTriggered = true;
|
|
252
|
+
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
_releaseAllQueues(EventSendType.SendBeacon, SendRequestReason.Unload);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function _handleShowEvents(evt: any) {
|
|
259
|
+
// Handle the page becoming visible again
|
|
260
|
+
_isPageUnloadTriggered = false;
|
|
261
|
+
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
262
|
+
}
|
|
263
|
+
|
|
224
264
|
function _addEventToQueues(event: IPostTransmissionTelemetryItem, append: boolean) {
|
|
225
265
|
// If send attempt field is undefined we should set it to 0.
|
|
226
266
|
if (!event.sendAttempt) {
|
|
@@ -228,7 +268,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
228
268
|
}
|
|
229
269
|
// Add default latency
|
|
230
270
|
if (!event.latency) {
|
|
231
|
-
event.latency =
|
|
271
|
+
event.latency = EventLatencyValue.Normal;
|
|
232
272
|
}
|
|
233
273
|
|
|
234
274
|
// Remove extra AI properties if present
|
|
@@ -254,7 +294,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
254
294
|
// If the transmission is backed off then do not send synchronous events.
|
|
255
295
|
// We will convert these events to Real time latency instead.
|
|
256
296
|
if (_currentBackoffCount || _paused) {
|
|
257
|
-
event.latency =
|
|
297
|
+
event.latency = EventLatencyValue.RealTime;
|
|
258
298
|
event.sync = false;
|
|
259
299
|
} else {
|
|
260
300
|
// Log the event synchronously
|
|
@@ -276,7 +316,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
276
316
|
let evtLatency = event.latency;
|
|
277
317
|
let queueSize = _queueSize;
|
|
278
318
|
let queueLimit = _queueSizeLimit;
|
|
279
|
-
if (evtLatency ===
|
|
319
|
+
if (evtLatency === EventLatencyValue.Immediate) {
|
|
280
320
|
queueSize = _immediateQueueSize;
|
|
281
321
|
queueLimit = _immediateQueueSizeLimit;
|
|
282
322
|
}
|
|
@@ -286,11 +326,11 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
286
326
|
if (queueSize < queueLimit) {
|
|
287
327
|
eventDropped = !_addEventToProperQueue(event, append);
|
|
288
328
|
} else {
|
|
289
|
-
let dropLatency =
|
|
329
|
+
let dropLatency = EventLatencyValue.Normal;
|
|
290
330
|
let dropNumber = EventsDroppedAtOneTime;
|
|
291
|
-
if (evtLatency ===
|
|
331
|
+
if (evtLatency === EventLatencyValue.Immediate) {
|
|
292
332
|
// Only drop other immediate events as they are not technically sharing the general queue
|
|
293
|
-
dropLatency =
|
|
333
|
+
dropLatency = EventLatencyValue.Immediate;
|
|
294
334
|
dropNumber = 1;
|
|
295
335
|
}
|
|
296
336
|
|
|
@@ -317,7 +357,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
317
357
|
|
|
318
358
|
if (!doFlush && _autoFlushBatchLimit > 0) {
|
|
319
359
|
// Check the auto flush max batch size
|
|
320
|
-
for (let latency =
|
|
360
|
+
for (let latency = EventLatencyValue.Normal; !doFlush && latency <= EventLatencyValue.RealTime; latency++) {
|
|
321
361
|
let batchQueue: IPostChannelBatchQueue = _batchQueues[latency];
|
|
322
362
|
if (batchQueue && batchQueue.batches) {
|
|
323
363
|
arrForEach(batchQueue.batches, (theBatch) => {
|
|
@@ -333,12 +373,6 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
333
373
|
_performAutoFlush(true, doFlush);
|
|
334
374
|
};
|
|
335
375
|
|
|
336
|
-
_self.teardown = () => {
|
|
337
|
-
_releaseAllQueues(EventSendType.SendBeacon, SendRequestReason.Unload);
|
|
338
|
-
_isTeardownCalled = true;
|
|
339
|
-
_httpManager.teardown();
|
|
340
|
-
};
|
|
341
|
-
|
|
342
376
|
_self.pause = () => {
|
|
343
377
|
_clearScheduledTimer();
|
|
344
378
|
_paused = true;
|
|
@@ -394,7 +428,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
394
428
|
|
|
395
429
|
if (async) {
|
|
396
430
|
// Move all queued events to the HttpManager
|
|
397
|
-
_queueBatches(
|
|
431
|
+
_queueBatches(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
398
432
|
|
|
399
433
|
// All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
|
|
400
434
|
_resetQueueCounts();
|
|
@@ -410,7 +444,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
410
444
|
}
|
|
411
445
|
} else {
|
|
412
446
|
// Now cause all queued events to be sent synchronously
|
|
413
|
-
_sendEventsForLatencyAndAbove(
|
|
447
|
+
_sendEventsForLatencyAndAbove(EventLatencyValue.Normal, EventSendType.Synchronous, sendReason);
|
|
414
448
|
|
|
415
449
|
if (callback !== null && callback !== undefined) {
|
|
416
450
|
callback();
|
|
@@ -420,7 +454,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
420
454
|
};
|
|
421
455
|
|
|
422
456
|
_self.setMsaAuthTicket = (ticket: string) => {
|
|
423
|
-
_httpManager.addHeader(
|
|
457
|
+
_httpManager.addHeader(strMsaDeviceTicket, ticket);
|
|
424
458
|
};
|
|
425
459
|
|
|
426
460
|
_self.hasEvents = _hasEvents;
|
|
@@ -470,7 +504,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
470
504
|
_immediateTimerId = _createTimer(() => {
|
|
471
505
|
_immediateTimerId = null;
|
|
472
506
|
// Only try to send direct events
|
|
473
|
-
_sendEventsForLatencyAndAbove(
|
|
507
|
+
_sendEventsForLatencyAndAbove(EventLatencyValue.Immediate, EventSendType.Batched, SendRequestReason.NormalSchedule);
|
|
474
508
|
_scheduleTimer();
|
|
475
509
|
}, immediateTimeOut);
|
|
476
510
|
}
|
|
@@ -482,7 +516,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
482
516
|
if (_hasEvents()) {
|
|
483
517
|
_scheduledTimerId = _createTimer(() => {
|
|
484
518
|
_scheduledTimerId = null;
|
|
485
|
-
_sendEventsForLatencyAndAbove(_timerCount === 0 ?
|
|
519
|
+
_sendEventsForLatencyAndAbove(_timerCount === 0 ? EventLatencyValue.RealTime : EventLatencyValue.Normal, EventSendType.Batched, SendRequestReason.NormalSchedule);
|
|
486
520
|
|
|
487
521
|
// Increment the count for next cycle
|
|
488
522
|
_timerCount++;
|
|
@@ -512,6 +546,50 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
512
546
|
}
|
|
513
547
|
};
|
|
514
548
|
|
|
549
|
+
function _initDefaults() {
|
|
550
|
+
_config = null;
|
|
551
|
+
_isTeardownCalled = false;
|
|
552
|
+
_flushCallbackQueue = [];
|
|
553
|
+
_flushCallbackTimerId = null;
|
|
554
|
+
_paused = false;
|
|
555
|
+
_immediateQueueSize = 0;
|
|
556
|
+
_immediateQueueSizeLimit = 500;
|
|
557
|
+
_queueSize = 0;
|
|
558
|
+
_queueSizeLimit = 10000;
|
|
559
|
+
_profiles = {};
|
|
560
|
+
_currentProfile = RT_PROFILE;
|
|
561
|
+
_scheduledTimerId = null;
|
|
562
|
+
_immediateTimerId = null;
|
|
563
|
+
_currentBackoffCount = 0;
|
|
564
|
+
_timerCount = 0;
|
|
565
|
+
_xhrOverride = null;
|
|
566
|
+
_batchQueues = {};
|
|
567
|
+
_autoFlushEventsLimit = undefined;
|
|
568
|
+
|
|
569
|
+
// either MaxBatchSize * (1+ Max Connections) or _queueLimit / 6 (where 3 latency Queues [normal, realtime, cost deferred] * 2 [allow half full -- allow for retry])
|
|
570
|
+
_autoFlushBatchLimit = 0;
|
|
571
|
+
_delayedBatchSendLatency = -1;
|
|
572
|
+
_delayedBatchReason = null;
|
|
573
|
+
_optimizeObject = true;
|
|
574
|
+
_isPageUnloadTriggered = false;
|
|
575
|
+
_disableXhrSync = false;
|
|
576
|
+
_maxEventSendAttempts = MaxSendAttempts;
|
|
577
|
+
_maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
578
|
+
_evtNamespace = null;
|
|
579
|
+
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
|
|
580
|
+
requeue: _requeueEvents,
|
|
581
|
+
send: _sendingEvent,
|
|
582
|
+
sent: _eventsSentEvent,
|
|
583
|
+
drop: _eventsDropped,
|
|
584
|
+
rspFail: _eventsResponseFail,
|
|
585
|
+
oth: _otherEvent
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
_initializeProfiles();
|
|
589
|
+
_clearQueues();
|
|
590
|
+
_setAutoLimits();
|
|
591
|
+
}
|
|
592
|
+
|
|
515
593
|
function _createTimer(theTimerFunc: () => void, timeOut: number): any {
|
|
516
594
|
// If the transmission is backed off make the timer at least 1 sec to allow for back off.
|
|
517
595
|
if (timeOut === 0 && _currentBackoffCount) {
|
|
@@ -520,7 +598,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
520
598
|
|
|
521
599
|
let timerMultiplier = 1000;
|
|
522
600
|
if (_currentBackoffCount) {
|
|
523
|
-
timerMultiplier =
|
|
601
|
+
timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
|
|
524
602
|
}
|
|
525
603
|
|
|
526
604
|
return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
|
|
@@ -545,7 +623,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
545
623
|
|
|
546
624
|
if (!_paused) {
|
|
547
625
|
// Queue all the remaining requests to be sent. The requests will be sent using HTML5 Beacons if they are available.
|
|
548
|
-
_sendEventsForLatencyAndAbove(
|
|
626
|
+
_sendEventsForLatencyAndAbove(EventLatencyValue.Normal, sendType, sendReason);
|
|
549
627
|
}
|
|
550
628
|
}
|
|
551
629
|
|
|
@@ -555,19 +633,19 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
555
633
|
* after flush are stored separately till we flush the current events.
|
|
556
634
|
*/
|
|
557
635
|
function _clearQueues() {
|
|
558
|
-
_batchQueues[
|
|
636
|
+
_batchQueues[EventLatencyValue.Immediate] = {
|
|
559
637
|
batches: [],
|
|
560
638
|
iKeyMap: {}
|
|
561
639
|
};
|
|
562
|
-
_batchQueues[
|
|
640
|
+
_batchQueues[EventLatencyValue.RealTime] = {
|
|
563
641
|
batches: [],
|
|
564
642
|
iKeyMap: {}
|
|
565
643
|
};
|
|
566
|
-
_batchQueues[
|
|
644
|
+
_batchQueues[EventLatencyValue.CostDeferred] = {
|
|
567
645
|
batches: [],
|
|
568
646
|
iKeyMap: {}
|
|
569
647
|
};
|
|
570
|
-
_batchQueues[
|
|
648
|
+
_batchQueues[EventLatencyValue.Normal] = {
|
|
571
649
|
batches: [],
|
|
572
650
|
iKeyMap: {}
|
|
573
651
|
};
|
|
@@ -576,7 +654,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
576
654
|
function _getEventBatch(iKey: string, latency: number, create: boolean) {
|
|
577
655
|
let batchQueue: IPostChannelBatchQueue = _batchQueues[latency];
|
|
578
656
|
if (!batchQueue) {
|
|
579
|
-
latency =
|
|
657
|
+
latency = EventLatencyValue.Normal;
|
|
580
658
|
batchQueue = _batchQueues[latency];
|
|
581
659
|
}
|
|
582
660
|
|
|
@@ -613,8 +691,8 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
613
691
|
|
|
614
692
|
const latency = event.latency;
|
|
615
693
|
let eventBatch = _getEventBatch(event.iKey, latency, true);
|
|
616
|
-
if (eventBatch.
|
|
617
|
-
if (latency !==
|
|
694
|
+
if (eventBatch.addEvent(event)) {
|
|
695
|
+
if (latency !== EventLatencyValue.Immediate) {
|
|
618
696
|
_queueSize++;
|
|
619
697
|
|
|
620
698
|
// Check for auto flushing based on total events in the queue, but not for requeued or retry events
|
|
@@ -641,7 +719,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
641
719
|
let droppedEvents = eventBatch.split(0, dropNumber);
|
|
642
720
|
let droppedCount = droppedEvents.count();
|
|
643
721
|
if (droppedCount > 0) {
|
|
644
|
-
if (currentLatency ===
|
|
722
|
+
if (currentLatency === EventLatencyValue.Immediate) {
|
|
645
723
|
_immediateQueueSize -= droppedCount;
|
|
646
724
|
} else {
|
|
647
725
|
_queueSize -= droppedCount;
|
|
@@ -668,11 +746,11 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
668
746
|
function _resetQueueCounts() {
|
|
669
747
|
let immediateQueue = 0;
|
|
670
748
|
let normalQueue = 0;
|
|
671
|
-
for (let latency =
|
|
749
|
+
for (let latency = EventLatencyValue.Normal; latency <= EventLatencyValue.Immediate; latency++) {
|
|
672
750
|
let batchQueue: IPostChannelBatchQueue = _batchQueues[latency];
|
|
673
751
|
if (batchQueue && batchQueue.batches) {
|
|
674
752
|
arrForEach(batchQueue.batches, (theBatch) => {
|
|
675
|
-
if (latency ===
|
|
753
|
+
if (latency === EventLatencyValue.Immediate) {
|
|
676
754
|
immediateQueue += theBatch.count();
|
|
677
755
|
} else {
|
|
678
756
|
normalQueue += theBatch.count();
|
|
@@ -695,7 +773,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
695
773
|
if (!isAsync || _httpManager.canSendRequest()) {
|
|
696
774
|
doPerf(_self.core, () => "PostChannel._queueBatches", () => {
|
|
697
775
|
let droppedEvents = [];
|
|
698
|
-
let latencyToProcess =
|
|
776
|
+
let latencyToProcess = EventLatencyValue.Immediate;
|
|
699
777
|
while (latencyToProcess >= latency) {
|
|
700
778
|
let batchQueue: IPostChannelBatchQueue = _batchQueues[latencyToProcess];
|
|
701
779
|
if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
|
|
@@ -708,7 +786,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
708
786
|
eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
|
|
709
787
|
}
|
|
710
788
|
|
|
711
|
-
if (latencyToProcess ===
|
|
789
|
+
if (latencyToProcess === EventLatencyValue.Immediate) {
|
|
712
790
|
_immediateQueueSize -= theBatch.count();
|
|
713
791
|
} else {
|
|
714
792
|
_queueSize -= theBatch.count();
|
|
@@ -749,7 +827,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
749
827
|
*/
|
|
750
828
|
function _flushImpl(callback: () => void, sendReason: SendRequestReason) {
|
|
751
829
|
// Add any additional queued events and cause all queued events to be sent asynchronously
|
|
752
|
-
_sendEventsForLatencyAndAbove(
|
|
830
|
+
_sendEventsForLatencyAndAbove(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
753
831
|
|
|
754
832
|
_waitForIdleManager(() => {
|
|
755
833
|
// Only called AFTER the httpManager does not have any outstanding requests
|
|
@@ -804,6 +882,11 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
804
882
|
*/
|
|
805
883
|
function _requeueEvents(batches: EventBatch[], reason?: number) {
|
|
806
884
|
let droppedEvents: IPostTransmissionTelemetryItem[] = [];
|
|
885
|
+
let maxSendAttempts = _maxEventSendAttempts;
|
|
886
|
+
if (_isPageUnloadTriggered) {
|
|
887
|
+
// If a page unlaod has been triggered reduce the number of times we try to "retry"
|
|
888
|
+
maxSendAttempts = _maxUnloadEventSendAttempts;
|
|
889
|
+
}
|
|
807
890
|
|
|
808
891
|
arrForEach(batches, (theBatch) => {
|
|
809
892
|
if (theBatch && theBatch.count() > 0) {
|
|
@@ -812,11 +895,11 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
812
895
|
if (theEvent) {
|
|
813
896
|
// Check if the request being added back is for a sync event in which case mark it no longer a sync event
|
|
814
897
|
if (theEvent.sync) {
|
|
815
|
-
theEvent.latency =
|
|
898
|
+
theEvent.latency = EventLatencyValue.Immediate;
|
|
816
899
|
theEvent.sync = false;
|
|
817
900
|
}
|
|
818
901
|
|
|
819
|
-
if (theEvent.sendAttempt <
|
|
902
|
+
if (theEvent.sendAttempt < maxSendAttempts) {
|
|
820
903
|
// Reset the event timings
|
|
821
904
|
setProcessTelemetryTimings(theEvent, _self.identifier);
|
|
822
905
|
_addEventToQueues(theEvent, false);
|
|
@@ -845,8 +928,9 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
845
928
|
try {
|
|
846
929
|
notifyFunc.apply(manager, theArgs);
|
|
847
930
|
} catch (e) {
|
|
848
|
-
_self.diagLog()
|
|
849
|
-
|
|
931
|
+
_throwInternal(_self.diagLog(),
|
|
932
|
+
eLoggingSeverity.CRITICAL,
|
|
933
|
+
_eInternalMessageId.NotificationException,
|
|
850
934
|
evtName + " notification failed: " + e);
|
|
851
935
|
}
|
|
852
936
|
}
|
|
@@ -958,13 +1042,6 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
958
1042
|
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
|
|
959
1043
|
}
|
|
960
1044
|
|
|
961
|
-
/**
|
|
962
|
-
* Batch all current events in the queues and send them.
|
|
963
|
-
*/
|
|
964
|
-
public teardown() {
|
|
965
|
-
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
|
|
966
|
-
}
|
|
967
|
-
|
|
968
1045
|
/**
|
|
969
1046
|
* Pause the transmission of any requests
|
|
970
1047
|
*/
|