Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Azure ApplicationsInsights for Xamarin iOS

DZone's Guide to

Azure ApplicationsInsights for Xamarin iOS

The Azure ApplicationInsights instrumentation tool lets you monitor your application during runtime. Learn to get it running on your Xamarin iOS app.

· Mobile Zone ·
Free Resource

Azure ApplicationInsights (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 instrumentation key, 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:

AzureAIManager.Setup();

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

AzureAIManager.Start();

The implementation of the AzureAIManager is as follows:

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();
    }
}

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 these bindings to play around with Azure AI, and you could even use it for your small projects.

Topics:
mobile ,ios ,xamarin ,azure ai ,mobile app development

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}