Adding Application Insights to an existing Web API with Trace Diagnostics.
Application Insights is an extremely useful application monitoring feature of Microsoft Azure which can be used with many different types of Azure services.
Application insights can be used for ensuring your application’s availability, diagnosing exceptions and performance issues and generally analysing your application’s usage.
In this article I will show you how to quickly and easily setup application insights on your existing ASP.NET Web API. We will also add Trace Diagnostics which will enable us to view in detail any failed requests, show the stack trace and errors encountered.
1) Right click on your Web API project in Visual Studio and click Add Application Insights Telemetry. This will quickly get you up and running, recording analytics from your API.
2) Install the NuGet package.
This enables your API in one simple step. Run your application in Debug mode and make a request then see it in your Azure Portal. We now want to take it one step further and record all Trace Diagnostics on the API which will enable you to quickly debug a failed request or failed dependences.
4) Search Application Insights Web API Tracing in NuGet
5) Once you install this great Package from the API team you only need to add one piece of code to enable the trace listener. Add the below line of code to your app Start Up Config.
That’s it! Your API is now recording all Trace Diagnostics in Application Insights. Run your API, make some requests and why not dummy a failed request!
Just a note : with trace diagnostics enabled you will quickly run past your FREE allocation on a well used live service. My advice would be to only enable System Diagnostics Tracing when you are wanting to squash a bug.
If you would prefer to watch a video to gain a better understanding, I would suggest the following :
Instrumenting your Web API using Application Insights with Victor Mushkatin
For more information please visit Microsoft : https://azure.microsoft.com/en-gb/services/application-insights/