@microsoft/applicationinsights-channel-js 3.0.0-beta.2210-01 → 3.0.0-beta.2210-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 (37) hide show
  1. package/browser/applicationinsights-channel-js.integrity.json +9 -9
  2. package/browser/applicationinsights-channel-js.js +946 -428
  3. package/browser/applicationinsights-channel-js.js.map +1 -1
  4. package/browser/applicationinsights-channel-js.min.js +2 -2
  5. package/browser/applicationinsights-channel-js.min.js.map +1 -1
  6. package/dist/applicationinsights-channel-js.api.json +1 -1
  7. package/dist/applicationinsights-channel-js.d.ts +22 -22
  8. package/dist/applicationinsights-channel-js.js +946 -428
  9. package/dist/applicationinsights-channel-js.js.map +1 -1
  10. package/dist/applicationinsights-channel-js.min.js +2 -2
  11. package/dist/applicationinsights-channel-js.min.js.map +1 -1
  12. package/dist/applicationinsights-channel-js.rollup.d.ts +22 -22
  13. package/dist-esm/EnvelopeCreator.js +2 -2
  14. package/dist-esm/EnvelopeCreator.js.map +1 -1
  15. package/dist-esm/Interfaces.js +1 -1
  16. package/dist-esm/InternalConstants.js +1 -1
  17. package/dist-esm/Offline.js +1 -1
  18. package/dist-esm/SendBuffer.js +9 -11
  19. package/dist-esm/SendBuffer.js.map +1 -1
  20. package/dist-esm/Sender.js +186 -135
  21. package/dist-esm/Sender.js.map +1 -1
  22. package/dist-esm/Serializer.js +2 -3
  23. package/dist-esm/Serializer.js.map +1 -1
  24. package/dist-esm/TelemetryProcessors/Sample.js +1 -1
  25. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
  26. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
  27. package/dist-esm/__DynamicConstants.js +11 -15
  28. package/dist-esm/__DynamicConstants.js.map +1 -1
  29. package/dist-esm/applicationinsights-channel-js.js +1 -1
  30. package/package.json +4 -4
  31. package/src/Interfaces.ts +17 -17
  32. package/src/SendBuffer.ts +5 -5
  33. package/src/Sender.ts +194 -129
  34. package/src/__DynamicConstants.ts +10 -14
  35. package/types/Interfaces.d.ts +17 -17
  36. package/types/Sender.d.ts +4 -4
  37. package/types/__DynamicConstants.d.ts +5 -9
package/src/Sender.ts CHANGED
@@ -5,12 +5,13 @@ import {
5
5
  Trace, eRequestHeaders, isInternalApplicationInsightsEndpoint, utlCanUseSessionStorage
6
6
  } from "@microsoft/applicationinsights-common";
7
7
  import {
8
- BaseTelemetryPlugin, IAppInsightsCore, IConfiguration, IDiagnosticLogger, INotificationManager, IPlugin, IProcessTelemetryContext,
9
- IProcessTelemetryUnloadContext, ITelemetryItem, ITelemetryPluginChain, ITelemetryUnloadState, SendRequestReason, _eInternalMessageId,
10
- _throwInternal, _warnToConsole, arrForEach, createUniqueNamespace, dateNow, dumpObj, eLoggingSeverity, getExceptionName, getIEVersion,
11
- getJSON, getNavigator, getWindow, isArray, isBeaconsSupported, isFetchSupported, isNullOrUndefined, isXhrSupported, mergeEvtNamespace,
12
- objForEachKey, objKeys, useXDomainRequest
8
+ BaseTelemetryPlugin, IAppInsightsCore, IConfigDefaults, IConfiguration, IDiagnosticLogger, INotificationManager, IPlugin,
9
+ IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryItem, ITelemetryPluginChain, ITelemetryUnloadState,
10
+ SendRequestReason, _eInternalMessageId, _throwInternal, _warnToConsole, arrForEach, createProcessTelemetryContext, createUniqueNamespace,
11
+ dateNow, dumpObj, eLoggingSeverity, getExceptionName, getIEVersion, getJSON, getNavigator, getWindow, isArray, isBeaconsSupported,
12
+ isFetchSupported, isNullOrUndefined, isXhrSupported, mergeEvtNamespace, objExtend, objKeys, onConfigChange, useXDomainRequest
13
13
  } from "@microsoft/applicationinsights-core-js";
14
+ import { isTruthy, objDeepFreeze, objDefineProp } from "@nevware21/ts-utils";
14
15
  import {
15
16
  DependencyEnvelopeCreator, EventEnvelopeCreator, ExceptionEnvelopeCreator, MetricEnvelopeCreator, PageViewEnvelopeCreator,
16
17
  PageViewPerformanceEnvelopeCreator, TraceEnvelopeCreator
@@ -21,6 +22,8 @@ import { ArraySendBuffer, ISendBuffer, SessionStorageSendBuffer } from "./SendBu
21
22
  import { Serializer } from "./Serializer";
22
23
  import { Sample } from "./TelemetryProcessors/Sample";
23
24
 
25
+ const UNDEFINED_VALUE: undefined = undefined;
26
+
24
27
  const FetchSyncRequestSizeLimitBytes = 65000; // approx 64kb (the current Edge, Firefox and Chrome max limit)
25
28
 
26
29
  declare var XDomainRequest: {
@@ -40,31 +43,27 @@ function _getResponseText(xhr: XMLHttpRequest | IXDomainRequest) {
40
43
  return null;
41
44
  }
42
45
 
43
- function _getDefaultAppInsightsChannelConfig(): ISenderConfig {
44
- let defaultValue: string;
45
- let defaultCustomHeaders: [{header: string, value: string}];
46
-
47
- // set default values
48
- return {
49
- endpointUrl: () => DEFAULT_BREEZE_ENDPOINT + DEFAULT_BREEZE_PATH,
50
- emitLineDelimitedJson: () => false,
51
- maxBatchInterval: () => 15000,
52
- maxBatchSizeInBytes: () => 102400, // 100kb
53
- disableTelemetry: () => false,
54
- enableSessionStorageBuffer: () => true,
55
- isRetryDisabled: () => false,
56
- isBeaconApiDisabled: () => true,
57
- disableXhr: () => false,
58
- onunloadDisableFetch: () => false,
59
- onunloadDisableBeacon: () => false,
60
- instrumentationKey: () => defaultValue, // Channel doesn't need iKey, it should be set already
61
- namePrefix: () => defaultValue,
62
- samplingPercentage: () => 100,
63
- customHeaders: () => defaultCustomHeaders,
64
- convertUndefined: () => defaultValue,
65
- eventsLimitInMem: () => 10000
66
- }
67
- }
46
+ const defaultAppInsightsChannelConfig: IConfigDefaults<ISenderConfig> = objDeepFreeze({
47
+ // Use the default value (handles empty string in the configuration)
48
+ endpointUrl: { isVal: isTruthy, v: DEFAULT_BREEZE_ENDPOINT + DEFAULT_BREEZE_PATH },
49
+ emitLineDelimitedJson: false,
50
+ maxBatchInterval: 15000,
51
+ maxBatchSizeInBytes: 102400, // 100kb
52
+ disableTelemetry: false,
53
+ enableSessionStorageBuffer: true,
54
+ isRetryDisabled: false,
55
+ isBeaconApiDisabled:true,
56
+ disableXhr: false,
57
+ onunloadDisableFetch: false,
58
+ onunloadDisableBeacon: false,
59
+ instrumentationKey: UNDEFINED_VALUE, // Channel doesn't need iKey, it should be set already
60
+ namePrefix: UNDEFINED_VALUE,
61
+ samplingPercentage: 100,
62
+ customHeaders: UNDEFINED_VALUE,
63
+ convertUndefined: UNDEFINED_VALUE,
64
+ eventsLimitInMem: 10000
65
+
66
+ });
68
67
 
69
68
  type EnvelopeCreator = (logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any) => IEnvelope;
70
69
 
@@ -90,9 +89,9 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
90
89
  } else {
91
90
  envelope = orig;
92
91
  }
93
-
92
+
94
93
  let creator: EnvelopeCreator = EnvelopeTypeCreator[envelope.baseType] || EventEnvelopeCreator;
95
-
94
+
96
95
  return creator(logger, envelope, convertUndefined);
97
96
  }
98
97
 
@@ -103,7 +102,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
103
102
  /**
104
103
  * The configuration for this sender instance
105
104
  */
106
- public readonly _senderConfig: ISenderConfig = _getDefaultAppInsightsChannelConfig();
105
+ public readonly _senderConfig: ISenderConfig;
107
106
 
108
107
  /**
109
108
  * A method which will cause data to be send to the url
@@ -139,6 +138,16 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
139
138
  let _syncUnloadSender: SenderFunction; // The identified sender to use for the synchronous unload stage
140
139
  let _offlineListener: IOfflineListener;
141
140
  let _evtNamespace: string | string[];
141
+ let _endpointUrl: string;
142
+ let _orgEndpointUrl: string;
143
+ let _maxBatchSizeInBytes: number;
144
+ let _beaconSupported: boolean;
145
+ let _customHeaders: Array<{header: string, value: string}>;
146
+ let _disableTelemetry: boolean;
147
+ let _instrumentationKey: string;
148
+ let _convertUndefined: any;
149
+ let _isRetryDisabled: boolean;
150
+ let _maxBatchInterval: number;
142
151
 
143
152
  dynamicProto(Sender, this, (_self, _base) => {
144
153
 
@@ -155,7 +164,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
155
164
  _retryAt = null;
156
165
 
157
166
  // flush if we have exceeded the max-size already
158
- if (_self._buffer.size() > _self._senderConfig.maxBatchSizeInBytes()) {
167
+ if (_self._buffer.size() > _maxBatchSizeInBytes) {
159
168
  _self.triggerSend(true, null, SendRequestReason.MaxBatchSize);
160
169
  }
161
170
 
@@ -181,7 +190,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
181
190
 
182
191
  _self.onunloadFlush = () => {
183
192
  if (!_paused) {
184
- if ((_self._senderConfig.onunloadDisableBeacon() === false || _self._senderConfig.isBeaconApiDisabled() === false) && isBeaconsSupported()) {
193
+ if (_beaconSupported) {
185
194
  try {
186
195
  _self.triggerSend(true, _doUnloadSend, SendRequestReason.Unload);
187
196
  } catch (e) {
@@ -206,7 +215,6 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
206
215
  }
207
216
 
208
217
  _base.initialize(config, core, extensions, pluginChain);
209
- let ctx = _self._getTelCtx();
210
218
  let identifier = _self.identifier;
211
219
  _serializer = new Serializer(core.logger);
212
220
  _consecutiveErrors = 0;
@@ -218,70 +226,109 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
218
226
  _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
219
227
  _offlineListener = createOfflineListener(_evtNamespace);
220
228
 
221
- // TODO v3.x: Change the ISenderConfig to not be function calls
222
- const defaultConfig = _getDefaultAppInsightsChannelConfig();
223
- objForEachKey(defaultConfig, (field, value) => {
224
- _self._senderConfig[field] = () => {
225
- let theValue = ctx.getConfig(identifier, field, value())
226
- if (!theValue && field === "endpointUrl") {
227
- // Use the default value (handles empty string in the configuration)
228
- theValue = value();
229
+ // This function will be re-called whenever any referenced configuration is changed
230
+ _self._addHook(onConfigChange(config, () => {
231
+ let ctx = createProcessTelemetryContext(null, config, core);
232
+ let senderConfig = ctx.getExtCfg(identifier, defaultAppInsightsChannelConfig);
233
+
234
+ objDefineProp(_self, "_senderConfig", {
235
+ enumerable: true,
236
+ configurable: true,
237
+ get: function() {
238
+ return senderConfig;
229
239
  }
230
- return theValue;
240
+ });
241
+
242
+ _maxBatchSizeInBytes = senderConfig.maxBatchSizeInBytes;
243
+ _beaconSupported = (senderConfig.onunloadDisableBeacon === false || senderConfig.isBeaconApiDisabled === false) && isBeaconsSupported();
244
+
245
+ if (_self._buffer) {
246
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
247
+ // TODO 3.x.x !!! - Handle the enableSessionStorageBuffer changing
248
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
249
+ } else {
250
+ _self._buffer = (senderConfig.enableSessionStorageBuffer && utlCanUseSessionStorage())
251
+ ? new SessionStorageSendBuffer(diagLog, senderConfig) : new ArraySendBuffer(diagLog, senderConfig);
231
252
  }
232
- });
233
-
234
- _self._buffer = (_self._senderConfig.enableSessionStorageBuffer() && utlCanUseSessionStorage())
235
- ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
236
- _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
237
-
238
- if(!_validateInstrumentationKey(config)) {
239
- _throwInternal(diagLog,
240
- eLoggingSeverity.CRITICAL,
241
- _eInternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key "+config.instrumentationKey);
242
- }
243
253
 
244
- if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
245
- arrForEach(_self._senderConfig.customHeaders(), customHeader => {
246
- this.addHeader(customHeader.header, customHeader.value);
247
- });
248
- }
254
+ _self._sample = new Sample(senderConfig.samplingPercentage, diagLog);
249
255
 
250
- let senderConfig = _self._senderConfig;
251
- let sendPostFunc: SenderFunction = null;
252
- if (!senderConfig.disableXhr() && useXDomainRequest()) {
253
- sendPostFunc = _xdrSender; // IE 8 and 9
254
- } else if (!senderConfig.disableXhr() && isXhrSupported()) {
255
- sendPostFunc = _xhrSender;
256
- }
256
+ _instrumentationKey = senderConfig.instrumentationKey;
257
+ if(!_validateInstrumentationKey(_instrumentationKey, config)) {
258
+ _throwInternal(diagLog,
259
+ eLoggingSeverity.CRITICAL,
260
+ _eInternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + _instrumentationKey);
261
+ }
257
262
 
258
- if (!sendPostFunc && isFetchSupported()) {
259
- sendPostFunc = _fetchSender;
260
- }
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
+ }
261
271
 
262
- // always fallback to XHR
263
- _fallbackSender = sendPostFunc || _xhrSender;
272
+ _endpointUrl = _orgEndpointUrl = senderConfig.endpointUrl;
273
+ }
264
274
 
265
- if (!senderConfig.isBeaconApiDisabled() && isBeaconsSupported()) {
266
- // Config is set to always used beacon sending
267
- sendPostFunc = _beaconSender;
268
- }
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
+ }
269
281
 
270
- _self._sender = sendPostFunc || _xhrSender;
271
-
272
- if (!senderConfig.onunloadDisableFetch() && isFetchSupported(true)) {
273
- // Try and use the fetch with keepalive
274
- _syncUnloadSender = _fetchKeepAliveSender;
275
- } else if (isBeaconsSupported()) {
276
- // Try and use sendBeacon
277
- _syncUnloadSender = _beaconSender;
278
- } else if (!senderConfig.disableXhr() && useXDomainRequest()) {
279
- _syncUnloadSender = _xdrSender; // IE 8 and 9
280
- } else if (!senderConfig.disableXhr() && isXhrSupported()) {
281
- _syncUnloadSender = _xhrSender;
282
- } else {
283
- _syncUnloadSender = _fallbackSender;
284
- }
282
+
283
+ _customHeaders = senderConfig.customHeaders;
284
+ if (!isInternalApplicationInsightsEndpoint(_endpointUrl) && _customHeaders && _customHeaders.length > 0) {
285
+ arrForEach(_customHeaders, customHeader => {
286
+ this.addHeader(customHeader.header, customHeader.value);
287
+ });
288
+ } else {
289
+ _customHeaders = null;
290
+ }
291
+
292
+ let sendPostFunc: SenderFunction = null;
293
+ if (!senderConfig.disableXhr && useXDomainRequest()) {
294
+ sendPostFunc = _xdrSender; // IE 8 and 9
295
+ } else if (!senderConfig.disableXhr && isXhrSupported()) {
296
+ sendPostFunc = _xhrSender;
297
+ }
298
+
299
+ if (!sendPostFunc && isFetchSupported()) {
300
+ sendPostFunc = _fetchSender;
301
+ }
302
+
303
+ // always fallback to XHR
304
+ _fallbackSender = sendPostFunc || _xhrSender;
305
+
306
+ if (!senderConfig.isBeaconApiDisabled && isBeaconsSupported()) {
307
+ // Config is set to always used beacon sending
308
+ sendPostFunc = _beaconSender;
309
+ }
310
+
311
+ _self._sender = sendPostFunc || _xhrSender;
312
+
313
+ if (!senderConfig.onunloadDisableFetch && isFetchSupported(true)) {
314
+ // Try and use the fetch with keepalive
315
+ _syncUnloadSender = _fetchKeepAliveSender;
316
+ } else if (isBeaconsSupported()) {
317
+ // Try and use sendBeacon
318
+ _syncUnloadSender = _beaconSender;
319
+ } else if (!senderConfig.disableXhr && useXDomainRequest()) {
320
+ _syncUnloadSender = _xdrSender; // IE 8 and 9
321
+ } else if (!senderConfig.disableXhr && isXhrSupported()) {
322
+ _syncUnloadSender = _xhrSender;
323
+ } else {
324
+ _syncUnloadSender = _fallbackSender;
325
+ }
326
+
327
+ _disableTelemetry = senderConfig.disableTelemetry;
328
+ _convertUndefined = senderConfig.convertUndefined || UNDEFINED_VALUE;
329
+ _isRetryDisabled = senderConfig.isRetryDisabled;
330
+ _maxBatchInterval = senderConfig.maxBatchInterval;
331
+ }));
285
332
  };
286
333
 
287
334
  _self.processTelemetry = (telemetryItem: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => {
@@ -290,7 +337,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
290
337
 
291
338
  try {
292
339
  // if master off switch is set, don't send any data
293
- if (_self._senderConfig.disableTelemetry()) {
340
+ if (_disableTelemetry) {
294
341
  // Do not send/save data
295
342
  return;
296
343
  }
@@ -328,11 +375,10 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
328
375
  telemetryItem[SampleRate] = _self._sample.sampleRate;
329
376
  }
330
377
 
331
- const convertUndefined = _self._senderConfig.convertUndefined() || undefined;
332
378
  // construct an envelope that Application Insights endpoint can understand
333
379
  // if ikey of telemetry is provided and not empty, envelope will use this iKey instead of senderConfig iKey
334
- let defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
335
- let aiEnvelope = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, diagLogger, convertUndefined);
380
+ let defaultEnvelopeIkey = telemetryItem.iKey || _instrumentationKey;
381
+ let aiEnvelope = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, diagLogger, _convertUndefined);
336
382
  if (!aiEnvelope) {
337
383
  _throwInternal(diagLogger, eLoggingSeverity.CRITICAL, _eInternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
338
384
  return;
@@ -369,7 +415,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
369
415
  const buffer = _self._buffer;
370
416
  const bufferSize = buffer.size();
371
417
 
372
- if ((bufferSize + payload.length) > _self._senderConfig.maxBatchSizeInBytes()) {
418
+ if ((bufferSize + payload.length) > _maxBatchSizeInBytes) {
373
419
  _self.triggerSend(true, null, SendRequestReason.MaxBatchSize);
374
420
  }
375
421
 
@@ -402,8 +448,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
402
448
 
403
449
  /**
404
450
  * Immediately send buffered data
405
- * @param async {boolean} - Indicates if the events should be sent asynchronously
406
- * @param forcedSender {SenderFunction} - Indicates the forcedSender, undefined if not passed
451
+ * @param async - {boolean} - Indicates if the events should be sent asynchronously
452
+ * @param forcedSender - {SenderFunction} - Indicates the forcedSender, undefined if not passed
407
453
  */
408
454
  _self.triggerSend = (async = true, forcedSender?: SenderFunction, sendReason?: SendRequestReason) => {
409
455
  if (!_paused) {
@@ -411,7 +457,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
411
457
  const buffer = _self._buffer;
412
458
 
413
459
  // Send data only if disableTelemetry is false
414
- if (!_self._senderConfig.disableTelemetry()) {
460
+ if (!_disableTelemetry) {
415
461
 
416
462
  if (buffer.count() > 0) {
417
463
  const payload = buffer.getItems();
@@ -523,7 +569,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
523
569
  const results = _parseResponse(responseText);
524
570
 
525
571
  if (results && results.itemsReceived && results.itemsReceived > results.itemsAccepted
526
- && !_self._senderConfig.isRetryDisabled()) {
572
+ && !_isRetryDisabled) {
527
573
  _self._onPartialSuccess(payload, results);
528
574
  } else {
529
575
  _self._onError(payload, _formatErrorMessageXdr(xdr));
@@ -556,7 +602,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
556
602
  }
557
603
  }
558
604
 
559
- if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
605
+ if (!_isRetryDisabled && _isRetriable(status)) {
560
606
  _resendPayload(payload);
561
607
  _throwInternal(_self.diagLog(),
562
608
  eLoggingSeverity.WARNING,
@@ -567,7 +613,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
567
613
  }
568
614
  } else if (_offlineListener && !_offlineListener.isOnline()) { // offline
569
615
  // Note: Don't check for status == 0, since adblock gives this code
570
- if (!_self._senderConfig.isRetryDisabled()) {
616
+ if (!_isRetryDisabled) {
571
617
  const offlineBackOffMultiplier = 10; // arbritrary number
572
618
  _resendPayload(payload, offlineBackOffMultiplier);
573
619
 
@@ -586,7 +632,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
586
632
  response = _parseResponse(res);
587
633
  }
588
634
 
589
- if (response && !_self._senderConfig.isRetryDisabled()) {
635
+ if (response && !_isRetryDisabled) {
590
636
  _self._onPartialSuccess(payload, response);
591
637
  } else {
592
638
  _self._onError(payload, errorMessage);
@@ -606,8 +652,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
606
652
  return false;
607
653
  }
608
654
  if(!isNullOrUndefined(responseUrl) && responseUrl !== "") {
609
- if(responseUrl !== _self._senderConfig.endpointUrl()) {
610
- _self._senderConfig.endpointUrl = () => responseUrl;
655
+ if(responseUrl !== _endpointUrl) {
656
+ _endpointUrl = responseUrl;
611
657
  ++_stamp_specific_redirects;
612
658
  return true;
613
659
  }
@@ -628,7 +674,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
628
674
  function _doBeaconSend(payload: string[]) {
629
675
  const nav = getNavigator();
630
676
  const buffer = _self._buffer;
631
- const url = _self._senderConfig.endpointUrl();
677
+ const url = _endpointUrl;
632
678
  const batch = _self._buffer.batchPayloads(payload);
633
679
 
634
680
  // Chrome only allows CORS-safelisted values for the sendBeacon data argument
@@ -647,8 +693,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
647
693
  }
648
694
  /**
649
695
  * Send Beacon API request
650
- * @param payload {string} - The data payload to be sent.
651
- * @param isAsync {boolean} - not used
696
+ * @param payload - {string} - The data payload to be sent.
697
+ * @param isAsync - {boolean} - not used
652
698
  * Note: Beacon API does not support custom headers and we are not able to get
653
699
  * appId from the backend for the correct correlation.
654
700
  */
@@ -677,12 +723,12 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
677
723
 
678
724
  /**
679
725
  * Send XMLHttpRequest
680
- * @param payload {string} - The data payload to be sent.
681
- * @param isAsync {boolean} - Indicates if the request should be sent asynchronously
726
+ * @param payload - {string} - The data payload to be sent.
727
+ * @param isAsync - {boolean} - Indicates if the request should be sent asynchronously
682
728
  */
683
729
  function _xhrSender(payload: string[], isAsync: boolean) {
684
730
  const xhr = new XMLHttpRequest();
685
- const endPointUrl = _self._senderConfig.endpointUrl();
731
+ const endPointUrl = _endpointUrl;
686
732
  try {
687
733
  xhr[DisabledPropertyName] = true;
688
734
  } catch(e) {
@@ -733,8 +779,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
733
779
 
734
780
  /**
735
781
  * Send fetch API request
736
- * @param payload {string} - The data payload to be sent.
737
- * @param isAsync {boolean} - not used
782
+ * @param payload - {string} - The data payload to be sent.
783
+ * @param isAsync - {boolean} - not used
738
784
  */
739
785
  function _fetchSender(payload: string[], isAsync: boolean) {
740
786
  _doFetchSender(payload, true);
@@ -742,11 +788,11 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
742
788
 
743
789
  /**
744
790
  * Send fetch API request
745
- * @param payload {string} - The data payload to be sent.
746
- * @param isAsync {boolean} - For fetch this identifies whether we are "unloading" (false) or a normal request
791
+ * @param payload - {string} - The data payload to be sent.
792
+ * @param isAsync - {boolean} - For fetch this identifies whether we are "unloading" (false) or a normal request
747
793
  */
748
794
  function _doFetchSender(payload: string[], isAsync: boolean) {
749
- const endPointUrl = _self._senderConfig.endpointUrl();
795
+ const endPointUrl = _endpointUrl;
750
796
  const batch = _self._buffer.batchPayloads(payload);
751
797
  const plainTextBatch = new Blob([batch], { type: "application/json" });
752
798
  let requestHeaders = new Headers();
@@ -916,7 +962,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
916
962
  function _setupTimer() {
917
963
  if (!_timeoutHandle && !_paused) {
918
964
  const retryInterval = _retryAt ? Math.max(0, _retryAt - dateNow()) : 0;
919
- const timerValue = Math.max(_self._senderConfig.maxBatchInterval(), retryInterval);
965
+ const timerValue = Math.max(_maxBatchInterval, retryInterval);
920
966
 
921
967
  _timeoutHandle = setTimeout(() => {
922
968
  _timeoutHandle = null;
@@ -956,8 +1002,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
956
1002
 
957
1003
  /**
958
1004
  * Send XDomainRequest
959
- * @param payload {string} - The data payload to be sent.
960
- * @param isAsync {boolean} - Indicates if the request should be sent asynchronously
1005
+ * @param payload - {string} - The data payload to be sent.
1006
+ * @param isAsync - {boolean} - Indicates if the request should be sent asynchronously
961
1007
  *
962
1008
  * Note: XDomainRequest does not support sync requests. This 'isAsync' parameter is added
963
1009
  * to maintain consistency with the xhrSender's contract
@@ -974,7 +1020,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
974
1020
  // XDomainRequest requires the same protocol as the hosting page.
975
1021
  // If the protocol doesn't match, we can't send the telemetry :(.
976
1022
  const hostingProtocol = _window && _window.location && _window.location.protocol || "";
977
- if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
1023
+ if (_endpointUrl.lastIndexOf(hostingProtocol, 0) !== 0) {
978
1024
  _throwInternal(_self.diagLog(),
979
1025
  eLoggingSeverity.WARNING,
980
1026
  _eInternalMessageId.TransmissionFailed, ". " +
@@ -984,7 +1030,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
984
1030
  return;
985
1031
  }
986
1032
 
987
- const endpointUrl = _self._senderConfig.endpointUrl().replace(/^(https?:)/, "");
1033
+ const endpointUrl = _endpointUrl.replace(/^(https?:)/, "");
988
1034
  xdr.open("POST", endpointUrl);
989
1035
 
990
1036
  // compose an array of payloads
@@ -1031,14 +1077,16 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
1031
1077
  * Validate UUID Format
1032
1078
  * Specs taken from https://tools.ietf.org/html/rfc4122 and breeze repo
1033
1079
  */
1034
- function _validateInstrumentationKey(config: IConfiguration & IConfig) :boolean {
1035
- const disableIKeyValidationFlag = isNullOrUndefined(config.disableInstrumentationKeyValidation) ? false : config.disableInstrumentationKeyValidation;
1080
+ function _validateInstrumentationKey(instrumentationKey: string, config: IConfiguration & IConfig) :boolean {
1081
+ let disableValidation = config.disableInstrumentationKeyValidation;
1082
+ const disableIKeyValidationFlag = isNullOrUndefined(disableValidation) ? false : disableValidation;
1036
1083
  if(disableIKeyValidationFlag) {
1037
1084
  return true;
1038
1085
  }
1086
+
1039
1087
  const UUID_Regex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
1040
1088
  const regexp = new RegExp(UUID_Regex);
1041
- return regexp.test(config.instrumentationKey);
1089
+ return regexp.test(instrumentationKey);
1042
1090
  }
1043
1091
 
1044
1092
  function _initDefaults() {
@@ -1059,6 +1107,23 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
1059
1107
  _fallbackSender = null;
1060
1108
  _syncUnloadSender = null;
1061
1109
  _evtNamespace = null;
1110
+ _endpointUrl = null;
1111
+ _orgEndpointUrl = null;
1112
+ _maxBatchSizeInBytes = 0;
1113
+ _beaconSupported = false;
1114
+ _customHeaders = null;
1115
+ _disableTelemetry = false;
1116
+ _instrumentationKey = null;
1117
+ _convertUndefined = UNDEFINED_VALUE;
1118
+ _isRetryDisabled = false;
1119
+
1120
+ objDefineProp(_self, "_senderConfig", {
1121
+ enumerable: true,
1122
+ configurable: true,
1123
+ get: function() {
1124
+ return objExtend({}, defaultAppInsightsChannelConfig);
1125
+ }
1126
+ });
1062
1127
  }
1063
1128
  });
1064
1129
  }
@@ -1114,8 +1179,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
1114
1179
 
1115
1180
  /**
1116
1181
  * Immediately send buffered data
1117
- * @param async {boolean} - Indicates if the events should be sent asynchronously
1118
- * @param forcedSender {SenderFunction} - Indicates the forcedSender, undefined if not passed
1182
+ * @param async - {boolean} - Indicates if the events should be sent asynchronously
1183
+ * @param forcedSender - {SenderFunction} - Indicates the forcedSender, undefined if not passed
1119
1184
  */
1120
1185
  public triggerSend(async = true, forcedSender?: SenderFunction, sendReason?: SendRequestReason) {
1121
1186
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
@@ -1151,8 +1216,8 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
1151
1216
 
1152
1217
  /**
1153
1218
  * Add header to request
1154
- * @param name - Header name.
1155
- * @param value - Header value.
1219
+ * @param name - Header name.
1220
+ * @param value - Header value.
1156
1221
  */
1157
1222
  public addHeader(name: string, value: string) {
1158
1223
  // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
@@ -24,6 +24,7 @@ export const _DYN_TO_STRING = "toString"; // Count: 7
24
24
  export const _DYN_ON_LINE = "onLine"; // Count: 4
25
25
  export const _DYN_ENQUEUE = "enqueue"; // Count: 5
26
26
  export const _DYN_COUNT = "count"; // Count: 6
27
+ export const _DYN_EVENTS_LIMIT_IN_MEM = "eventsLimitInMem"; // Count: 2
27
28
  export const _DYN_PUSH = "push"; // Count: 6
28
29
  export const _DYN_EMIT_LINE_DELIMITED_0 = "emitLineDelimitedJson"; // Count: 3
29
30
  export const _DYN_CLEAR = "clear"; // Count: 6
@@ -33,36 +34,31 @@ export const _DYN_CLEAR_SENT = "clearSent"; // Count: 5
33
34
  export const _DYN__BUFFER__KEY = "BUFFER_KEY"; // Count: 5
34
35
  export const _DYN__SENT__BUFFER__KEY = "SENT_BUFFER_KEY"; // Count: 7
35
36
  export const _DYN__MAX__BUFFER__SIZE = "MAX_BUFFER_SIZE"; // Count: 5
36
- export const _DYN_NAME_PREFIX = "namePrefix"; // Count: 6
37
- export const _DYN_MAX_BATCH_SIZE_IN_BY1 = "maxBatchSizeInBytes"; // Count: 3
37
+ export const _DYN_NAME_PREFIX = "namePrefix"; // Count: 4
38
38
  export const _DYN_TRIGGER_SEND = "triggerSend"; // Count: 6
39
39
  export const _DYN_DIAG_LOG = "diagLog"; // Count: 15
40
- export const _DYN_ONUNLOAD_DISABLE_BEA2 = "onunloadDisableBeacon"; // Count: 2
41
- export const _DYN_IS_BEACON_API_DISABL3 = "isBeaconApiDisabled"; // Count: 3
42
40
  export const _DYN__SENDER = "_sender"; // Count: 5
43
- export const _DYN__SENDER_CONFIG = "_senderConfig"; // Count: 4
44
- export const _DYN__BUFFER = "_buffer"; // Count: 7
41
+ export const _DYN_MAX_BATCH_SIZE_IN_BY1 = "maxBatchSizeInBytes"; // Count: 2
42
+ export const _DYN_ONUNLOAD_DISABLE_BEA2 = "onunloadDisableBeacon"; // Count: 2
43
+ export const _DYN_IS_BEACON_API_DISABL3 = "isBeaconApiDisabled"; // Count: 2
44
+ export const _DYN__BUFFER = "_buffer"; // Count: 8
45
45
  export const _DYN_ENABLE_SESSION_STORA4 = "enableSessionStorageBuffer"; // Count: 2
46
46
  export const _DYN_SAMPLING_PERCENTAGE = "samplingPercentage"; // Count: 2
47
- export const _DYN_INSTRUMENTATION_KEY = "instrumentationKey"; // Count: 4
48
- export const _DYN_ENDPOINT_URL = "endpointUrl"; // Count: 8
49
- export const _DYN_CUSTOM_HEADERS = "customHeaders"; // Count: 4
47
+ export const _DYN_INSTRUMENTATION_KEY = "instrumentationKey"; // Count: 2
48
+ export const _DYN_CUSTOM_HEADERS = "customHeaders"; // Count: 3
50
49
  export const _DYN_DISABLE_XHR = "disableXhr"; // Count: 5
51
50
  export const _DYN_ONUNLOAD_DISABLE_FET5 = "onunloadDisableFetch"; // Count: 2
52
- export const _DYN_DISABLE_TELEMETRY = "disableTelemetry"; // Count: 2
51
+ export const _DYN_CONVERT_UNDEFINED = "convertUndefined"; // Count: 2
52
+ export const _DYN_MAX_BATCH_INTERVAL = "maxBatchInterval"; // Count: 2
53
53
  export const _DYN_BASE_TYPE = "baseType"; // Count: 4
54
54
  export const _DYN_SAMPLE_RATE = "sampleRate"; // Count: 4
55
- export const _DYN_CONVERT_UNDEFINED = "convertUndefined"; // Count: 2
56
55
  export const _DYN__XHR_READY_STATE_CHA6 = "_xhrReadyStateChange"; // Count: 2
57
56
  export const _DYN__ON_ERROR = "_onError"; // Count: 11
58
57
  export const _DYN__ON_PARTIAL_SUCCESS = "_onPartialSuccess"; // Count: 3
59
58
  export const _DYN__ON_SUCCESS = "_onSuccess"; // Count: 6
60
59
  export const _DYN_ITEMS_ACCEPTED = "itemsAccepted"; // Count: 5
61
60
  export const _DYN_ITEMS_RECEIVED = "itemsReceived"; // Count: 6
62
- export const _DYN_IS_RETRY_DISABLED = "isRetryDisabled"; // Count: 5
63
61
  export const _DYN_SET_REQUEST_HEADER = "setRequestHeader"; // Count: 3
64
- export const _DYN_MAX_BATCH_INTERVAL = "maxBatchInterval"; // Count: 2
65
62
  export const _DYN_EVENTS_SEND_REQUEST = "eventsSendRequest"; // Count: 2
66
- export const _DYN_DISABLE_INSTRUMENTAT7 = "disableInstrumentationKeyValidation"; // Count: 2
67
63
  export const _DYN_GET_SAMPLING_SCORE = "getSamplingScore"; // Count: 2
68
64
  export const _DYN_GET_HASH_CODE_SCORE = "getHashCodeScore"; // Count: 4