/How to use Azure Monitor Application Insights to record custom events | Azure Tips and Tricks

How to use Azure Monitor Application Insights to record custom events | Azure Tips and Tricks

Video: How to use Azure Monitor Application Insights to record custom events | Azure Tips and Tricks


>> Learn how to use Azure Application Insights to make your application logging smarter with Custom Event Tracking in this episode of Azure Tips and Tricks. Azure Application Insights is a powerful monitoring tool that you can use to track everything about your application. You can also use Application Insights to track custom information. Let's do that for this application in Visual Studio.

Here I have an ASP.net core MVC application. I've already set up Application Insights for it but I'll show you how to add it if you haven't yet. It's simple. You can right-click on the "Project file" and click "Add Application Insights Telemetry". This takes you to the ad app insights wizard. This application is already running in Azure with Application Insights enabled. But if you want, you can add a new application insights instance from here as well. All I need to do now is add the Application Insights SDK by clicking here. All right. There it goes. Now that the SDK is added, I can show you how I use it to track custom events. I do that. For instance here, in the HomeController, I do that by referencing this package and then I create a telemetry client like this. I can use the client to talk to application insights. Here I do just that. The application uses this method to filter and search for things and I want to know what users are searching for or filtering on. So here, I send custom events to application insights.

READ  Schwab’s Trading Tools and Platforms

This is the name of the event. So, searched in this case. This is the data for this event, the search term that the user used and that's it. You can also track other things like performance metrics and exceptions straight from the telemetry client. This is what using Application Insights on the backend looks like. But you can also track client side events. Let me show you. Here in this JavaScript file, this method is responsible for showing a user and information box. I want to know which box the user is looking at. So, here I track a custom event called service click and I feed it this data which is the name of the service that the user is looking at. I don't have to instantiate a new telemetry client here. I can use Application Insights straight from the Window and that is because it is injected into the DOM.

Let's take a look at that. The code that I want to show is here in the layout page. Here, a piece of JavaScript is injected which contains the Application Insights tracking code and also a reference to the telemetry client. Simple, right? Now let's go to the Azure portal. Here in the Azure portal, we are in the Application Insights instance that my application is sending data to. The custom data that we're sending our events. So, let's look at the events page. Here we see that a lot of events happened and we can drill down on them to find out more. Let's do that. Here are the events statistics and here are the custom events searched, service click, and filtered on status. Cool, right? From here I can drill down on them. Let's look at the searched event. Here it is and here I can see that this specific event happens when someone entered the search term Redis Cache. As you've seen, it is very easy to log custom data with Application Insights in your back end and your front end.

READ  iPhone X vs iPhone XR - Which Should You Choose?

Use this as it will provide powerful insights about your application..