Azure Application Insights (AI) is a great instrumentation tool that can help you learn about how your application is doing during run-time. It is currently in Preview mode, so bear that in mind when developing production ready apps. It gives you the ability to log lots of different kinds of information like tracing, page views, custom events, metrics and more.

Azure AI supports multiple platforms, but unfortunately they have not released a Xamarin package yet. There is one library which is for Xamarin.Forms since it uses the DependencyResolver. I have taken that and removed that dependency to make it compatible with Xamarin.iOS. You could do the same thing to use it for Xamarin.Android too if you like.

It’s very simple to use, all you need is your instrumentationkey which you can get from your Azure portal. Follow the steps from the MSDN tutorial as you can see here to create the Azure AI instance and get your key. Once done, you could download and reference the repository that I have created on GitHub, as you can find it here.

To start Azure AI on your Xamarin iOS app, you could do:

[code lang=”csharp”]

AzureAIManager.Setup();

AzureAIManager.Configure("my-user-or-device-name");

AzureAIManager.Start();

[/code]

The implementation of the AzureAIManager is as follows:

[code lang=”csharp”]

public static class AzureAIManager
{
public static void Setup(string appKey = "your-azure-AI-instrumentation-key")
{
AI.Xamarin.iOS.ApplicationInsights.Init();

var ai = new AI.Xamarin.iOS.ApplicationInsights ();
ApplicationInsights.Init (ai);

TelemetryManager.Init(new AI.Xamarin.iOS.TelemetryManager());
ApplicationInsights.Setup(appKey);

}

public static void Start()
{
ApplicationInsights.Start();
}

public static void Configure(string userId = "" )
{
ApplicationInsights.SetAutoPageViewTrackingDisabled(true);

if (string.IsNullOrEmpty(userId))
ApplicationInsights.SetUserId(userId);
}

public static void RenewSession()
{
ApplicationInsights.StartNewSession();
}
}

[/code]

I have not put this as a Nuget package because I am sure Microsoft will release one very soon, so until that happens, you can use this bindings to play around with Azure AI and you could even use it on your small projects.

Category:
Application Development and Integration, Azure Platform, Mobile
Tags:
, , , , , , ,

Join the conversation! 4 Comments

  1. “I have taken that and removed that dependency to make it compatible with Xamarin.iOS”
    How did you remove that dependecy?

Comments are closed.