How to add Microsoft Application Insights v1 to your Windows 8.1 Universal app
Late in 2014, Microsoft finally started Application Insights (AI), their own telemetry service for all kind of apps. For Windows (Phone) 8.1 apps, the service was a long running beta. This month, Microsoft finally released version 1.0 of Application Insights for Windows apps.
However, if you are upgrading from a previous version, you will see that AI will no longer send any data to Azure. This has a very simple reason. Microsoft moved the configuration from the former ApplicationInsights.config file to a class called WindowsAppInitializer. I only found this out because I commented at the corresponding documentation site, which causes Microsoft to send me an email with a link to the solution in the forums. You will not find these info in the documentation as of writing this blog post. Microsoft also updated the docs tonight.
I strongly recommend you to remove all old references in favor of just updating to avoid any glitches with the new API.
I played around with the new WindowsAppInitializer class. If you want to collect all data with the automatic WindowsCollectors, all you have to add to your code is one line in your App.xaml.cs constructor (Microsoft recommends to add it before all other code):
1
WindowsAppInitializer.InitializeAsync("your instrumentation key”);
That’s it. Really. Here’s a screen shot of the test app in Visual Studio I created to play around with the new WindowsAppInitializer class:
As you can see, telemetry data gets written to the debug output, and with that, it will be submitted to your Azure account. If you do not want to use all Collectors, just add those you want to use after your InstrumentationKey, separated with ‘ | ’ in the IninitalizeAsync Method. |
Adding custom telemetry data collection is still possible. Quick sample:
1
2
var tc = new TelemetryClient();
tc.TrackEvent("MainPage loaded... [WP TestEvent]");
This will send this string as a custom event to your Azure account. For more info about custom telemetry data, check this page.
As always, I hope this blog post is helpful for some of you.
Happy coding!
Comments powered by Disqus.