Correlating Custom Event Telemetry in distributed applications in Microsoft Azure-Part 2
Leveraging the power of Application Insight SDK in ASP.Net Core 3.1 and Azure Cache for Redis and Kusto Query Language (KQL)
This is in continuation of my previous blog in which we have created Application Insight and Redis Cache. And then I also covered how we can capture and correlate custom EventTelemetry in distributed applications and send it to Azure Application Insight.
In this blog let's deploy the app services and see Azure Application Insight in action. And I will explain how we can see elegant view of all our custom EventTelemetry we captured in previous blog in Azure Application Insight . And then we will see how we can create nice visual representation of telemetry in Application Insight. And finally we will see how to get useful outcome of all great work we did using Application Insight SDK.
Deploy/Publish ProductManagementApp and ProductAPI in Azure as App Services
Publish ProductAPI from Visual Studio in Azure as App Service
Publish ProductManagementApp from Visual Studio in Azure as App Service
Post deployment App Services are ready to use in Azure
ProductManagementApp App Service
ProductAPI App Service
Now let's check our ProductAPI post deployment in Azure as App Service. It will just return product list data in json format.
Test the Product Management App
Step 1 : Now check our ProductManagementApp looks like running as Azure App Service
Step 2 : Let's click on Details to see specific product details
Step 3 : Click on Edit to edit select Product
Step 4 : Change the User to User2 in code
Now change the User to User2 in both ProductMangmentApp and ProductAPI as shown below screenshots and deploy both again to Azure.
Step 5 : Test ProductManagment App
Now to capture the different user actions let's repeat the same steps 1,2 and 3 mentioned above in Test the Product Management App section.
And then again repeat Step 4 and Step 5 for User3
The purpose here is just to test the application with different users (in our case 3 users) so that we will get EventTelemetry for multiple user actions. This I already mentioned in my previous blog under User Related Settings section.
ProductManagmentApp Code change for User
ProductAPI Code change for User
Application Insight in Action
This is how your application insight will look like.
Check Performance tab under Investigate option
Check User flows which shows very nice view of how user is engaged with your application.
Please notice wherever we have given event name it is showing below in User Flows.
Recommended by LinkedIn
Viewing Custom EventTelemetry - Most Awaited one guys !!!!!
Now it's time to see our Custom EventTelemetry in action. Let's go to Application Insight-Logs under Monitoring section and type below query. This is Kusto Query Language (KQL) It is the query language which is used by Azure Application Insights.
Whatever Custom EventTelemetry we have added we can query it from customEvents table .Please notice we need to refer custom properties we have added by customDimensions.<event property name>
So congratulations now we achieved what we want with all our nice work we did with Application Insight SDK in ASP.Net Core 3.1 . Now let's see awesome things we can do with this.
Query
customEvents
| project Time=timestamp,EventName=name, EventDetail= customDimensions.EventDescription ,ApplicationTier=customDimensions.ApplicationTier, User=tostring(customDimensions.User),EventTelemetryParentID=customDimensions.EventTelemetryParentID ,EventSource=customDimensions.AppInsightTelemetryEventSource
Result of above Query
Viewing how many users updated products by visiting Edit page
Query
customEvents
| where name == "ProductUpdatedFromProductAPI"
| summarize ProductUpdatesPerformed=sum(itemCount) by User=tostring(customDimensions.User)
Result of above Query
Viewing column chart view of how many users updated products
customEvents
| where name == "ProductUpdatedFromProductAPI"
| summarize ProductUpdatesPerformed=sum(itemCount) by User=tostring(customDimensions.User)
| render columncharts
Query Result -Column Chart
Viewing total events count per user
Query
customEvents
| where tostring(customDimensions.User) != ""
|summarize EventCountByUser=sum(itemCount) by tostring(customDimensions.User)
Query Result
Viewing how many users visited Product List page/view
Query
customEvents
| where name == "ProductListRequestedFromWebApp"
| summarize totalCount=sum(itemCount) by User=tostring(customDimensions.User)
Query Result
Viewing column chart of how many users visited Product List page/view
Query
customEvents
| where name == "ProductListRequestedFromWebApp"
| summarize ProductUpdatesPerformed=sum(itemCount) by User=tostring(customDimensions.User)
| render columncharts
Query Result-Column Chart
Viewing how many users visited Product Details page/view
Query
customEvents
| where name == "ProductDetailsRequested_UI"
| summarize ProductDetailsViewed=sum(itemCount) by User=tostring(customDimensions.User)s
Query Result
Conclusion
Application Insight has lot of power which you can leverage to monitor performance , user interactions, user engagements etc. So I have covered the most challenging part of how we can correlate custom event telemetry in the world of distributed applications. This can also be used in Microservices world as well.
I hope you enjoyed this a lot.
In case of any questions please send me an email on amolsj10@gmail.com or connect with me over LinkedIn Amol Joshi.
Nice one Amol
Awesome!