RUM Android Monitoring

RUM Android Monitoring

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Datadog Real User Monitoring (RUM) enables you to visualize and analyze the real-time performance and user journeys of your application’s individual users.

Setup

  1. Declare SDK as a dependency.
  2. Specify application details in UI.
  3. Initialize the library with application context.
  4. Initialize RUM Monitor, Interceptor and start sending data.

Minimum Android OS version: Datadog SDK for Android supports Android OS v19+.

Declare SDK as dependency

Declare dd-sdk-android and gradle plugin as a dependency in your build.gradle file:

plugins {
    id("dd-sdk-android-gradle-plugin")
}
dependencies {
    implementation "com.datadoghq:dd-sdk-android:x.x.x" 
}
buildscript {
    dependencies {
        classpath("com.datadoghq:dd-sdk-android-gradle-plugin:x.x.x")
    }
}

Specify application details in UI

  1. Select UX Monitoring -> RUM Applications -> New Application
  2. Choose android as your Application Type in Datadog UI and provide a new application name to generate a unique Datadog application ID and client token.

image

To ensure the safety of your data, you must use a client token. You cannot use only Datadog API keys to configure the dd-sdk-android library, as they would be exposed client-side in the Android application APK byte code. For more information about setting up a client token, see the Client Token documentation.

Initialize the library with application context

class SampleApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        val configuration = Configuration.Builder(
            rumEnabled = true,
            crashReportsEnabled = true
        )
                        .trackInteractions()
                        .trackLongTasks(durationThreshold)
                        .useViewTrackingStrategy(strategy)
                        .build()
          val credentials = Credentials(<CLIENT_TOKEN>, <ENV_NAME>, <APP_VARIANT_NAME>, <APPLICATION_ID>)
          Datadog.initialize(this, credentials, configuration, trackingConsent)

       }
   }
class SampleApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        val configuration = Configuration.Builder(
            rumEnabled = true,
            crashReportsEnabled = true
        )
                        .trackInteractions()
                        .trackLongTasks(durationThreshold)
                        .useViewTrackingStrategy(strategy)
                        .useEUEndpoints()
                        .build()
        val credentials = Credentials(<CLIENT_TOKEN>, <ENV_NAME>, <APP_VARIANT_NAME>, <APPLICATION_ID>)
        Datadog.initialize(this, credentials, configuration, trackingConsent)
          
    }
}

Learn more about ViewTrackingStrategy to enable automatic tracking of all your views (activities, fragments, etc.), trackingConsent to add GDPR compliance for your EU users, and other configuration options to initialize the library.

Note that in the credentials required for initialization, your application variant name is also required. This is important because it enables the right ProGuard mapping.txt file to be automatically uploaded at build time to be able to view de-obfuscated stack traces. For more information see the guide to uploading Android source mapping files.

Initialize RUM Monitor and Interceptor

Configure and register the RUM Monitor. You only need to do it once, usually in your application’s onCreate() method:

    val monitor = RumMonitor.Builder()
            .build()
    GlobalRum.registerIfAbsent(monitor)

To track your OkHttp requests as resources, add the provided Interceptor:

    val okHttpClient =  OkHttpClient.Builder()
        .addInterceptor(DatadogInterceptor())
        .build()

This records each request processed by the OkHttpClient as a resource in RUM, with all the relevant information automatically filled (URL, method, status code, error). Note that only network requests started when a view is active are tracked. If you want to track requests when your application is in the background, you can create a view manually.

Note: If you also use multiple Interceptors, DatadogInterceptor must be called first.

You can further add an EventListener for the OkHttpClient to automatically track resource timing (third-party providers, network requests).

Further Reading

Documentation, liens et articles supplémentaires utiles: