Skip to content

Commit

Permalink
[BUG] When using Multiple instances of AI only the first instance is …
Browse files Browse the repository at this point in the history
…correctly reporting ajax events #1655 (#1686)
  • Loading branch information
MSNev authored Oct 6, 2021
1 parent 401bd3c commit 25e8375
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions extensions/applicationinsights-dependencies-js/src/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,14 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
req: (args:IInstrumentCallDetails, method:string, url:string, async?:boolean) => {
let xhr = args.inst as XMLHttpRequestInstrumented;
let ajaxData = xhr[strAjaxData];
if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true) &&
(!ajaxData || !ajaxData.xhrMonitoringState.openDone)) {
_openHandler(xhr, method, url, async);
if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
// Only create a single ajaxData (even when multiple AI instances are running)
_openHandler(xhr, method, url, async);
}

// always attach to the on ready state change (required for handling multiple instances)
_attachToOnReadyStateChange(xhr);
}
},
hkErr: _createErrorCallbackFunc(_self, _InternalMessageId.FailedMonitorAjaxOpen,
Expand Down Expand Up @@ -643,8 +648,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
ajaxData.async = async;
ajaxData.errorStatusText = _enableAjaxErrorStatusText;
xhr[strAjaxData] = ajaxData;

_attachToOnReadyStateChange(xhr);
}

function _attachToOnReadyStateChange(xhr: XMLHttpRequestInstrumented) {
Expand Down

0 comments on commit 25e8375

Please sign in to comment.