@microsoft/applicationinsights-channel-js 3.0.0-beta.2301-08 → 3.0.0-beta.2301-10
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/browser/applicationinsights-channel-js.integrity.json +9 -9
- package/browser/applicationinsights-channel-js.js +89 -37
- package/browser/applicationinsights-channel-js.js.map +1 -1
- package/browser/applicationinsights-channel-js.min.js +2 -2
- package/browser/applicationinsights-channel-js.min.js.map +1 -1
- package/dist/applicationinsights-channel-js.api.json +1 -1
- package/dist/applicationinsights-channel-js.d.ts +39 -1
- package/dist/applicationinsights-channel-js.js +89 -37
- package/dist/applicationinsights-channel-js.js.map +1 -1
- package/dist/applicationinsights-channel-js.min.js +2 -2
- package/dist/applicationinsights-channel-js.min.js.map +1 -1
- package/dist/applicationinsights-channel-js.rollup.d.ts +39 -1
- package/dist-esm/EnvelopeCreator.js +2 -2
- package/dist-esm/EnvelopeCreator.js.map +1 -1
- package/dist-esm/Interfaces.js +1 -1
- package/dist-esm/InternalConstants.js +1 -1
- package/dist-esm/Offline.js +1 -1
- package/dist-esm/SendBuffer.js +40 -8
- package/dist-esm/SendBuffer.js.map +1 -1
- package/dist-esm/Sender.js +56 -30
- package/dist-esm/Sender.js.map +1 -1
- package/dist-esm/Serializer.js +1 -1
- package/dist-esm/TelemetryProcessors/Sample.js +1 -1
- package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
- package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
- package/dist-esm/__DynamicConstants.js +11 -10
- package/dist-esm/__DynamicConstants.js.map +1 -1
- package/dist-esm/applicationinsights-channel-js.js +1 -1
- package/package.json +3 -3
- package/src/SendBuffer.ts +53 -4
- package/src/Sender.ts +67 -36
- package/src/__DynamicConstants.ts +10 -9
- package/types/SendBuffer.d.ts +9 -0
- package/types/__DynamicConstants.d.ts +4 -3
- package/types/tsdoc-metadata.json +1 -1
package/src/Sender.ts
CHANGED
|
@@ -148,6 +148,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
148
148
|
let _convertUndefined: any;
|
|
149
149
|
let _isRetryDisabled: boolean;
|
|
150
150
|
let _maxBatchInterval: number;
|
|
151
|
+
let _sessionStorageUsed: boolean;
|
|
152
|
+
let _namePrefix: string;
|
|
151
153
|
|
|
152
154
|
dynamicProto(Sender, this, (_self, _base) => {
|
|
153
155
|
|
|
@@ -164,10 +166,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
164
166
|
_retryAt = null;
|
|
165
167
|
|
|
166
168
|
// flush if we have exceeded the max-size already
|
|
167
|
-
|
|
168
|
-
_self.triggerSend(true, null, SendRequestReason.MaxBatchSize);
|
|
169
|
-
}
|
|
170
|
-
|
|
169
|
+
_checkMaxSize();
|
|
171
170
|
_setupTimer();
|
|
172
171
|
}
|
|
173
172
|
};
|
|
@@ -227,7 +226,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
227
226
|
_offlineListener = createOfflineListener(_evtNamespace);
|
|
228
227
|
|
|
229
228
|
// This function will be re-called whenever any referenced configuration is changed
|
|
230
|
-
_self._addHook(onConfigChange(config, () => {
|
|
229
|
+
_self._addHook(onConfigChange(config, (details) => {
|
|
230
|
+
let config = details.cfg;
|
|
231
231
|
let ctx = createProcessTelemetryContext(null, config, core);
|
|
232
232
|
let senderConfig = ctx.getExtCfg(identifier, defaultAppInsightsChannelConfig);
|
|
233
233
|
|
|
@@ -239,18 +239,62 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
239
239
|
}
|
|
240
240
|
});
|
|
241
241
|
|
|
242
|
+
// Only update the endpoint if the original config !== the current config
|
|
243
|
+
// This is so any redirect endpointUrl is not overwritten
|
|
244
|
+
if (_orgEndpointUrl !== senderConfig.endpointUrl) {
|
|
245
|
+
if (_orgEndpointUrl) {
|
|
246
|
+
// TODO: add doc to remind users to flush before changing endpoint, otherwise all unsent payload will be sent to new endpoint
|
|
247
|
+
}
|
|
248
|
+
_endpointUrl = _orgEndpointUrl = senderConfig.endpointUrl;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (_customHeaders && _customHeaders !== senderConfig.customHeaders) {
|
|
252
|
+
// Removing any previously defined custom headers as they have changed
|
|
253
|
+
arrForEach(_customHeaders, customHeader => {
|
|
254
|
+
delete _headers[customHeader.header];
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
242
258
|
_maxBatchSizeInBytes = senderConfig.maxBatchSizeInBytes;
|
|
243
259
|
_beaconSupported = (senderConfig.onunloadDisableBeacon === false || senderConfig.isBeaconApiDisabled === false) && isBeaconsSupported();
|
|
260
|
+
|
|
261
|
+
let canUseSessionStorage = !!senderConfig.enableSessionStorageBuffer && utlCanUseSessionStorage();
|
|
262
|
+
let namePrefix = senderConfig.namePrefix;
|
|
263
|
+
|
|
264
|
+
//Note: emitLineDelimitedJson and eventsLimitInMem is directly accessed via config in senderBuffer
|
|
265
|
+
//Therefore, if canUseSessionStorage is not changed, we do not need to re initialize a new one
|
|
266
|
+
let shouldUpdate = (canUseSessionStorage !== _sessionStorageUsed)
|
|
267
|
+
|| (canUseSessionStorage && (_namePrefix !== namePrefix)); // prefixName is only used in session storage
|
|
244
268
|
|
|
245
269
|
if (_self._buffer) {
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
//
|
|
270
|
+
// case1 (Pre and Now enableSessionStorageBuffer settings are same)
|
|
271
|
+
// if namePrefix changes, transfer current buffer to new buffer
|
|
272
|
+
// else no action needed
|
|
273
|
+
|
|
274
|
+
//case2 (Pre and Now enableSessionStorageBuffer settings are changed)
|
|
275
|
+
// transfer current buffer to new buffer
|
|
276
|
+
|
|
277
|
+
if (shouldUpdate) {
|
|
278
|
+
try {
|
|
279
|
+
|
|
280
|
+
_self._buffer = _self._buffer.createNew(diagLog, senderConfig, canUseSessionStorage);
|
|
281
|
+
|
|
282
|
+
} catch (e) {
|
|
283
|
+
_throwInternal(_self.diagLog(), eLoggingSeverity.CRITICAL,
|
|
284
|
+
_eInternalMessageId.FailedAddingTelemetryToBuffer,
|
|
285
|
+
"failed to transfer telemetry to different buffer storage, telemetry will be lost: " + getExceptionName(e),
|
|
286
|
+
{ exception: dumpObj(e) });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
_checkMaxSize();
|
|
249
290
|
} else {
|
|
250
|
-
_self._buffer =
|
|
291
|
+
_self._buffer = canUseSessionStorage
|
|
251
292
|
? new SessionStorageSendBuffer(diagLog, senderConfig) : new ArraySendBuffer(diagLog, senderConfig);
|
|
252
293
|
}
|
|
253
294
|
|
|
295
|
+
_namePrefix = namePrefix;
|
|
296
|
+
_sessionStorageUsed = canUseSessionStorage;
|
|
297
|
+
|
|
254
298
|
_self._sample = new Sample(senderConfig.samplingPercentage, diagLog);
|
|
255
299
|
|
|
256
300
|
_instrumentationKey = senderConfig.instrumentationKey;
|
|
@@ -260,26 +304,6 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
260
304
|
_eInternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + _instrumentationKey);
|
|
261
305
|
}
|
|
262
306
|
|
|
263
|
-
// Only update the endpoint if the original config !== the current config
|
|
264
|
-
// This is so any redirect endpointUrl is not overwritten
|
|
265
|
-
if (_orgEndpointUrl !== senderConfig.endpointUrl) {
|
|
266
|
-
if (_orgEndpointUrl) {
|
|
267
|
-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
268
|
-
// TODO 3.x.x !!! - Handle the endpointUrl changing
|
|
269
|
-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
_endpointUrl = _orgEndpointUrl = senderConfig.endpointUrl;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (_customHeaders && _customHeaders !== senderConfig.customHeaders) {
|
|
276
|
-
// Removing any previously defined custom headers as they have changed
|
|
277
|
-
arrForEach(_customHeaders, customHeader => {
|
|
278
|
-
delete _headers[customHeader.header];
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
307
|
_customHeaders = senderConfig.customHeaders;
|
|
284
308
|
if (!isInternalApplicationInsightsEndpoint(_endpointUrl) && _customHeaders && _customHeaders.length > 0) {
|
|
285
309
|
arrForEach(_customHeaders, customHeader => {
|
|
@@ -413,12 +437,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
413
437
|
|
|
414
438
|
// flush if we would exceed the max-size limit by adding this item
|
|
415
439
|
const buffer = _self._buffer;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
if ((bufferSize + payload.length) > _maxBatchSizeInBytes) {
|
|
419
|
-
_self.triggerSend(true, null, SendRequestReason.MaxBatchSize);
|
|
420
|
-
}
|
|
421
|
-
|
|
440
|
+
_checkMaxSize(payload);
|
|
441
|
+
|
|
422
442
|
// enqueue the payload
|
|
423
443
|
buffer.enqueue(payload);
|
|
424
444
|
|
|
@@ -581,6 +601,15 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
581
601
|
return _self._sample.isSampledIn(envelope);
|
|
582
602
|
}
|
|
583
603
|
|
|
604
|
+
function _checkMaxSize(incomingPayload?: string): boolean {
|
|
605
|
+
let incomingSize = incomingPayload? incomingPayload.length : 0;
|
|
606
|
+
if ((_self._buffer.size() + incomingSize) > _maxBatchSizeInBytes) {
|
|
607
|
+
_self.triggerSend(true, null, SendRequestReason.MaxBatchSize);
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
|
|
584
613
|
function _checkResponsStatus(status: number, payload: string[], responseUrl: string, countOfItemsInPayload: number, errorMessage: string, res: any) {
|
|
585
614
|
let response: IBackendResponse = null;
|
|
586
615
|
|
|
@@ -601,7 +630,6 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
601
630
|
return;
|
|
602
631
|
}
|
|
603
632
|
}
|
|
604
|
-
|
|
605
633
|
if (!_isRetryDisabled && _isRetriable(status)) {
|
|
606
634
|
_resendPayload(payload);
|
|
607
635
|
_throwInternal(_self.diagLog(),
|
|
@@ -1014,6 +1042,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
1014
1042
|
const buffer = _self._buffer;
|
|
1015
1043
|
let _window = getWindow();
|
|
1016
1044
|
const xdr = new XDomainRequest();
|
|
1045
|
+
// NOTE: xdr may send previous retry payload to new endpoint since we are not able to check response URL
|
|
1017
1046
|
xdr.onload = () => _self._xdrOnLoad(xdr, payload);
|
|
1018
1047
|
xdr.onerror = (event: ErrorEvent|any) => _self._onError(payload, _formatErrorMessageXdr(xdr), event);
|
|
1019
1048
|
|
|
@@ -1116,6 +1145,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
|
|
|
1116
1145
|
_instrumentationKey = null;
|
|
1117
1146
|
_convertUndefined = UNDEFINED_VALUE;
|
|
1118
1147
|
_isRetryDisabled = false;
|
|
1148
|
+
_sessionStorageUsed = null;
|
|
1149
|
+
_namePrefix = UNDEFINED_VALUE;
|
|
1119
1150
|
|
|
1120
1151
|
objDefineProp(_self, "_senderConfig", {
|
|
1121
1152
|
enumerable: true,
|
|
@@ -22,30 +22,31 @@ export const _DYN_DATA_TYPE = "dataType"; // Count: 10
|
|
|
22
22
|
export const _DYN_ENVELOPE_TYPE = "envelopeType"; // Count: 7
|
|
23
23
|
export const _DYN_TO_STRING = "toString"; // Count: 7
|
|
24
24
|
export const _DYN_ON_LINE = "onLine"; // Count: 4
|
|
25
|
-
export const
|
|
25
|
+
export const _DYN__GET = "_get"; // Count: 5
|
|
26
|
+
export const _DYN_ENQUEUE = "enqueue"; // Count: 7
|
|
26
27
|
export const _DYN_COUNT = "count"; // Count: 6
|
|
27
28
|
export const _DYN_EVENTS_LIMIT_IN_MEM = "eventsLimitInMem"; // Count: 2
|
|
28
29
|
export const _DYN_PUSH = "push"; // Count: 6
|
|
29
30
|
export const _DYN_EMIT_LINE_DELIMITED_0 = "emitLineDelimitedJson"; // Count: 3
|
|
30
|
-
export const _DYN_CLEAR = "clear"; // Count:
|
|
31
|
+
export const _DYN_CLEAR = "clear"; // Count: 7
|
|
31
32
|
export const _DYN_BATCH_PAYLOADS = "batchPayloads"; // Count: 5
|
|
32
|
-
export const
|
|
33
|
+
export const _DYN_CREATE_NEW = "createNew"; // Count: 3
|
|
34
|
+
export const _DYN_MARK_AS_SENT = "markAsSent"; // Count: 7
|
|
33
35
|
export const _DYN_CLEAR_SENT = "clearSent"; // Count: 5
|
|
34
36
|
export const _DYN__BUFFER__KEY = "BUFFER_KEY"; // Count: 5
|
|
35
|
-
export const _DYN__SENT__BUFFER__KEY = "SENT_BUFFER_KEY"; // Count:
|
|
37
|
+
export const _DYN__SENT__BUFFER__KEY = "SENT_BUFFER_KEY"; // Count: 8
|
|
36
38
|
export const _DYN__MAX__BUFFER__SIZE = "MAX_BUFFER_SIZE"; // Count: 5
|
|
37
|
-
export const
|
|
38
|
-
export const
|
|
39
|
-
export const _DYN_DIAG_LOG = "diagLog"; // Count: 15
|
|
39
|
+
export const _DYN_TRIGGER_SEND = "triggerSend"; // Count: 5
|
|
40
|
+
export const _DYN_DIAG_LOG = "diagLog"; // Count: 16
|
|
40
41
|
export const _DYN__SENDER = "_sender"; // Count: 5
|
|
42
|
+
export const _DYN_CUSTOM_HEADERS = "customHeaders"; // Count: 3
|
|
41
43
|
export const _DYN_MAX_BATCH_SIZE_IN_BY1 = "maxBatchSizeInBytes"; // Count: 2
|
|
42
44
|
export const _DYN_ONUNLOAD_DISABLE_BEA2 = "onunloadDisableBeacon"; // Count: 2
|
|
43
45
|
export const _DYN_IS_BEACON_API_DISABL3 = "isBeaconApiDisabled"; // Count: 2
|
|
44
|
-
export const _DYN__BUFFER = "_buffer"; // Count: 8
|
|
45
46
|
export const _DYN_ENABLE_SESSION_STORA4 = "enableSessionStorageBuffer"; // Count: 2
|
|
47
|
+
export const _DYN__BUFFER = "_buffer"; // Count: 9
|
|
46
48
|
export const _DYN_SAMPLING_PERCENTAGE = "samplingPercentage"; // Count: 2
|
|
47
49
|
export const _DYN_INSTRUMENTATION_KEY = "instrumentationKey"; // Count: 2
|
|
48
|
-
export const _DYN_CUSTOM_HEADERS = "customHeaders"; // Count: 3
|
|
49
50
|
export const _DYN_DISABLE_XHR = "disableXhr"; // Count: 5
|
|
50
51
|
export const _DYN_ONUNLOAD_DISABLE_FET5 = "onunloadDisableFetch"; // Count: 2
|
|
51
52
|
export const _DYN_CONVERT_UNDEFINED = "convertUndefined"; // Count: 2
|
package/types/SendBuffer.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export interface ISendBuffer {
|
|
|
34
34
|
* Removes items from the SENT_BUFFER. Should be called on successful response from the backend.
|
|
35
35
|
*/
|
|
36
36
|
clearSent: (payload: string[]) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Copy current buffer items to a new buffer.
|
|
39
|
+
* if canUseSessionStorage is undefined, it will set to false.
|
|
40
|
+
* if newLogger and newConfig are undefined, current logger and empty config will be used.
|
|
41
|
+
* if canUseSessionStorage is set to true, new SessionStorageSendBuffer will be returned otherwise ArraySendBuffer will be returned.
|
|
42
|
+
*/
|
|
43
|
+
createNew: (newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean) => ArraySendBuffer | SessionStorageSendBuffer;
|
|
37
44
|
}
|
|
38
45
|
declare abstract class BaseSendBuffer {
|
|
39
46
|
protected _get: () => string[];
|
|
@@ -45,6 +52,7 @@ declare abstract class BaseSendBuffer {
|
|
|
45
52
|
clear(): void;
|
|
46
53
|
getItems(): string[];
|
|
47
54
|
batchPayloads(payload: string[]): string;
|
|
55
|
+
createNew(newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean): ArraySendBuffer | SessionStorageSendBuffer;
|
|
48
56
|
}
|
|
49
57
|
export declare class ArraySendBuffer extends BaseSendBuffer implements ISendBuffer {
|
|
50
58
|
constructor(logger: IDiagnosticLogger, config: ISenderConfig);
|
|
@@ -60,5 +68,6 @@ export declare class SessionStorageSendBuffer extends BaseSendBuffer implements
|
|
|
60
68
|
clear(): void;
|
|
61
69
|
markAsSent(payload: string[]): void;
|
|
62
70
|
clearSent(payload: string[]): void;
|
|
71
|
+
createNew(newLogger?: IDiagnosticLogger, newConfig?: ISenderConfig, canUseSessionStorage?: boolean): ArraySendBuffer | SessionStorageSendBuffer;
|
|
63
72
|
}
|
|
64
73
|
export {};
|
|
@@ -10,6 +10,7 @@ export declare const _DYN_DATA_TYPE = "dataType";
|
|
|
10
10
|
export declare const _DYN_ENVELOPE_TYPE = "envelopeType";
|
|
11
11
|
export declare const _DYN_TO_STRING = "toString";
|
|
12
12
|
export declare const _DYN_ON_LINE = "onLine";
|
|
13
|
+
export declare const _DYN__GET = "_get";
|
|
13
14
|
export declare const _DYN_ENQUEUE = "enqueue";
|
|
14
15
|
export declare const _DYN_COUNT = "count";
|
|
15
16
|
export declare const _DYN_EVENTS_LIMIT_IN_MEM = "eventsLimitInMem";
|
|
@@ -17,23 +18,23 @@ export declare const _DYN_PUSH = "push";
|
|
|
17
18
|
export declare const _DYN_EMIT_LINE_DELIMITED_0 = "emitLineDelimitedJson";
|
|
18
19
|
export declare const _DYN_CLEAR = "clear";
|
|
19
20
|
export declare const _DYN_BATCH_PAYLOADS = "batchPayloads";
|
|
21
|
+
export declare const _DYN_CREATE_NEW = "createNew";
|
|
20
22
|
export declare const _DYN_MARK_AS_SENT = "markAsSent";
|
|
21
23
|
export declare const _DYN_CLEAR_SENT = "clearSent";
|
|
22
24
|
export declare const _DYN__BUFFER__KEY = "BUFFER_KEY";
|
|
23
25
|
export declare const _DYN__SENT__BUFFER__KEY = "SENT_BUFFER_KEY";
|
|
24
26
|
export declare const _DYN__MAX__BUFFER__SIZE = "MAX_BUFFER_SIZE";
|
|
25
|
-
export declare const _DYN_NAME_PREFIX = "namePrefix";
|
|
26
27
|
export declare const _DYN_TRIGGER_SEND = "triggerSend";
|
|
27
28
|
export declare const _DYN_DIAG_LOG = "diagLog";
|
|
28
29
|
export declare const _DYN__SENDER = "_sender";
|
|
30
|
+
export declare const _DYN_CUSTOM_HEADERS = "customHeaders";
|
|
29
31
|
export declare const _DYN_MAX_BATCH_SIZE_IN_BY1 = "maxBatchSizeInBytes";
|
|
30
32
|
export declare const _DYN_ONUNLOAD_DISABLE_BEA2 = "onunloadDisableBeacon";
|
|
31
33
|
export declare const _DYN_IS_BEACON_API_DISABL3 = "isBeaconApiDisabled";
|
|
32
|
-
export declare const _DYN__BUFFER = "_buffer";
|
|
33
34
|
export declare const _DYN_ENABLE_SESSION_STORA4 = "enableSessionStorageBuffer";
|
|
35
|
+
export declare const _DYN__BUFFER = "_buffer";
|
|
34
36
|
export declare const _DYN_SAMPLING_PERCENTAGE = "samplingPercentage";
|
|
35
37
|
export declare const _DYN_INSTRUMENTATION_KEY = "instrumentationKey";
|
|
36
|
-
export declare const _DYN_CUSTOM_HEADERS = "customHeaders";
|
|
37
38
|
export declare const _DYN_DISABLE_XHR = "disableXhr";
|
|
38
39
|
export declare const _DYN_ONUNLOAD_DISABLE_FET5 = "onunloadDisableFetch";
|
|
39
40
|
export declare const _DYN_CONVERT_UNDEFINED = "convertUndefined";
|