Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,51 @@ export class AjaxTests extends AITestClass {
}
});

this.testCase({
name: "Fetch: fetch keeps custom headers when correlation headers are discarded by dependencyListeners",
test: () => {
hookFetch((resolve) => {
AITestClass.orgSetTimeout(function() {
resolve();
}, 0);
});


this._ajax = new AjaxMonitor();
this._ajax.addDependencyListener((details: IDependencyListenerDetails) => {
return false;
});
let appInsightsCore = new AppInsightsCore();
let coreConfig = {
instrumentationKey: "",
disableFetchTracking: false,
disableAjaxTracking: true
};
appInsightsCore.initialize(coreConfig, [this._ajax, new TestChannelPlugin()]);
let fetchSpy = this.sandbox.spy(window, "fetch");

// Setup
let headers = new Headers();
headers.append('My-Header', 'Header field');
let init = {
method: 'get',
headers: headers
};
const url = 'https://httpbin.org/status/200';

let headerSpy = this.sandbox.spy(this._ajax, "includeCorrelationHeaders");

// Act
Assert.ok(fetchSpy.notCalled);
fetch(url, init);

// Assert
Assert.ok(fetchSpy.calledOnce);
Assert.ok(headerSpy.calledOnce);
Assert.deepEqual(init, headerSpy.returnValue || headerSpy.returnValues[0]);
}
});

this.testCaseAsync({
name: "Fetch: should create and pass a traceparent header if ai and w3c is enabled with custom headers",
stepDelay: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IAjaxMonitorPlug

init.headers = headers;
}

return init;
} else if (xhr) { // XHR
if (correlationIdCanIncludeCorrelationHeader(_extensionConfig, ajaxData.getAbsoluteUrl(), currentWindowHost)) {
if (_isUsingAIHeaders) {
Expand Down Expand Up @@ -512,12 +510,10 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IAjaxMonitorPlug
}
}
}

return xhr;
}
}

return undefined;
return xhr || init;
}

_self.trackDependencyDataInternal = (dependency: IDependencyTelemetry, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) => {
Expand Down