AppDynamics Xamarin SDK  2021.5.1
Real user monitoring for your Xamarin app.
AppDynamics Xamarin SDK Documentation

Table of Contents

About the AppDynamics Xamarin SDK

The AppDynamics Xamarin SDK is a package that allows you to monitor the performance and activities of a Xamarin.Android, Xamarin.iOS and/or a Xamarin.Forms app.

The SDK includes APIs to instrument specific methods in your own code, to measure durations of operations in your application (like application start up, for example), or to report an arbitrary metric.

Xamarin.Forms on Windows or .NET

NOTE: The SDK only targets Android and iOS deployments. All other targets will build and run. However, at runtime, the SDK calls are "stubbed" out and will actually do no work.

Quick install

Add the Nuget Package to your project. It is called AppDynamics.Agent.<version>.nupkg.


The Namespace

We use the namespace AppDynamics.Agent. In order to use the abbreviated form of the methods below you should add a using directive:

Intializing the Agent

You must configure the agent and intialize it. The code to initialize is the same for all target platforms:

Note: See the AppDynamics.Agent.AgentConfiguration object for more configuration options

Where to best place this code snippet depends on the desgin of the application. It is usually best to place it as early as possible in the runtime lifecycle.

For iOS

In the AppDelegate.cs file under the class AppDelegate in the method:

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)

You may even consider placing it in the Main.cs int the method:

static void Main(string[] args)

before the AppDelegate is called.

For Android

In the MainActivity.cs file under the class MainActivity in the method:

protected override void OnCreate(Bundle savedInstanceState)

Manifest Changes

Although these are usually on by default, it is important to make sure that the following "Required Permissions" are enabled in the Properties/AndroidManifest.xml file:

Instrumenting methods

The AppDynamics Xamarin SDK can be used to instrument methods in your own code. When you do this, you'll be able to see how often the instrumented method is invoked, and how long it takes to run. To do this, add a call at the beginning and end of the method you'd like to instrument:

public class MyClass {
public MyClass() {
var tracker = AppDynamics.Agent.Instrumentation.BeginCall("MyClass", "Constructor");
// your code here

Timing events

Sometimes you want to time an event in your application that spans multiple methods. You can do this by calling the SDK when the event starts, and then again when it ends. For example, to track the time a user spends viewing a screen, the instrumentation looks like:

async private void StartCapturePreview_Click(object sender, RoutedEventArgs e) {
capturePreview.Source = captureManager;
await captureManager.StartPreviewAsync();
async private void StopCapturePreview_Click(object sender, RoutedEventArgs e) {
await captureManager.StopPreviewAsync();

Reporting metrics

If you'd like to report some other type of data, you can use a metric. The only requirement is that the metric value must be a long integer. Reporting a metric looks like this:

Reporting custom HTTP requests

You can report a Network Request by reporting via the SDK by using the AppDynamics.Agent.HTTPRequestTracker.


public async Task<string> Fetch(Uri uri) {
var client = new HttpClient();
// Create AppDynamics Tracker
// Add AppDynamics Server Correlation Headers
// each header could have multiple values
foreach (var value in header.Value) {
client.DefaultRequestHeaders.Add(header.Key, value);
var response = await client.GetAsync(uri);
// Add response information
tracker.ResponseCode = (int)response.StatusCode;
tracker.StatusLine = response.ReasonPhrase;
tracker.ResponseHeaderFields = response.Headers;
return await response.Content.ReadAsStringAsync();