Set up the Agentedit

Follow these steps to start reporting your Java application’s performance to Elastic APM:

Set up Gradleedit

First, add the Elastic APM agent plugin to your application’s build.gradle file as shown below:

// Android app's build.gradle file
plugins {
    id "com.android.application"
    id "co.elastic.apm.android" version "[latest_version]" 
}

The Elastic plugin declaration must be added below the Android app plugin declaration (com.android.application) and below the Kotlin plugin declaration (if used).

After adding the agent plugin, configure it. A minimal configuration sets the Elastic APM Server endpoint as shown below:

// Android app's build.gradle file
plugins {
    //...
    id "co.elastic.apm.android" version "[latest_version]"
}

elasticApm {
    // Minimal configuration
    serverUrl = "https://your.elastic.server"

    // Optional
    serviceName = "your app name" 
    serviceVersion = "0.0.0" 
    secretToken = "your server auth token" 
}

Defaults to your android.defaultConfig.applicationId value.

Defaults to your android.defaultConfig.versionName value.

Defaults to null.

Set up your applicationedit

After syncing your project with the Gradle changes above, the Elastic APM agent needs to be initialized within your Application class. This example shows the simplest way to configure the agent:

// Your Application class

class MyApp extends android.app.Application {

    @Override
    public void onCreate() {
        super.onCreate();
        ElasticApmAgent.initialize(this); 
    }
}

Initialize the Elastic APM agent once.

Compile and runedit

All that’s left is to compile and run your application. That’s it!

After initializing the agent as shown above, you’ll automatically create traces for all OkHttp network requests and for all Activity and Fragment starting methods.

Head over to the APM app in Kibana to see your Android application events, or see configuration for details on how to tailor the Elastic APM agent to your project’s needs.