@microsoft/applicationinsights-channel-js 3.0.0-beta.2209-03 → 3.0.0-beta.2210-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.
- package/browser/applicationinsights-channel-js.integrity.json +9 -9
- package/browser/applicationinsights-channel-js.js +946 -428
- 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 +2 -2
- package/dist/applicationinsights-channel-js.d.ts +22 -22
- package/dist/applicationinsights-channel-js.js +946 -428
- 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 +22 -22
- 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 +9 -11
- package/dist-esm/SendBuffer.js.map +1 -1
- package/dist-esm/Sender.js +186 -135
- package/dist-esm/Sender.js.map +1 -1
- package/dist-esm/Serializer.js +2 -3
- package/dist-esm/Serializer.js.map +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 -15
- package/dist-esm/__DynamicConstants.js.map +1 -1
- package/dist-esm/applicationinsights-channel-js.js +1 -1
- package/package.json +4 -4
- package/src/Interfaces.ts +17 -17
- package/src/SendBuffer.ts +5 -5
- package/src/Sender.ts +194 -129
- package/src/__DynamicConstants.ts +10 -14
- package/types/Interfaces.d.ts +17 -17
- package/types/Sender.d.ts +4 -4
- package/types/__DynamicConstants.d.ts +5 -9
- package/types/tsdoc-metadata.json +1 -1
package/dist-esm/Sender.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Channel, 3.0.0-beta.
|
|
2
|
+
* Application Insights JavaScript SDK - Channel, 3.0.0-beta.2210-02
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
|
-
var _a;
|
|
5
|
+
var _a, _b;
|
|
6
6
|
import { __assignFn as __assign, __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
|
|
7
7
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
8
8
|
import { BreezeChannelIdentifier, DEFAULT_BREEZE_ENDPOINT, DEFAULT_BREEZE_PATH, DisabledPropertyName, Event, Exception, Metric, PageView, PageViewPerformance, ProcessLegacy, RemoteDependencyData, RequestHeaders, SampleRate, Trace, isInternalApplicationInsightsEndpoint, utlCanUseSessionStorage } from "@microsoft/applicationinsights-common";
|
|
9
|
-
import { BaseTelemetryPlugin, _throwInternal, _warnToConsole, arrForEach, createUniqueNamespace, dateNow, dumpObj, getExceptionName, getIEVersion, getJSON, getNavigator, getWindow, isArray, isBeaconsSupported, isFetchSupported, isNullOrUndefined, isXhrSupported, mergeEvtNamespace,
|
|
9
|
+
import { BaseTelemetryPlugin, _throwInternal, _warnToConsole, arrForEach, createProcessTelemetryContext, createUniqueNamespace, dateNow, dumpObj, getExceptionName, getIEVersion, getJSON, getNavigator, getWindow, isArray, isBeaconsSupported, isFetchSupported, isNullOrUndefined, isXhrSupported, mergeEvtNamespace, objExtend, objKeys, onConfigChange, useXDomainRequest } from "@microsoft/applicationinsights-core-js";
|
|
10
|
+
import { isTruthy, objDeepFreeze, objDefineProp } from "@nevware21/ts-utils";
|
|
10
11
|
import { DependencyEnvelopeCreator, EventEnvelopeCreator, ExceptionEnvelopeCreator, MetricEnvelopeCreator, PageViewEnvelopeCreator, PageViewPerformanceEnvelopeCreator, TraceEnvelopeCreator } from "./EnvelopeCreator";
|
|
11
12
|
import { createOfflineListener } from "./Offline";
|
|
12
13
|
import { ArraySendBuffer, SessionStorageSendBuffer } from "./SendBuffer";
|
|
13
14
|
import { Serializer } from "./Serializer";
|
|
14
15
|
import { Sample } from "./TelemetryProcessors/Sample";
|
|
15
|
-
import { _DYN_BASE_TYPE, _DYN_BATCH_PAYLOADS, _DYN_CLEAR, _DYN_CLEAR_SENT, _DYN_CONVERT_UNDEFINED, _DYN_COUNT, _DYN_CUSTOM_HEADERS, _DYN_DIAG_LOG,
|
|
16
|
+
import { _DYN_BASE_TYPE, _DYN_BATCH_PAYLOADS, _DYN_CLEAR, _DYN_CLEAR_SENT, _DYN_CONVERT_UNDEFINED, _DYN_COUNT, _DYN_CUSTOM_HEADERS, _DYN_DIAG_LOG, _DYN_DISABLE_XHR, _DYN_EMIT_LINE_DELIMITED_0, _DYN_ENABLE_SESSION_STORA4, _DYN_ENQUEUE, _DYN_EVENTS_LIMIT_IN_MEM, _DYN_EVENTS_SEND_REQUEST, _DYN_INSTRUMENTATION_KEY, _DYN_IS_BEACON_API_DISABL3, _DYN_ITEMS_ACCEPTED, _DYN_ITEMS_RECEIVED, _DYN_LENGTH, _DYN_MARK_AS_SENT, _DYN_MAX_BATCH_INTERVAL, _DYN_MAX_BATCH_SIZE_IN_BY1, _DYN_NAME_PREFIX, _DYN_ONUNLOAD_DISABLE_BEA2, _DYN_ONUNLOAD_DISABLE_FET5, _DYN_PUSH, _DYN_SAMPLE_RATE, _DYN_SAMPLING_PERCENTAGE, _DYN_SET_REQUEST_HEADER, _DYN_TAGS, _DYN_TRIGGER_SEND, _DYN__BUFFER, _DYN__ON_ERROR, _DYN__ON_PARTIAL_SUCCESS, _DYN__ON_SUCCESS, _DYN__SENDER, _DYN__XHR_READY_STATE_CHA6 } from "./__DynamicConstants";
|
|
17
|
+
var UNDEFINED_VALUE = undefined;
|
|
16
18
|
var FetchSyncRequestSizeLimitBytes = 65000; // approx 64kb (the current Edge, Firefox and Chrome max limit)
|
|
17
19
|
function _getResponseText(xhr) {
|
|
18
20
|
try {
|
|
@@ -23,51 +25,42 @@ function _getResponseText(xhr) {
|
|
|
23
25
|
}
|
|
24
26
|
return null;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_a[PageViewPerformance.dataType] = PageViewPerformanceEnvelopeCreator,
|
|
57
|
-
_a[Exception.dataType] = ExceptionEnvelopeCreator,
|
|
58
|
-
_a[Metric.dataType] = MetricEnvelopeCreator,
|
|
59
|
-
_a[RemoteDependencyData.dataType] = DependencyEnvelopeCreator,
|
|
60
|
-
_a);
|
|
28
|
+
var defaultAppInsightsChannelConfig = objDeepFreeze((_a = {
|
|
29
|
+
// Use the default value (handles empty string in the configuration)
|
|
30
|
+
endpointUrl: { isVal: isTruthy, v: DEFAULT_BREEZE_ENDPOINT + DEFAULT_BREEZE_PATH }
|
|
31
|
+
},
|
|
32
|
+
_a[_DYN_EMIT_LINE_DELIMITED_0 /* @min:emitLineDelimitedJson */] = false,
|
|
33
|
+
_a[_DYN_MAX_BATCH_INTERVAL /* @min:maxBatchInterval */] = 15000,
|
|
34
|
+
_a[_DYN_MAX_BATCH_SIZE_IN_BY1 /* @min:maxBatchSizeInBytes */] = 102400,
|
|
35
|
+
_a.disableTelemetry = false,
|
|
36
|
+
_a[_DYN_ENABLE_SESSION_STORA4 /* @min:enableSessionStorageBuffer */] = true,
|
|
37
|
+
_a.isRetryDisabled = false,
|
|
38
|
+
_a.isBeaconApiDisabled = true,
|
|
39
|
+
_a[_DYN_DISABLE_XHR /* @min:disableXhr */] = false,
|
|
40
|
+
_a[_DYN_ONUNLOAD_DISABLE_FET5 /* @min:onunloadDisableFetch */] = false,
|
|
41
|
+
_a[_DYN_ONUNLOAD_DISABLE_BEA2 /* @min:onunloadDisableBeacon */] = false,
|
|
42
|
+
_a[_DYN_INSTRUMENTATION_KEY /* @min:instrumentationKey */] = UNDEFINED_VALUE,
|
|
43
|
+
_a[_DYN_NAME_PREFIX /* @min:namePrefix */] = UNDEFINED_VALUE,
|
|
44
|
+
_a[_DYN_SAMPLING_PERCENTAGE /* @min:samplingPercentage */] = 100,
|
|
45
|
+
_a[_DYN_CUSTOM_HEADERS /* @min:customHeaders */] = UNDEFINED_VALUE,
|
|
46
|
+
_a[_DYN_CONVERT_UNDEFINED /* @min:convertUndefined */] = UNDEFINED_VALUE,
|
|
47
|
+
_a[_DYN_EVENTS_LIMIT_IN_MEM /* @min:eventsLimitInMem */] = 10000,
|
|
48
|
+
_a));
|
|
49
|
+
var EnvelopeTypeCreator = (_b = {},
|
|
50
|
+
_b[Event.dataType] = EventEnvelopeCreator,
|
|
51
|
+
_b[Trace.dataType] = TraceEnvelopeCreator,
|
|
52
|
+
_b[PageView.dataType] = PageViewEnvelopeCreator,
|
|
53
|
+
_b[PageViewPerformance.dataType] = PageViewPerformanceEnvelopeCreator,
|
|
54
|
+
_b[Exception.dataType] = ExceptionEnvelopeCreator,
|
|
55
|
+
_b[Metric.dataType] = MetricEnvelopeCreator,
|
|
56
|
+
_b[RemoteDependencyData.dataType] = DependencyEnvelopeCreator,
|
|
57
|
+
_b);
|
|
61
58
|
var Sender = /** @class */ (function (_super) {
|
|
62
59
|
__extends(Sender, _super);
|
|
63
60
|
function Sender() {
|
|
64
61
|
var _this = _super.call(this) || this;
|
|
65
62
|
_this.priority = 1001;
|
|
66
63
|
_this.identifier = BreezeChannelIdentifier;
|
|
67
|
-
/**
|
|
68
|
-
* The configuration for this sender instance
|
|
69
|
-
*/
|
|
70
|
-
_this._senderConfig = _getDefaultAppInsightsChannelConfig();
|
|
71
64
|
// Don't set the defaults here, set them in the _initDefaults() as this is also called during unload
|
|
72
65
|
var _consecutiveErrors; // How many times in a row a retryable error condition has occurred.
|
|
73
66
|
var _retryAt; // The time to retry at in milliseconds from 1970/01/01 (this makes the timer calculation easy).
|
|
@@ -82,6 +75,16 @@ var Sender = /** @class */ (function (_super) {
|
|
|
82
75
|
var _syncUnloadSender; // The identified sender to use for the synchronous unload stage
|
|
83
76
|
var _offlineListener;
|
|
84
77
|
var _evtNamespace;
|
|
78
|
+
var _endpointUrl;
|
|
79
|
+
var _orgEndpointUrl;
|
|
80
|
+
var _maxBatchSizeInBytes;
|
|
81
|
+
var _beaconSupported;
|
|
82
|
+
var _customHeaders;
|
|
83
|
+
var _disableTelemetry;
|
|
84
|
+
var _instrumentationKey;
|
|
85
|
+
var _convertUndefined;
|
|
86
|
+
var _isRetryDisabled;
|
|
87
|
+
var _maxBatchInterval;
|
|
85
88
|
dynamicProto(Sender, _this, function (_self, _base) {
|
|
86
89
|
_initDefaults();
|
|
87
90
|
_self.pause = function () {
|
|
@@ -93,7 +96,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
93
96
|
_paused = false;
|
|
94
97
|
_retryAt = null;
|
|
95
98
|
// flush if we have exceeded the max-size already
|
|
96
|
-
if (_self
|
|
99
|
+
if (_self[_DYN__BUFFER /* @min:%2e_buffer */].size() > _maxBatchSizeInBytes) {
|
|
97
100
|
_self[_DYN_TRIGGER_SEND /* @min:%2etriggerSend */](true, null, 10 /* SendRequestReason.MaxBatchSize */);
|
|
98
101
|
}
|
|
99
102
|
_setupTimer();
|
|
@@ -114,7 +117,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
114
117
|
};
|
|
115
118
|
_self.onunloadFlush = function () {
|
|
116
119
|
if (!_paused) {
|
|
117
|
-
if (
|
|
120
|
+
if (_beaconSupported) {
|
|
118
121
|
try {
|
|
119
122
|
_self[_DYN_TRIGGER_SEND /* @min:%2etriggerSend */](true, _doUnloadSend, 2 /* SendRequestReason.Unload */);
|
|
120
123
|
}
|
|
@@ -135,7 +138,6 @@ var Sender = /** @class */ (function (_super) {
|
|
|
135
138
|
_throwInternal(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), 1 /* eLoggingSeverity.CRITICAL */, 28 /* _eInternalMessageId.SenderNotInitialized */, "Sender is already initialized");
|
|
136
139
|
}
|
|
137
140
|
_base.initialize(config, core, extensions, pluginChain);
|
|
138
|
-
var ctx = _self._getTelCtx();
|
|
139
141
|
var identifier = _self.identifier;
|
|
140
142
|
_serializer = new Serializer(core.logger);
|
|
141
143
|
_consecutiveErrors = 0;
|
|
@@ -146,71 +148,104 @@ var Sender = /** @class */ (function (_super) {
|
|
|
146
148
|
var diagLog = _self[_DYN_DIAG_LOG /* @min:%2ediagLog */]();
|
|
147
149
|
_evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
|
|
148
150
|
_offlineListener = createOfflineListener(_evtNamespace);
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
// This function will be re-called whenever any referenced configuration is changed
|
|
152
|
+
_self._addHook(onConfigChange(config, function () {
|
|
153
|
+
var ctx = createProcessTelemetryContext(null, config, core);
|
|
154
|
+
var senderConfig = ctx.getExtCfg(identifier, defaultAppInsightsChannelConfig);
|
|
155
|
+
objDefineProp(_self, "_senderConfig", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
get: function () {
|
|
159
|
+
return senderConfig;
|
|
157
160
|
}
|
|
158
|
-
return theValue;
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
_self._buffer = (_self[_DYN__SENDER_CONFIG /* @min:%2e_senderConfig */][_DYN_ENABLE_SESSION_STORA4 /* @min:%2eenableSessionStorageBuffer */]() && utlCanUseSessionStorage())
|
|
162
|
-
? new SessionStorageSendBuffer(diagLog, _self[_DYN__SENDER_CONFIG /* @min:%2e_senderConfig */]) : new ArraySendBuffer(diagLog, _self[_DYN__SENDER_CONFIG /* @min:%2e_senderConfig */]);
|
|
163
|
-
_self._sample = new Sample(_self[_DYN__SENDER_CONFIG /* @min:%2e_senderConfig */][_DYN_SAMPLING_PERCENTAGE /* @min:%2esamplingPercentage */](), diagLog);
|
|
164
|
-
if (!_validateInstrumentationKey(config)) {
|
|
165
|
-
_throwInternal(diagLog, 1 /* eLoggingSeverity.CRITICAL */, 100 /* _eInternalMessageId.InvalidInstrumentationKey */, "Invalid Instrumentation key " + config[_DYN_INSTRUMENTATION_KEY /* @min:%2einstrumentationKey */]);
|
|
166
|
-
}
|
|
167
|
-
if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders()[_DYN_LENGTH /* @min:%2elength */] > 0) {
|
|
168
|
-
arrForEach(_self[_DYN__SENDER_CONFIG /* @min:%2e_senderConfig */][_DYN_CUSTOM_HEADERS /* @min:%2ecustomHeaders */](), function (customHeader) {
|
|
169
|
-
_this.addHeader(customHeader.header, customHeader.value);
|
|
170
161
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
162
|
+
_maxBatchSizeInBytes = senderConfig[_DYN_MAX_BATCH_SIZE_IN_BY1 /* @min:%2emaxBatchSizeInBytes */];
|
|
163
|
+
_beaconSupported = (senderConfig[_DYN_ONUNLOAD_DISABLE_BEA2 /* @min:%2eonunloadDisableBeacon */] === false || senderConfig[_DYN_IS_BEACON_API_DISABL3 /* @min:%2eisBeaconApiDisabled */] === false) && isBeaconsSupported();
|
|
164
|
+
if (_self[_DYN__BUFFER /* @min:%2e_buffer */]) {
|
|
165
|
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
166
|
+
// TODO 3.x.x !!! - Handle the enableSessionStorageBuffer changing
|
|
167
|
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
_self[_DYN__BUFFER /* @min:%2e_buffer */] = (senderConfig[_DYN_ENABLE_SESSION_STORA4 /* @min:%2eenableSessionStorageBuffer */] && utlCanUseSessionStorage())
|
|
171
|
+
? new SessionStorageSendBuffer(diagLog, senderConfig) : new ArraySendBuffer(diagLog, senderConfig);
|
|
172
|
+
}
|
|
173
|
+
_self._sample = new Sample(senderConfig[_DYN_SAMPLING_PERCENTAGE /* @min:%2esamplingPercentage */], diagLog);
|
|
174
|
+
_instrumentationKey = senderConfig[_DYN_INSTRUMENTATION_KEY /* @min:%2einstrumentationKey */];
|
|
175
|
+
if (!_validateInstrumentationKey(_instrumentationKey, config)) {
|
|
176
|
+
_throwInternal(diagLog, 1 /* eLoggingSeverity.CRITICAL */, 100 /* _eInternalMessageId.InvalidInstrumentationKey */, "Invalid Instrumentation key " + _instrumentationKey);
|
|
177
|
+
}
|
|
178
|
+
// Only update the endpoint if the original config !== the current config
|
|
179
|
+
// This is so any redirect endpointUrl is not overwritten
|
|
180
|
+
if (_orgEndpointUrl !== senderConfig.endpointUrl) {
|
|
181
|
+
if (_orgEndpointUrl) {
|
|
182
|
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
183
|
+
// TODO 3.x.x !!! - Handle the endpointUrl changing
|
|
184
|
+
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
185
|
+
}
|
|
186
|
+
_endpointUrl = _orgEndpointUrl = senderConfig.endpointUrl;
|
|
187
|
+
}
|
|
188
|
+
if (_customHeaders && _customHeaders !== senderConfig[_DYN_CUSTOM_HEADERS /* @min:%2ecustomHeaders */]) {
|
|
189
|
+
// Removing any previously defined custom headers as they have changed
|
|
190
|
+
arrForEach(_customHeaders, function (customHeader) {
|
|
191
|
+
delete _headers[customHeader.header];
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
_customHeaders = senderConfig[_DYN_CUSTOM_HEADERS /* @min:%2ecustomHeaders */];
|
|
195
|
+
if (!isInternalApplicationInsightsEndpoint(_endpointUrl) && _customHeaders && _customHeaders[_DYN_LENGTH /* @min:%2elength */] > 0) {
|
|
196
|
+
arrForEach(_customHeaders, function (customHeader) {
|
|
197
|
+
_this.addHeader(customHeader.header, customHeader.value);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
_customHeaders = null;
|
|
202
|
+
}
|
|
203
|
+
var sendPostFunc = null;
|
|
204
|
+
if (!senderConfig[_DYN_DISABLE_XHR /* @min:%2edisableXhr */] && useXDomainRequest()) {
|
|
205
|
+
sendPostFunc = _xdrSender; // IE 8 and 9
|
|
206
|
+
}
|
|
207
|
+
else if (!senderConfig[_DYN_DISABLE_XHR /* @min:%2edisableXhr */] && isXhrSupported()) {
|
|
208
|
+
sendPostFunc = _xhrSender;
|
|
209
|
+
}
|
|
210
|
+
if (!sendPostFunc && isFetchSupported()) {
|
|
211
|
+
sendPostFunc = _fetchSender;
|
|
212
|
+
}
|
|
213
|
+
// always fallback to XHR
|
|
214
|
+
_fallbackSender = sendPostFunc || _xhrSender;
|
|
215
|
+
if (!senderConfig[_DYN_IS_BEACON_API_DISABL3 /* @min:%2eisBeaconApiDisabled */] && isBeaconsSupported()) {
|
|
216
|
+
// Config is set to always used beacon sending
|
|
217
|
+
sendPostFunc = _beaconSender;
|
|
218
|
+
}
|
|
219
|
+
_self[_DYN__SENDER /* @min:%2e_sender */] = sendPostFunc || _xhrSender;
|
|
220
|
+
if (!senderConfig[_DYN_ONUNLOAD_DISABLE_FET5 /* @min:%2eonunloadDisableFetch */] && isFetchSupported(true)) {
|
|
221
|
+
// Try and use the fetch with keepalive
|
|
222
|
+
_syncUnloadSender = _fetchKeepAliveSender;
|
|
223
|
+
}
|
|
224
|
+
else if (isBeaconsSupported()) {
|
|
225
|
+
// Try and use sendBeacon
|
|
226
|
+
_syncUnloadSender = _beaconSender;
|
|
227
|
+
}
|
|
228
|
+
else if (!senderConfig[_DYN_DISABLE_XHR /* @min:%2edisableXhr */] && useXDomainRequest()) {
|
|
229
|
+
_syncUnloadSender = _xdrSender; // IE 8 and 9
|
|
230
|
+
}
|
|
231
|
+
else if (!senderConfig[_DYN_DISABLE_XHR /* @min:%2edisableXhr */] && isXhrSupported()) {
|
|
232
|
+
_syncUnloadSender = _xhrSender;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
_syncUnloadSender = _fallbackSender;
|
|
236
|
+
}
|
|
237
|
+
_disableTelemetry = senderConfig.disableTelemetry;
|
|
238
|
+
_convertUndefined = senderConfig[_DYN_CONVERT_UNDEFINED /* @min:%2econvertUndefined */] || UNDEFINED_VALUE;
|
|
239
|
+
_isRetryDisabled = senderConfig.isRetryDisabled;
|
|
240
|
+
_maxBatchInterval = senderConfig[_DYN_MAX_BATCH_INTERVAL /* @min:%2emaxBatchInterval */];
|
|
241
|
+
}));
|
|
207
242
|
};
|
|
208
243
|
_self.processTelemetry = function (telemetryItem, itemCtx) {
|
|
209
244
|
itemCtx = _self._getTelCtx(itemCtx);
|
|
210
245
|
var diagLogger = itemCtx[_DYN_DIAG_LOG /* @min:%2ediagLog */]();
|
|
211
246
|
try {
|
|
212
247
|
// if master off switch is set, don't send any data
|
|
213
|
-
if (
|
|
248
|
+
if (_disableTelemetry) {
|
|
214
249
|
// Do not send/save data
|
|
215
250
|
return;
|
|
216
251
|
}
|
|
@@ -242,11 +277,10 @@ var Sender = /** @class */ (function (_super) {
|
|
|
242
277
|
else {
|
|
243
278
|
telemetryItem[SampleRate] = _self._sample[_DYN_SAMPLE_RATE /* @min:%2esampleRate */];
|
|
244
279
|
}
|
|
245
|
-
var convertUndefined = _self[_DYN__SENDER_CONFIG /* @min:%2e_senderConfig */][_DYN_CONVERT_UNDEFINED /* @min:%2econvertUndefined */]() || undefined;
|
|
246
280
|
// construct an envelope that Application Insights endpoint can understand
|
|
247
281
|
// if ikey of telemetry is provided and not empty, envelope will use this iKey instead of senderConfig iKey
|
|
248
|
-
var defaultEnvelopeIkey = telemetryItem.iKey ||
|
|
249
|
-
var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, diagLogger,
|
|
282
|
+
var defaultEnvelopeIkey = telemetryItem.iKey || _instrumentationKey;
|
|
283
|
+
var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, diagLogger, _convertUndefined);
|
|
250
284
|
if (!aiEnvelope_1) {
|
|
251
285
|
_throwInternal(diagLogger, 1 /* eLoggingSeverity.CRITICAL */, 47 /* _eInternalMessageId.CreateEnvelopeError */, "Unable to create an AppInsights envelope");
|
|
252
286
|
return;
|
|
@@ -277,7 +311,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
277
311
|
// flush if we would exceed the max-size limit by adding this item
|
|
278
312
|
var buffer = _self[_DYN__BUFFER /* @min:%2e_buffer */];
|
|
279
313
|
var bufferSize = buffer.size();
|
|
280
|
-
if ((bufferSize + payload[_DYN_LENGTH /* @min:%2elength */]) >
|
|
314
|
+
if ((bufferSize + payload[_DYN_LENGTH /* @min:%2elength */]) > _maxBatchSizeInBytes) {
|
|
281
315
|
_self[_DYN_TRIGGER_SEND /* @min:%2etriggerSend */](true, null, 10 /* SendRequestReason.MaxBatchSize */);
|
|
282
316
|
}
|
|
283
317
|
// enqueue the payload
|
|
@@ -301,8 +335,8 @@ var Sender = /** @class */ (function (_super) {
|
|
|
301
335
|
};
|
|
302
336
|
/**
|
|
303
337
|
* Immediately send buffered data
|
|
304
|
-
* @param async {boolean} - Indicates if the events should be sent asynchronously
|
|
305
|
-
* @param forcedSender {SenderFunction} - Indicates the forcedSender, undefined if not passed
|
|
338
|
+
* @param async - {boolean} - Indicates if the events should be sent asynchronously
|
|
339
|
+
* @param forcedSender - {SenderFunction} - Indicates the forcedSender, undefined if not passed
|
|
306
340
|
*/
|
|
307
341
|
_self[_DYN_TRIGGER_SEND /* @min:%2etriggerSend */] = function (async, forcedSender, sendReason) {
|
|
308
342
|
if (async === void 0) { async = true; }
|
|
@@ -310,7 +344,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
310
344
|
try {
|
|
311
345
|
var buffer = _self[_DYN__BUFFER /* @min:%2e_buffer */];
|
|
312
346
|
// Send data only if disableTelemetry is false
|
|
313
|
-
if (!
|
|
347
|
+
if (!_disableTelemetry) {
|
|
314
348
|
if (buffer[_DYN_COUNT /* @min:%2ecount */]() > 0) {
|
|
315
349
|
var payload = buffer.getItems();
|
|
316
350
|
_notifySendRequest(sendReason || 0 /* SendRequestReason.Undefined */, async);
|
|
@@ -401,7 +435,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
401
435
|
else {
|
|
402
436
|
var results = _parseResponse(responseText);
|
|
403
437
|
if (results && results.itemsReceived && results.itemsReceived > results[_DYN_ITEMS_ACCEPTED /* @min:%2eitemsAccepted */]
|
|
404
|
-
&& !
|
|
438
|
+
&& !_isRetryDisabled) {
|
|
405
439
|
_self[_DYN__ON_PARTIAL_SUCCESS /* @min:%2e_onPartialSuccess */](payload, results);
|
|
406
440
|
}
|
|
407
441
|
else {
|
|
@@ -429,7 +463,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
429
463
|
return;
|
|
430
464
|
}
|
|
431
465
|
}
|
|
432
|
-
if (!
|
|
466
|
+
if (!_isRetryDisabled && _isRetriable(status)) {
|
|
433
467
|
_resendPayload(payload);
|
|
434
468
|
_throwInternal(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), 2 /* eLoggingSeverity.WARNING */, 40 /* _eInternalMessageId.TransmissionFailed */, ". " +
|
|
435
469
|
"Response code " + status + ". Will retry to send " + payload[_DYN_LENGTH /* @min:%2elength */] + " items.");
|
|
@@ -440,7 +474,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
440
474
|
}
|
|
441
475
|
else if (_offlineListener && !_offlineListener.isOnline()) { // offline
|
|
442
476
|
// Note: Don't check for status == 0, since adblock gives this code
|
|
443
|
-
if (!
|
|
477
|
+
if (!_isRetryDisabled) {
|
|
444
478
|
var offlineBackOffMultiplier = 10; // arbritrary number
|
|
445
479
|
_resendPayload(payload, offlineBackOffMultiplier);
|
|
446
480
|
_throwInternal(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), 2 /* eLoggingSeverity.WARNING */, 40 /* _eInternalMessageId.TransmissionFailed */, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(!_offlineListener.isOnline(), ". Will retry to send ").concat(payload.length, " items."));
|
|
@@ -454,7 +488,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
454
488
|
if (!response) {
|
|
455
489
|
response = _parseResponse(res);
|
|
456
490
|
}
|
|
457
|
-
if (response && !
|
|
491
|
+
if (response && !_isRetryDisabled) {
|
|
458
492
|
_self[_DYN__ON_PARTIAL_SUCCESS /* @min:%2e_onPartialSuccess */](payload, response);
|
|
459
493
|
}
|
|
460
494
|
else {
|
|
@@ -475,8 +509,8 @@ var Sender = /** @class */ (function (_super) {
|
|
|
475
509
|
return false;
|
|
476
510
|
}
|
|
477
511
|
if (!isNullOrUndefined(responseUrl) && responseUrl !== "") {
|
|
478
|
-
if (responseUrl !==
|
|
479
|
-
|
|
512
|
+
if (responseUrl !== _endpointUrl) {
|
|
513
|
+
_endpointUrl = responseUrl;
|
|
480
514
|
++_stamp_specific_redirects;
|
|
481
515
|
return true;
|
|
482
516
|
}
|
|
@@ -496,7 +530,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
496
530
|
function _doBeaconSend(payload) {
|
|
497
531
|
var nav = getNavigator();
|
|
498
532
|
var buffer = _self[_DYN__BUFFER /* @min:%2e_buffer */];
|
|
499
|
-
var url =
|
|
533
|
+
var url = _endpointUrl;
|
|
500
534
|
var batch = _self._buffer[_DYN_BATCH_PAYLOADS /* @min:%2ebatchPayloads */](payload);
|
|
501
535
|
// Chrome only allows CORS-safelisted values for the sendBeacon data argument
|
|
502
536
|
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=720283
|
|
@@ -512,8 +546,8 @@ var Sender = /** @class */ (function (_super) {
|
|
|
512
546
|
}
|
|
513
547
|
/**
|
|
514
548
|
* Send Beacon API request
|
|
515
|
-
* @param payload {string} - The data payload to be sent.
|
|
516
|
-
* @param isAsync {boolean} - not used
|
|
549
|
+
* @param payload - {string} - The data payload to be sent.
|
|
550
|
+
* @param isAsync - {boolean} - not used
|
|
517
551
|
* Note: Beacon API does not support custom headers and we are not able to get
|
|
518
552
|
* appId from the backend for the correct correlation.
|
|
519
553
|
*/
|
|
@@ -539,12 +573,12 @@ var Sender = /** @class */ (function (_super) {
|
|
|
539
573
|
}
|
|
540
574
|
/**
|
|
541
575
|
* Send XMLHttpRequest
|
|
542
|
-
* @param payload {string} - The data payload to be sent.
|
|
543
|
-
* @param isAsync {boolean} - Indicates if the request should be sent asynchronously
|
|
576
|
+
* @param payload - {string} - The data payload to be sent.
|
|
577
|
+
* @param isAsync - {boolean} - Indicates if the request should be sent asynchronously
|
|
544
578
|
*/
|
|
545
579
|
function _xhrSender(payload, isAsync) {
|
|
546
580
|
var xhr = new XMLHttpRequest();
|
|
547
|
-
var endPointUrl =
|
|
581
|
+
var endPointUrl = _endpointUrl;
|
|
548
582
|
try {
|
|
549
583
|
xhr[DisabledPropertyName] = true;
|
|
550
584
|
}
|
|
@@ -590,20 +624,20 @@ var Sender = /** @class */ (function (_super) {
|
|
|
590
624
|
}
|
|
591
625
|
/**
|
|
592
626
|
* Send fetch API request
|
|
593
|
-
* @param payload {string} - The data payload to be sent.
|
|
594
|
-
* @param isAsync {boolean} - not used
|
|
627
|
+
* @param payload - {string} - The data payload to be sent.
|
|
628
|
+
* @param isAsync - {boolean} - not used
|
|
595
629
|
*/
|
|
596
630
|
function _fetchSender(payload, isAsync) {
|
|
597
631
|
_doFetchSender(payload, true);
|
|
598
632
|
}
|
|
599
633
|
/**
|
|
600
634
|
* Send fetch API request
|
|
601
|
-
* @param payload {string} - The data payload to be sent.
|
|
602
|
-
* @param isAsync {boolean} - For fetch this identifies whether we are "unloading" (false) or a normal request
|
|
635
|
+
* @param payload - {string} - The data payload to be sent.
|
|
636
|
+
* @param isAsync - {boolean} - For fetch this identifies whether we are "unloading" (false) or a normal request
|
|
603
637
|
*/
|
|
604
638
|
function _doFetchSender(payload, isAsync) {
|
|
605
639
|
var _a;
|
|
606
|
-
var endPointUrl =
|
|
640
|
+
var endPointUrl = _endpointUrl;
|
|
607
641
|
var batch = _self._buffer[_DYN_BATCH_PAYLOADS /* @min:%2ebatchPayloads */](payload);
|
|
608
642
|
var plainTextBatch = new Blob([batch], { type: "application/json" });
|
|
609
643
|
var requestHeaders = new Headers();
|
|
@@ -755,7 +789,7 @@ var Sender = /** @class */ (function (_super) {
|
|
|
755
789
|
function _setupTimer() {
|
|
756
790
|
if (!_timeoutHandle && !_paused) {
|
|
757
791
|
var retryInterval = _retryAt ? Math.max(0, _retryAt - dateNow()) : 0;
|
|
758
|
-
var timerValue = Math.max(
|
|
792
|
+
var timerValue = Math.max(_maxBatchInterval, retryInterval);
|
|
759
793
|
_timeoutHandle = setTimeout(function () {
|
|
760
794
|
_timeoutHandle = null;
|
|
761
795
|
_self[_DYN_TRIGGER_SEND /* @min:%2etriggerSend */](true, null, 1 /* SendRequestReason.NormalSchedule */);
|
|
@@ -789,8 +823,8 @@ var Sender = /** @class */ (function (_super) {
|
|
|
789
823
|
}
|
|
790
824
|
/**
|
|
791
825
|
* Send XDomainRequest
|
|
792
|
-
* @param payload {string} - The data payload to be sent.
|
|
793
|
-
* @param isAsync {boolean} - Indicates if the request should be sent asynchronously
|
|
826
|
+
* @param payload - {string} - The data payload to be sent.
|
|
827
|
+
* @param isAsync - {boolean} - Indicates if the request should be sent asynchronously
|
|
794
828
|
*
|
|
795
829
|
* Note: XDomainRequest does not support sync requests. This 'isAsync' parameter is added
|
|
796
830
|
* to maintain consistency with the xhrSender's contract
|
|
@@ -806,13 +840,13 @@ var Sender = /** @class */ (function (_super) {
|
|
|
806
840
|
// XDomainRequest requires the same protocol as the hosting page.
|
|
807
841
|
// If the protocol doesn't match, we can't send the telemetry :(.
|
|
808
842
|
var hostingProtocol = _window && _window.location && _window.location.protocol || "";
|
|
809
|
-
if (
|
|
843
|
+
if (_endpointUrl.lastIndexOf(hostingProtocol, 0) !== 0) {
|
|
810
844
|
_throwInternal(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), 2 /* eLoggingSeverity.WARNING */, 40 /* _eInternalMessageId.TransmissionFailed */, ". " +
|
|
811
845
|
"Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
|
|
812
846
|
buffer[_DYN_CLEAR /* @min:%2eclear */]();
|
|
813
847
|
return;
|
|
814
848
|
}
|
|
815
|
-
var endpointUrl =
|
|
849
|
+
var endpointUrl = _endpointUrl.replace(/^(https?:)/, "");
|
|
816
850
|
xdr.open("POST", endpointUrl);
|
|
817
851
|
// compose an array of payloads
|
|
818
852
|
var batch = buffer[_DYN_BATCH_PAYLOADS /* @min:%2ebatchPayloads */](payload);
|
|
@@ -849,14 +883,15 @@ var Sender = /** @class */ (function (_super) {
|
|
|
849
883
|
* Validate UUID Format
|
|
850
884
|
* Specs taken from https://tools.ietf.org/html/rfc4122 and breeze repo
|
|
851
885
|
*/
|
|
852
|
-
function _validateInstrumentationKey(config) {
|
|
853
|
-
var
|
|
886
|
+
function _validateInstrumentationKey(instrumentationKey, config) {
|
|
887
|
+
var disableValidation = config.disableInstrumentationKeyValidation;
|
|
888
|
+
var disableIKeyValidationFlag = isNullOrUndefined(disableValidation) ? false : disableValidation;
|
|
854
889
|
if (disableIKeyValidationFlag) {
|
|
855
890
|
return true;
|
|
856
891
|
}
|
|
857
892
|
var UUID_Regex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
|
858
893
|
var regexp = new RegExp(UUID_Regex);
|
|
859
|
-
return regexp.test(
|
|
894
|
+
return regexp.test(instrumentationKey);
|
|
860
895
|
}
|
|
861
896
|
function _initDefaults() {
|
|
862
897
|
_self[_DYN__SENDER /* @min:%2e_sender */] = null;
|
|
@@ -876,6 +911,22 @@ var Sender = /** @class */ (function (_super) {
|
|
|
876
911
|
_fallbackSender = null;
|
|
877
912
|
_syncUnloadSender = null;
|
|
878
913
|
_evtNamespace = null;
|
|
914
|
+
_endpointUrl = null;
|
|
915
|
+
_orgEndpointUrl = null;
|
|
916
|
+
_maxBatchSizeInBytes = 0;
|
|
917
|
+
_beaconSupported = false;
|
|
918
|
+
_customHeaders = null;
|
|
919
|
+
_disableTelemetry = false;
|
|
920
|
+
_instrumentationKey = null;
|
|
921
|
+
_convertUndefined = UNDEFINED_VALUE;
|
|
922
|
+
_isRetryDisabled = false;
|
|
923
|
+
objDefineProp(_self, "_senderConfig", {
|
|
924
|
+
enumerable: true,
|
|
925
|
+
configurable: true,
|
|
926
|
+
get: function () {
|
|
927
|
+
return objExtend({}, defaultAppInsightsChannelConfig);
|
|
928
|
+
}
|
|
929
|
+
});
|
|
879
930
|
}
|
|
880
931
|
});
|
|
881
932
|
return _this;
|