I have an Angular application and it is deployed as a static website in Azure storage account. I use the following code to set up Application Insights in my app. After deployment, I can not see any trace data in my App Insights workspace.
loadApplicationInsights() {
this._initAppInsights();
this._appInsights?.loadAppInsights();
}
logException(exception: Error, severityLevel?: number) {
this._appInsights?.trackException({ exception: exception, severityLevel: severityLevel });
}
logTrace(message: string, properties?: { [key: string]: any }) {
this._appInsights?.trackTrace({ message: message}, properties);
}
private _initAppInsights() {
const { enableInsights, instrumentationKey } = this._appConfig.envConfig.applicationInsights || { enableInsights: false, instrumentationKey: null };
if (enableInsights && instrumentationKey){
this._appInsights = new ApplicationInsights({
config: {
instrumentationKey,
enableAutoRouteTracking: true,
}
});
}
}
This setting works when I deploy the app to Azure web app. What needs to be adjusted for static website hosting in Azure storage account?
Firstly, Install
npm install --save @microsoft/applicationinsights-web
in your Angular application.Configure CORS rules to allow requests from your static website's domain. This is crucial for Application Insights to send telemetry data to the correct endpoint.