2
votes

The Azure documentation for App Insights doesn't appear to have fresh articles relating to Windows 10 UWP Apps specifically. This appears to be endemic throughout all services (Notification Hub, Mobile Apps, Azure AD, etc.). So far I have found only references to Windows 8/8.1 Universal apps. I'm not sure how applicable they are but some code snippets do seem to compile at least.

My problem is that I have just setup a new App Insights instance for a 'WindowsStore App'. This is intended for a Windows 10 UWP app.

In my app, I have done the following:

  1. Ingested the nuget package for App Insights which has created an ApplicationInsights.config file.
  2. Updated the Instrumentation Key with the one from my WindowsStore App Insights Instance in the Azure Portal.
  3. Added Internet (Client) capability in application manifest.
  4. Created a static TelemetryClient that I use throughout all my Views / View Models.

    private static TelemetryClient telemetry = new TelemetryClient();
    public static TelemetryClient Telemetry
    {
        get { return telemetry; }
    }
    
  5. Updated the WindowsAppInitializer to include several WindowsCollectors.

            Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
            WindowsCollectors.Metadata | 
            WindowsCollectors.Session | 
            WindowsCollectors.PageView | 
            WindowsCollectors.UnhandledException
            );
    
  6. Added an event handler within App.xaml.cs for Unhandled Exception and call TelemetryClient.TrackException on the exception.

    private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        ViewModelDispatcher.Telemetry.TrackException(e.Exception);
    }
    
  7. Added TelemetryClient.TrackPageViews to OnNavigatedTo overrides in my views.

But so far, after doing all that, my App Insights dashboard in the Azure Portal is showing zip, zilch, nada. :\

This makes me think one of two things is going on. Either I am missing some critical piece of this recipe or I'm still within the refresh window for the App Insights Dashboard.

2
hypothetically you don't need #6 since you had WindowsCollectors.UnhandledException already set in the initializeasync call. - John Gardner
but in my app config file is not adding.. how to add it.. - Devi Prasad

2 Answers

3
votes

Have you tried to include your instrumentation key to the call of InitializeAsync? I'm using the following code at the constructor of App class.

    Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
                    "YOURINST-RUME-NTAT-IONK-EY012345678",
                    WindowsCollectors.Metadata |
                    WindowsCollectors.PageView |
                    WindowsCollectors.Session |
                    WindowsCollectors.UnhandledException);

I haven't confirmed the current specs (yes...the documentation of ApplicationInsight is an labyrinth :( ), but from AI v1.0, you have not to include your instrumentation key to your applicationinsight.config. Instead of it, you can specify the key with the call of initializer.

2
votes

Recently found this (i work on the AI team and it still happened to me!).

If you manually added the applicationinsights.config file, make sure it is set to "Content" and "Copy if newer" in the project settings. If it isn't, then the sdk can't find the instrumentation key at runtime, since the applicationinsights.config file didn't get deployed to the device.

Update 1/11/2016: i just learned of another issue that can cause this: comments in the xml file that look like xml tags.

If your config file has any comments of the form:

<!-- <InstrumentationKey>anything</InstrumentationKey> -->

Or

<!-- 
Learn more about Application Insights configuration with ApplicationInsights.config here: 
http://go.microsoft.com/fwlink/?LinkID=513840

Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
 -->

(Like is common in examples you might have gotten online, or migrating from a previous version of the AI SDK's)

If those comments appear in your config file before your real key, then the win10 sdk startup code will find those in the comments instead of your real key.

So if you see debug output that says it is using the literal string "YourKey" instead your actual key, that's the reason. (The win10 sdk uses a regex to find your key instead of loading system.xml assemblies to parse the file)