@microsoft/applicationinsights-dependencies-js 2.7.5-nightly.2204-03 → 2.7.6

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/src/ajax.ts CHANGED
@@ -4,14 +4,13 @@
4
4
  import {
5
5
  RequestHeaders, CorrelationIdHelper, TelemetryItemCreator, ICorrelationConfig,
6
6
  RemoteDependencyData, dateTimeUtilsNow, DisabledPropertyName, IDependencyTelemetry,
7
- IConfig, ITelemetryContext, PropertiesPluginIdentifier, eDistributedTracingModes, IRequestContext, isInternalApplicationInsightsEndpoint
7
+ IConfig, ITelemetryContext, PropertiesPluginIdentifier, DistributedTracingModes, IRequestContext, isInternalApplicationInsightsEndpoint
8
8
  } from "@microsoft/applicationinsights-common";
9
9
  import {
10
10
  isNullOrUndefined, arrForEach, isString, strTrim, isFunction, LoggingSeverity, _InternalMessageId,
11
11
  IAppInsightsCore, BaseTelemetryPlugin, ITelemetryPluginChain, IConfiguration, IPlugin, ITelemetryItem, IProcessTelemetryContext,
12
12
  getLocation, getGlobal, strPrototype, IInstrumentCallDetails, InstrumentFunc, InstrumentProto, getPerformance,
13
- IInstrumentHooksCallbacks, objForEachKey, generateW3CId, getIEVersion, dumpObj, ICustomProperties, isXhrSupported, eventOn,
14
- mergeEvtNamespace, createUniqueNamespace, createProcessTelemetryContext
13
+ IInstrumentHooksCallbacks, IInstrumentHook, objForEachKey, generateW3CId, getIEVersion, dumpObj, ICustomProperties, isXhrSupported, attachEvent
15
14
  } from "@microsoft/applicationinsights-core-js";
16
15
  import { ajaxRecord, IAjaxRecordResponse } from "./ajaxRecord";
17
16
  import { Traceparent } from "./TraceParent";
@@ -22,7 +21,6 @@ const strDiagLog = "diagLog";
22
21
  const strAjaxData = "ajaxData";
23
22
  const strThrowInternal = "throwInternal";
24
23
  const strFetch = "fetch";
25
- const strTrackDependencyDataInternal = "trackDependencyDataInternal"; // Using string to help with minification
26
24
 
27
25
  // Using a global value so that to handle same iKey with multiple app insights instances (mostly for testing)
28
26
  let _markCount: number = 0;
@@ -160,7 +158,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
160
158
  disableFetchTracking: true,
161
159
  excludeRequestFromAutoTrackingPatterns: undefined,
162
160
  disableCorrelationHeaders: false,
163
- distributedTracingMode: eDistributedTracingModes.AI_AND_W3C,
161
+ distributedTracingMode: DistributedTracingModes.AI_AND_W3C,
164
162
  correlationHeaderExcludedDomains: [
165
163
  "*.blob.core.windows.net",
166
164
  "*.blob.core.chinacloudapi.cn",
@@ -200,49 +198,90 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
200
198
 
201
199
  constructor() {
202
200
  super();
203
- let _fetchInitialized: boolean; // fetch monitoring initialized
204
- let _xhrInitialized: boolean; // XHR monitoring initialized
205
- let _currentWindowHost: string;
206
- let _config: ICorrelationConfig;
207
- let _enableRequestHeaderTracking: boolean;
208
- let _enableAjaxErrorStatusText: boolean;
209
- let _trackAjaxAttempts: number;
201
+ let strTrackDependencyDataInternal = "trackDependencyDataInternal"; // Using string to help with minification
202
+ let location = getLocation();
203
+ let _fetchInitialized:boolean = false; // fetch monitoring initialized
204
+ let _xhrInitialized:boolean = false; // XHR monitoring initialized
205
+ let _currentWindowHost:string = location && location.host && location.host.toLowerCase();
206
+ let _config: ICorrelationConfig = AjaxMonitor.getEmptyConfig();
207
+ let _enableRequestHeaderTracking = false;
208
+ let _enableAjaxErrorStatusText = false;
209
+ let _trackAjaxAttempts: number = 0;
210
210
  let _context: ITelemetryContext;
211
211
  let _isUsingW3CHeaders: boolean;
212
212
  let _isUsingAIHeaders: boolean;
213
213
  let _markPrefix: string;
214
- let _enableAjaxPerfTracking: boolean;
215
- let _maxAjaxCallsPerView: number;
216
- let _enableResponseHeaderTracking: boolean;
217
- let _disabledUrls: any;
218
- let _disableAjaxTracking: boolean;
219
- let _disableFetchTracking: boolean;
214
+ let _enableAjaxPerfTracking:boolean = false;
215
+ let _maxAjaxCallsPerView:number = 0;
216
+ let _enableResponseHeaderTracking:boolean = false;
217
+ let _hooks:IInstrumentHook[] = [];
218
+ let _disabledUrls:any = {};
220
219
  let _excludeRequestFromAutoTrackingPatterns: string[] | RegExp[];
221
220
  let _addRequestContext: (requestContext?: IRequestContext) => ICustomProperties;
222
- let _evtNamespace: string | string[];
223
-
224
- dynamicProto(AjaxMonitor, this, (_self, _base) => {
225
- let _addHook = _base._addHook;
226
-
227
- _initDefaults();
228
221
 
222
+ dynamicProto(AjaxMonitor, this, (_self, base) => {
229
223
  _self.initialize = (config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => {
230
224
  if (!_self.isInitialized()) {
231
- _base.initialize(config, core, extensions, pluginChain);
225
+ base.initialize(config, core, extensions, pluginChain);
226
+ let ctx = _self._getTelCtx();
227
+ const defaultConfig = AjaxMonitor.getDefaultConfig();
228
+ objForEachKey(defaultConfig, (field, value) => {
229
+ _config[field] = ctx.getConfig(AjaxMonitor.identifier, field, value);
230
+ });
232
231
 
233
- _evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
232
+ let distributedTracingMode = _config.distributedTracingMode;
233
+ _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
234
+ _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
235
+ _enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
236
+ _maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
237
+ _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
238
+ _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
239
+ _addRequestContext = _config.addRequestContext;
240
+
241
+ _isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
242
+ _isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
243
+ if (_enableAjaxPerfTracking) {
244
+ let iKey = config.instrumentationKey || "unkwn";
245
+ if (iKey.length > 5) {
246
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
247
+ } else {
248
+ _markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
249
+ }
250
+ }
234
251
 
235
- _populateDefaults(config);
252
+ if (_config.disableAjaxTracking === false) {
253
+ _instrumentXhr();
254
+ }
236
255
 
237
- _instrumentXhr();
238
256
  _instrumentFetch();
239
- _populateContext();
257
+
258
+ if (extensions.length > 0 && extensions) {
259
+ let propExt: any, extIx = 0;
260
+ while (!propExt && extIx < extensions.length) {
261
+ if (extensions[extIx] && extensions[extIx].identifier === PropertiesPluginIdentifier) {
262
+ propExt = extensions[extIx];
263
+ }
264
+
265
+ extIx++;
266
+ }
267
+
268
+ if (propExt) {
269
+ _context = propExt.context; // we could move IPropertiesPlugin to common as well
270
+ }
271
+ }
240
272
  }
241
273
  };
242
274
 
243
- _self._doTeardown = () => {
244
- _initDefaults();
245
- };
275
+ _self.teardown = () => {
276
+ // Remove all instrumentation hooks
277
+ arrForEach(_hooks, (fn) => {
278
+ fn.rm();
279
+ });
280
+ _hooks = [];
281
+ _fetchInitialized = false;
282
+ _xhrInitialized = false;
283
+ _self.setInitialized(false);
284
+ }
246
285
 
247
286
  _self.trackDependencyData = (dependency: IDependencyTelemetry, properties?: { [key: string]: any }) => {
248
287
  _self[strTrackDependencyDataInternal](dependency, properties);
@@ -320,8 +359,8 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
320
359
  // Hack since expected format in w3c mode is |abc.def.
321
360
  // Non-w3c format is |abc.def
322
361
  // @todo Remove if better solution is available, e.g. handle in portal
323
- if ((_config.distributedTracingMode === eDistributedTracingModes.W3C
324
- || _config.distributedTracingMode === eDistributedTracingModes.AI_AND_W3C)
362
+ if ((_config.distributedTracingMode === DistributedTracingModes.W3C
363
+ || _config.distributedTracingMode === DistributedTracingModes.AI_AND_W3C)
325
364
  && typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== "."
326
365
  ) {
327
366
  dependency.id += ".";
@@ -348,73 +387,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
348
387
  ++_trackAjaxAttempts;
349
388
  }
350
389
 
351
- function _initDefaults() {
352
- let location = getLocation();
353
- _fetchInitialized = false; // fetch monitoring initialized
354
- _xhrInitialized = false; // XHR monitoring initialized
355
- _currentWindowHost = location && location.host && location.host.toLowerCase();
356
- _config = AjaxMonitor.getEmptyConfig();
357
- _enableRequestHeaderTracking = false;
358
- _enableAjaxErrorStatusText = false;
359
- _trackAjaxAttempts = 0;
360
- _context = null;
361
- _isUsingW3CHeaders = false;
362
- _isUsingAIHeaders = false;
363
- _markPrefix = null;
364
- _enableAjaxPerfTracking = false;
365
- _maxAjaxCallsPerView = 0;
366
- _enableResponseHeaderTracking = false;
367
- _disabledUrls = {};
368
- _disableAjaxTracking = false;
369
- _disableFetchTracking = true;
370
-
371
- _excludeRequestFromAutoTrackingPatterns = null
372
- _addRequestContext = null;
373
- _evtNamespace = null;
374
- }
375
-
376
- function _populateDefaults(config: IConfiguration) {
377
- let ctx = createProcessTelemetryContext(null, config, _self.core);
378
-
379
- // Reset to the empty config
380
- _config = AjaxMonitor.getEmptyConfig();
381
- const defaultConfig = AjaxMonitor.getDefaultConfig();
382
- objForEachKey(defaultConfig, (field, value) => {
383
- _config[field] = ctx.getConfig(AjaxMonitor.identifier, field, value);
384
- });
385
-
386
- let distributedTracingMode = _config.distributedTracingMode;
387
- _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
388
- _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
389
- _enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
390
- _maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
391
- _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
392
- _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
393
- _addRequestContext = _config.addRequestContext;
394
-
395
- _isUsingAIHeaders = distributedTracingMode === eDistributedTracingModes.AI || distributedTracingMode === eDistributedTracingModes.AI_AND_W3C;
396
- _isUsingW3CHeaders = distributedTracingMode === eDistributedTracingModes.AI_AND_W3C || distributedTracingMode === eDistributedTracingModes.W3C;
397
-
398
- if (_enableAjaxPerfTracking) {
399
- let iKey = config.instrumentationKey || "unkwn";
400
- if (iKey.length > 5) {
401
- _markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
402
- } else {
403
- _markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
404
- }
405
- }
406
-
407
- _disableAjaxTracking = !!_config.disableAjaxTracking;
408
- _disableFetchTracking = !!_config.disableFetchTracking;
409
- }
410
-
411
- function _populateContext() {
412
- let propExt = _self.core.getPlugin<any>(PropertiesPluginIdentifier);
413
- if (propExt) {
414
- _context = propExt.plugin.context; // we could move IPropertiesPlugin to common as well
415
- }
416
- }
417
-
418
390
  // discard the header if it's defined as ignoreHeaders in ICorrelationConfig
419
391
  function _canIncludeHeaders(header: string) {
420
392
  let rlt = true;
@@ -438,13 +410,12 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
438
410
 
439
411
  let global = getGlobal();
440
412
  let isPolyfill = (fetch as any).polyfill;
441
- if (!_disableFetchTracking && !_fetchInitialized) {
442
- _addHook(InstrumentFunc(global, strFetch, {
443
- ns: _evtNamespace,
413
+ if (_config.disableFetchTracking === false) {
414
+ _hooks.push(InstrumentFunc(global, strFetch, {
444
415
  // Add request hook
445
416
  req: (callDetails: IInstrumentCallDetails, input, init) => {
446
417
  let fetchData: ajaxRecord;
447
- if (!_disableFetchTracking && _fetchInitialized &&
418
+ if (_fetchInitialized &&
448
419
  !_isDisabledRequest(null, input, init) &&
449
420
  // If we have a polyfil and XHR instrumented then let XHR report otherwise we get duplicates
450
421
  !(isPolyfill && _xhrInitialized)) {
@@ -458,39 +429,35 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
458
429
  }
459
430
  },
460
431
  rsp: (callDetails: IInstrumentCallDetails, input) => {
461
- if (!_disableFetchTracking) {
462
- let fetchData = callDetails.ctx().data;
463
- if (fetchData) {
464
- // Replace the result with the new promise from this code
465
- callDetails.rslt = callDetails.rslt.then((response: any) => {
466
- _reportFetchMetrics(callDetails, (response||{}).status, input, response, fetchData, () => {
467
- let ajaxResponse:IAjaxRecordResponse = {
468
- statusText: response.statusText,
469
- headerMap: null,
470
- correlationContext: _getFetchCorrelationContext(response)
471
- };
472
-
473
- if (_enableResponseHeaderTracking) {
474
- const responseHeaderMap = {};
475
- response.headers.forEach((value: string, name: string) => {
476
- if (_canIncludeHeaders(name)) {
477
- responseHeaderMap[name] = value;
478
- }
479
- });
480
-
481
- ajaxResponse.headerMap = responseHeaderMap;
482
- }
483
-
484
- return ajaxResponse;
485
- });
486
-
487
- return response;
488
- })
489
- .catch((reason: any) => {
490
- _reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
491
- throw reason;
492
- });
493
- }
432
+ let fetchData = callDetails.ctx().data;
433
+ if (fetchData) {
434
+ // Replace the result with the new promise from this code
435
+ callDetails.rslt = callDetails.rslt.then((response: any) => {
436
+ _reportFetchMetrics(callDetails, (response||{}).status, input, response, fetchData, () => {
437
+ let ajaxResponse:IAjaxRecordResponse = {
438
+ statusText: response.statusText,
439
+ headerMap: null,
440
+ correlationContext: _getFetchCorrelationContext(response)
441
+ };
442
+
443
+ if (_enableResponseHeaderTracking) {
444
+ const responseHeaderMap = {};
445
+ response.headers.forEach((value: string, name: string) => {
446
+ if (_canIncludeHeaders(name)) { responseHeaderMap[name] = value; }
447
+ });
448
+
449
+ ajaxResponse.headerMap = responseHeaderMap;
450
+ }
451
+
452
+ return ajaxResponse;
453
+ });
454
+
455
+ return response;
456
+ })
457
+ .catch((reason: any) => {
458
+ _reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
459
+ throw reason;
460
+ });
494
461
  }
495
462
  },
496
463
  // Create an error callback to report any hook errors
@@ -506,8 +473,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
506
473
  // Note: Polyfill implementations that don't support the "poyyfill" tag are not supported
507
474
  // the workaround is to add a polyfill property to your fetch implementation before initializing
508
475
  // App Insights
509
- _addHook(InstrumentFunc(global, strFetch, {
510
- ns: _evtNamespace,
476
+ _hooks.push(InstrumentFunc(global, strFetch, {
511
477
  req: (callDetails: IInstrumentCallDetails, input, init) => {
512
478
  // Just call so that we record any disabled URL
513
479
  _isDisabledRequest(null, input, init);
@@ -523,27 +489,24 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
523
489
  }
524
490
 
525
491
  function _hookProto(target: any, funcName: string, callbacks: IInstrumentHooksCallbacks) {
526
- _addHook(InstrumentProto(target, funcName, callbacks));
492
+ _hooks.push(InstrumentProto(target, funcName, callbacks));
527
493
  }
528
494
 
529
495
  function _instrumentXhr():void {
530
- if (_supportsAjaxMonitoring(_self) && !_disableAjaxTracking && !_xhrInitialized) {
496
+ if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
531
497
  // Instrument open
532
498
  _hookProto(XMLHttpRequest, "open", {
533
- ns: _evtNamespace,
534
499
  req: (args:IInstrumentCallDetails, method:string, url:string, async?:boolean) => {
535
- if (!_disableAjaxTracking) {
536
- let xhr = args.inst as XMLHttpRequestInstrumented;
537
- let ajaxData = xhr[strAjaxData];
538
- if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
539
- if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
540
- // Only create a single ajaxData (even when multiple AI instances are running)
541
- _openHandler(xhr, method, url, async);
542
- }
543
-
544
- // always attach to the on ready state change (required for handling multiple instances)
545
- _attachToOnReadyStateChange(xhr);
500
+ let xhr = args.inst as XMLHttpRequestInstrumented;
501
+ let ajaxData = xhr[strAjaxData];
502
+ if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
503
+ if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
504
+ // Only create a single ajaxData (even when multiple AI instances are running)
505
+ _openHandler(xhr, method, url, async);
546
506
  }
507
+
508
+ // always attach to the on ready state change (required for handling multiple instances)
509
+ _attachToOnReadyStateChange(xhr);
547
510
  }
548
511
  },
549
512
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen,
@@ -552,17 +515,14 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
552
515
 
553
516
  // Instrument send
554
517
  _hookProto(XMLHttpRequest, "send", {
555
- ns: _evtNamespace,
556
518
  req: (args:IInstrumentCallDetails, context?: Document | BodyInit | null) => {
557
- if (!_disableAjaxTracking) {
558
- let xhr = args.inst as XMLHttpRequestInstrumented;
559
- let ajaxData = xhr[strAjaxData];
560
- if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
561
- _createMarkId("xhr", ajaxData);
562
- ajaxData.requestSentTime = dateTimeUtilsNow();
563
- _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
564
- ajaxData.xhrMonitoringState.sendDone = true;
565
- }
519
+ let xhr = args.inst as XMLHttpRequestInstrumented;
520
+ let ajaxData = xhr[strAjaxData];
521
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
522
+ _createMarkId("xhr", ajaxData);
523
+ ajaxData.requestSentTime = dateTimeUtilsNow();
524
+ _self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
525
+ ajaxData.xhrMonitoringState.sendDone = true;
566
526
  }
567
527
  },
568
528
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSend,
@@ -571,15 +531,12 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
571
531
 
572
532
  // Instrument abort
573
533
  _hookProto(XMLHttpRequest, "abort", {
574
- ns: _evtNamespace,
575
534
  req: (args:IInstrumentCallDetails) => {
576
- if (!_disableAjaxTracking) {
577
- let xhr = args.inst as XMLHttpRequestInstrumented;
578
- let ajaxData = xhr[strAjaxData];
579
- if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
580
- ajaxData.aborted = 1;
581
- ajaxData.xhrMonitoringState.abortDone = true;
582
- }
535
+ let xhr = args.inst as XMLHttpRequestInstrumented;
536
+ let ajaxData = xhr[strAjaxData];
537
+ if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
538
+ ajaxData.aborted = 1;
539
+ ajaxData.xhrMonitoringState.abortDone = true;
583
540
  }
584
541
  },
585
542
  hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxAbort,
@@ -587,19 +544,18 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
587
544
  });
588
545
 
589
546
  // Instrument setRequestHeader
590
- _hookProto(XMLHttpRequest, "setRequestHeader", {
591
- ns: _evtNamespace,
592
- req: (args: IInstrumentCallDetails, header: string, value: string) => {
593
- if (!_disableAjaxTracking && _enableRequestHeaderTracking) {
547
+ if (_enableRequestHeaderTracking) {
548
+ _hookProto(XMLHttpRequest, "setRequestHeader", {
549
+ req: (args: IInstrumentCallDetails, header: string, value: string) => {
594
550
  let xhr = args.inst as XMLHttpRequestInstrumented;
595
551
  if (_isMonitoredXhrInstance(xhr) && _canIncludeHeaders(header)) {
596
552
  xhr[strAjaxData].requestHeaders[header] = value;
597
553
  }
598
- }
599
- },
600
- hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader,
601
- "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
602
- });
554
+ },
555
+ hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxSetRequestHeader,
556
+ "Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
557
+ });
558
+ }
603
559
 
604
560
  _xhrInitialized = true;
605
561
  }
@@ -697,7 +653,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
697
653
  }
698
654
 
699
655
  function _attachToOnReadyStateChange(xhr: XMLHttpRequestInstrumented) {
700
- xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", () => {
656
+ xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = attachEvent(xhr, "readystatechange", () => {
701
657
  try {
702
658
  if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
703
659
  _onAjaxComplete(xhr);
@@ -716,7 +672,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
716
672
  });
717
673
  }
718
674
  }
719
- }, _evtNamespace);
675
+ });
720
676
  }
721
677
 
722
678
  function _getResponseText(xhr: XMLHttpRequestInstrumented) {
@@ -775,9 +731,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
775
731
  const parts = line.split(": ");
776
732
  const header = parts.shift();
777
733
  const value = parts.join(": ");
778
- if(_canIncludeHeaders(header)) {
779
- responseHeaderMap[header] = value;
780
- }
734
+ if(_canIncludeHeaders(header)) { responseHeaderMap[header] = value; }
781
735
  });
782
736
 
783
737
  ajaxResponse.headerMap = responseHeaderMap;
@@ -805,9 +759,9 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
805
759
  _self[strTrackDependencyDataInternal](dependency);
806
760
  } else {
807
761
  _reportXhrError(null, {
808
- requestSentTime: ajaxData.requestSentTime,
809
- responseFinishedTime: ajaxData.responseFinishedTime
810
- });
762
+ requestSentTime: ajaxData.requestSentTime,
763
+ responseFinishedTime: ajaxData.responseFinishedTime
764
+ });
811
765
  }
812
766
  } finally {
813
767
  // cleanup telemetry data
@@ -947,9 +901,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
947
901
  if (_enableRequestHeaderTracking) {
948
902
  let headers = new Headers((init ? init.headers : 0) || (input instanceof Request ? (input.headers || {}) : {}));
949
903
  headers.forEach((value, key) => {
950
- if (_canIncludeHeaders(key)) {
951
- requestHeaders[key] = value;
952
- }
904
+ if (_canIncludeHeaders(key)) { requestHeaders[key] = value; }
953
905
  });
954
906
  }
955
907
 
@@ -1055,6 +1007,10 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
1055
1007
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
1056
1008
  }
1057
1009
 
1010
+ public teardown():void {
1011
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
1012
+ }
1013
+
1058
1014
  public processTelemetry(item: ITelemetryItem, itemCtx?: IProcessTelemetryContext) {
1059
1015
  this.processNext(item, itemCtx);
1060
1016
  }
package/src/ajaxRecord.ts CHANGED
@@ -141,7 +141,7 @@ function _populatePerfData(ajaxData:ajaxRecord, dependency:IDependencyTelemetry)
141
141
  arrForEach(serverTiming, (value, idx) => {
142
142
  let name = normalizeJsName(value[strName] || "" + idx);
143
143
  let newValue = server[name] || {};
144
- objForEachKey(value, (key, val: any) => {
144
+ objForEachKey(value, (key, val) => {
145
145
  if (key !== strName && isString(val) || isNumber(val)) {
146
146
  if (newValue[key]) {
147
147
  val = newValue[key] + ";" + val;
package/types/ajax.d.ts CHANGED
@@ -22,6 +22,7 @@ export declare class AjaxMonitor extends BaseTelemetryPlugin implements IDepende
22
22
  priority: number;
23
23
  constructor();
24
24
  initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
25
+ teardown(): void;
25
26
  processTelemetry(item: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
26
27
  /**
27
28
  * Logs dependency call
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.19.5"
8
+ "packageVersion": "7.23.0"
9
9
  }
10
10
  ]
11
11
  }