How to integrate HockeyApp with Application Insights

Starting from HockeySDK 4.1.1 we introduced integration with Application Insights. Now, having just single HockeySDK in your mobile application you can use features from both powerful products - HockeyApp and Application Insights, where HockeyApp is the leader on Windows Platform for Crash Reporting, Beta Distribution and Application Insights provides a rich experience for custom telemetry reporting.

This document contains the following sections:

  1. On-boarding to Application Insights
  2. Application Insights API
    1. TrackEvent
    2. TrackMetric
    3. TrackTrace
    4. TrackPageView
    5. TrackDependency
    6. TrackException
    7. Flush
  3. Application Insights SDK Migration

1. On-boarding to Application Insights

You can onboard to Application Insights through your Azure account. More details, please see this blog post.

Please note that Application Insights will cause additional costs on your Azure subscription, separate to HockeyApp. For details, please refer to the Application Insights pricing page. Also note that we highly recommend against buying the Enterprise tier as the node-based pricing is not suitable for mobile or desktop apps!

2. Application Insights API

HockeyApp for Windows provides six Application Insights APIs, which we will describe in detail below.

2.1 TrackEvent

HockeyApp provides in an event tracking feature. With Application Insights integration, you can add custom properties with custom values to any event you track.

   Microsoft.HockeyApp.HockeyClient.Current.TrackEvent(name, properties = null, metrics = null)

2.2 TrackMetric

TrackMetric API allows to send metrics that are not attached to particular events. For example, you could monitor a queue length at regular intervals.

    Microsoft.HockeyApp.HockeyClient.Current.TrackMetric(name, value, properties = null)

2.3 TrackTrace

Use this to help diagnose problems by sending a 'breadcrumb trail' to Application Insights.

    Microsoft.HockeyApp.HockeyClient.Current.TrackTrace(string message, severityLevel)

2.4 TrackPageView

In a your mobile application you might want to track a "page" whenever the user opens a pivot or a page in the application. User and session data is sent as properties along with page views, so the user and session charts come alive when there is page view telemetry.

    Microsoft.HockeyApp.HockeyClient.Current.TrackPageView(name)

2.5 TrackDependency

Use this api to log the duration and frequency of calls to external components on which your app depends, like HTTP calls or SQL calls.

    Microsoft.HockeyApp.HockeyClient.Current.TrackDependency( dependencyName, commandName, startTime, duration, success);

2.6 TrackException

Use this api to log handled exceptions from your application.

    Microsoft.HockeyApp.HockeyClient.Current.TrackException(exception, properties);

Please note, that for UWP application, you will see exception from TrackException method in HockeyApp application as a crash, for all other application types you will see exception from this method in Application Insights portal.

2.7 Flush

Normally the SDK sends data at times chosen to minimize impact on the user. However, in some cases you might want to flush the buffer - for example, if you are using the SDK in an application that shuts down. Please note, that the function is is synchronous and you need to invoke it only in case there is a real need in it.

    Microsoft.HockeyApp.HockeyClient.Flush();

3. Application Insights SDK Migration

If you are using the old Application Insights SDK for Windows, you have three options:

  1. Migrate to HockeySDK, either with your old instrumentation key from Application Insights or the App ID from HockeyApp (see below). This is the recommended option and you will benefit from future features. This is also the only option that enables support for .NET Native crash reporting.

  2. Keep using the Application Insights SDK, either with your old instrumentation key from Application Insights or the App ID from HockeyApp (see below). Please note that we no longer provide updates or bugfixes for the Application Insights SDK. Any support request will be mitigated by migration to HockeySDK.

  3. Review the source code of the Application Insights Core SDK and write you own wrapper for its API. This option is fully at your own risk and we are not able to provide help with this.

Both HockeySDK and Application Insights SDK send the same data format (called "Common Schema") to the same API endpoint, so you can use either SDK under the mentioned constraints. Both SDKs also use the same database for instrumentation keys or App IDs, with the following difference:

  • HockeySDK expects the App ID to be formatted as a 40-char hex string with no dashes, for example: 0873e2b98ad046a92c170a243a8515f6.

  • Application Insights SDK expects the instrumentation key formatted as a GUID, so the above example needs to be converted to: 0873e2b9-8ad0-46a9-2c17-0a243a8515f6.

We do not recommend to use both SDKs in the same app, i.e. you need to chose one.