Skip to content

Commit

Permalink
Merge pull request #199 from devm33/devm33/fix-aiwb
Browse files Browse the repository at this point in the history
Set xhr override before creating AppInsights client
  • Loading branch information
lramos15 committed Feb 21, 2024
2 parents 3a87442 + a2c7721 commit 997abf0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/common/appInsightsClientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import type { ApplicationInsights } from "@microsoft/applicationinsights-web-basic";
import type { IXHROverride } from "@microsoft/applicationinsights-core-js";
import type { IXHROverride, IConfiguration } from "@microsoft/applicationinsights-core-js";
import { BreezeChannelIdentifier } from "@microsoft/applicationinsights-common";
import { ReplacementOption, SenderData } from "./baseTelemetryReporter";
import { BaseTelemetryClient } from "./baseTelemetrySender";
Expand All @@ -15,6 +15,16 @@ export const appInsightsClientFactory = async (key: string, xhrOverride?: IXHROv
let appInsightsClient: ApplicationInsights | undefined;
try {
const basicAISDK = await import/* webpackMode: "eager" */("@microsoft/applicationinsights-web-basic");
const extensionConfig: IConfiguration["extensionConfig"] = {};
if (xhrOverride) {
// Configure the channel to use a XHR Request override since it's not available in node
const channelConfig: IChannelConfiguration = {
alwaysUseXhrOverride: true,
httpXHROverride: xhrOverride
};
extensionConfig[BreezeChannelIdentifier] = channelConfig;
}

appInsightsClient = new basicAISDK.ApplicationInsights({
instrumentationKey: key,
disableAjaxTracking: true,
Expand All @@ -24,19 +34,9 @@ export const appInsightsClientFactory = async (key: string, xhrOverride?: IXHROv
disableCookiesUsage: true,
autoTrackPageVisitTime: false,
emitLineDelimitedJson: false,
disableInstrumentationKeyValidation: true
},
);

if (xhrOverride) {
appInsightsClient.config.extensionConfig = {};
// Configure the channel to use a XHR Request override since it's not available in node
const channelConfig: IChannelConfiguration = {
alwaysUseXhrOverride: true,
httpXHROverride: xhrOverride
};
appInsightsClient.config.extensionConfig[BreezeChannelIdentifier] = channelConfig;
}
disableInstrumentationKeyValidation: true,
extensionConfig,
});
} catch (e) {
return Promise.reject(e);
}
Expand Down

0 comments on commit 997abf0

Please sign in to comment.