Skip to content

Commit 997abf0

Browse files
authored
Merge pull request #199 from devm33/devm33/fix-aiwb
Set xhr override before creating AppInsights client
2 parents 3a87442 + a2c7721 commit 997abf0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/common/appInsightsClientFactory.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import type { ApplicationInsights } from "@microsoft/applicationinsights-web-basic";
7-
import type { IXHROverride } from "@microsoft/applicationinsights-core-js";
7+
import type { IXHROverride, IConfiguration } from "@microsoft/applicationinsights-core-js";
88
import { BreezeChannelIdentifier } from "@microsoft/applicationinsights-common";
99
import { ReplacementOption, SenderData } from "./baseTelemetryReporter";
1010
import { BaseTelemetryClient } from "./baseTelemetrySender";
@@ -15,6 +15,16 @@ export const appInsightsClientFactory = async (key: string, xhrOverride?: IXHROv
1515
let appInsightsClient: ApplicationInsights | undefined;
1616
try {
1717
const basicAISDK = await import/* webpackMode: "eager" */("@microsoft/applicationinsights-web-basic");
18+
const extensionConfig: IConfiguration["extensionConfig"] = {};
19+
if (xhrOverride) {
20+
// Configure the channel to use a XHR Request override since it's not available in node
21+
const channelConfig: IChannelConfiguration = {
22+
alwaysUseXhrOverride: true,
23+
httpXHROverride: xhrOverride
24+
};
25+
extensionConfig[BreezeChannelIdentifier] = channelConfig;
26+
}
27+
1828
appInsightsClient = new basicAISDK.ApplicationInsights({
1929
instrumentationKey: key,
2030
disableAjaxTracking: true,
@@ -24,19 +34,9 @@ export const appInsightsClientFactory = async (key: string, xhrOverride?: IXHROv
2434
disableCookiesUsage: true,
2535
autoTrackPageVisitTime: false,
2636
emitLineDelimitedJson: false,
27-
disableInstrumentationKeyValidation: true
28-
},
29-
);
30-
31-
if (xhrOverride) {
32-
appInsightsClient.config.extensionConfig = {};
33-
// Configure the channel to use a XHR Request override since it's not available in node
34-
const channelConfig: IChannelConfiguration = {
35-
alwaysUseXhrOverride: true,
36-
httpXHROverride: xhrOverride
37-
};
38-
appInsightsClient.config.extensionConfig[BreezeChannelIdentifier] = channelConfig;
39-
}
37+
disableInstrumentationKeyValidation: true,
38+
extensionConfig,
39+
});
4040
} catch (e) {
4141
return Promise.reject(e);
4242
}

0 commit comments

Comments
 (0)