I’ve been doing a lot of work on software monitoring solutions lately and got totally blown away at how well Azure App Insights is quick to integrate and easy to use for web sites.
The first thing i did was to go into Azure, add a new App Insight instance (located under developer services). Once that is done, go grab the API key which is in the properties pane.
Second, step, add to your website the Microsoft ApplicationInsights Web nuget, that will add everything you need to get going. he nuget modifies your web.config so it includes the handler for ApplicationInsights to monitor your web site. At the same time a new file called ApplicationInsights.config is added to your solution. Make sure to go into that file and put the right API key. At this point you can start your app and start collecting server information.
If you want to also grab what’s happening in the browser, then go to your _layout.cshtml file (if you are doing mvc), and add this code:
<script type=”text/javascript”>
var appInsights=window.appInsights||function(config){
function s(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},r=document,f=window,e=“script”,o=r.createElement(e),i,u;for(o.src=config.url||“//az416426.vo.msecnd.net/scripts/a/ai.0.js”,r.getElementsByTagName(e)[0].parentNode.appendChild(o),t.cookie=r.cookie,t.queue=[],i=[“Event”,“Exception”,“Metric”,“PageView”,“Trace”];i.length;)s(“track”+i.pop());return config.disableExceptionTracking||(i=“onerror”,s(“_”+i),u=f[i],f[i]=function(config,r,f,e,o){var s=u&&u(config,r,f,e,o);return s!==!0&&t[“_”+i](config,r,f,e,o),s}),t
}({
url:“@Url.Content(@”~/Scripts/ai.0.15.0-build30412.min.js”)“,
instrumentationKey:“@Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey“,
});
window.appInsights=appInsights;
appInsights.trackPageView();
</script>
What this will do is the load the App Insights script form my own web site (and not from the CDN) and then configure it to use the API key in my applicationinsights.config file.
Voilà ! that’s it!

Leave a comment