CodexBloom - Programming Q&A Platform

Telemetry data not being sent in Angular app with Azure Application Insights

👀 Views: 56 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-01
angular application-insights telemetry typescript

I've been struggling with this for a few days now and could really use some help. I'm relatively new to this, so bear with me. I'm integrating Azure Application Insights into my Angular 14 application to track telemetry data, but I'm working with an scenario where the telemetry data isn't being sent to the Azure portal. I have followed the official documentation and set up the Application Insights SDK as follows: ```typescript import { ApplicationInsights } from '@microsoft/applicationinsights-web'; const appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY', enableAutoRouteTracking: true } }); appInsights.loadAppInsights(); ``` After this setup, I tried to track a custom event when a button is clicked: ```html <button (click)="trackButtonClick()">Click Me</button> ``` ```typescript trackButtonClick() { appInsights.trackEvent({ name: 'ButtonClicked' }); } ``` However, when I check the Azure portal, there are no custom events logged, and I don't see any behavior messages in the console. I have verified that the instrumentation key is correct and that the Application Insights resources are properly set up in Azure. I also tried adding `appInsights.flush();` after tracking the event to ensure that the telemetry was sent immediately, but still no luck. Additionally, when I inspect network requests in the browser's developer tools, there are no outgoing requests to the Application Insights endpoint. I suspect there might be an scenario with how I initialized the SDK or how Angular lifecycle hooks are affecting the timing of the telemetry sending. I've also checked my `angular.json` file to ensure that necessary polyfills or configurations aren't missing. Has anyone encountered this scenario before, or does anyone have suggestions on what to check next? I'm working on a web app that needs to handle this. Any ideas what could be causing this? What am I doing wrong?