Configure the Splunk RUM Android agent

Configure the Splunk Observability Cloud real user monitoring / RUM instrumentation for your Android applications.

You can configure the Splunk RUM agent to add custom attributes, adapt the instrumentation to your environment and application, customize sampling, and more.

To configure the Android RUM agent, pass the settings by preparing an AgentConfiguration instance. The following example shows how to configure an AgentConfiguration instance with your Splunk RUM token, Splunk realm, application name, and deployment environment:

Kotlin
val agent = SplunkRum.install(
    application = this,
    agentConfiguration = AgentConfiguration(
        endpoint = EndpointConfiguration(
            realm = "your_splunk_realm",
            rumAccessToken = "your-splunk-rum-access-token"
        ),
        appName = "Android demo app",
        deploymentEnvironment = "dev"
    )
)
Java
SplunkRum agent = SplunkRum.install(
    this,
    new AgentConfiguration(
        new EndpointConfiguration(
            "your_splunk_realm",
            "your_splunk_access_token"
        ),
        "Android demo app",
        "dev"
    )
);

General settings

Use the following settings to configure the Android RUM agent:

OptionDescription
endpoint (required)Sets the configuration needed to export data to an endpoint. Specifically two required inputs:
appName (required)Sets the application name.
deploymentEnvironment(required)Environment for all the spans produced by the application. For example, dev, test, or prod.
appVersionSets the application version.
globalAttributesAttributes to append to every span collected. For an example, see Manage global attributes.
spanInterceptorUse this setting to filter or customize spans. For example, you can use (SpanData) -> SpanData? to redact personal identifiable information (PII), remove span attributes, or change the span name. See Filter spans.
userConfigured by UserConfiguration for end user tracking. It has following properties: trackingMode with a default of NO TRACKING.
sessionConfigured by SessionConfiguration for configuring sessions. It has following properties: samplingRate Activates session ID based sampling and sets a sampling ratio. The sampling ratio is the probability of a session being included between. Values range between 0.0 (all dropped) and 1.0 (all included).
enableDebugLoggingActivates debug logging. Default: false
deferredUntilForegroundDefer telemetry until the app is brought to the foreground. Default: false
instrumentedProcessNameCompares application ID and process name. If they are the same, the application is visible to user. If not, it is the background process.

Instrumentation module settings

You can configure the following modules in the Splunk RUM agent:

Note: A module's settings only take effect if that module is activated (its isEnabled attribute is set to true). All modules except for navigation detection are activated by default.

HTTP instrumentation module

Automatic network instrumentation

The Android RUM agent supports automatic instrumentation for the OkHttp and HttpURLConnection HTTP clients.

  • Okhttp3

    This instrumentation automatically modifies the code at build time and adds the necessary hooks for tracing network requests made through the OkHttp3 APIs. To activate this, add the following plugin to your Android application:

    plugins {
      id("com.splunk.rum-okhttp3-auto-plugin") version "2.0.0"
    }
    Note: If you don't add the plugin to the application at build time, the runtime OkHttp3AutoModuleConfiguration will have no effect.
  • HttpUrlConnection

    This instrumentation automatically modifies the code at build time and adds the necessary hooks for tracing network requests made via the URLConnection , HttpURLConnection, or HttpsURLConnection APIs. To enable this, add the following plugin to your Android application.

    plugins {
      id("com.splunk.rum-httpurlconnection-auto-plugin") version "2.0.0"
    }
    Note: If you don't add the plugin to the application at build time, the runtime HttpUrlModuleConfiguration will have no effect.
    Note:

    Note: There is currently an open issue with Google that may result in a build failure when an application is built with these plugins. It's related to the Jetifier. The issue is tracked in the Google Issue Tracker and can be resolved by setting the enableJetifier flag to false in your gradle.properties file. For example, android.enableJetifier=false

Manual OkHttp instrumentation
  1. Obtain the instrumented Call.Factory object using the following API:

    Kotlin
    // Provide your OkHttpClient to this API to obtain the instrumented Call.Factory 
    val instrumentedCallFactory = SplunkRum.instance.okHttpManualInstrumentation.buildOkHttpCallFactory(okHttpClient)
    Java
    Call.Factory instrumentedCallFactory = OkHttpManualInstrumentation.instance.buildOkHttpCallFactory(okHttpClient);
  2. Use the obtained Call.Factory object (similar to how you would use the OkHttpClient object) to make requests. For example:

    Kotlin
    val request = Request.Builder()
        .url("https://publicobject.com/helloworld.txt")
        .build()
    
    instrumentedCallFactory.newCall(request).execute().use { response ->
      if (!response.isSuccessful) throw IOException("Unexpected code $response")
    
      for ((name, value) in response.headers) {
        println("$name: $value")
      }
    
      println(response.body?.string())
    }
    Java
    Request request = new Request.Builder()
            .url("https://publicobject.com/helloworld.txt")
            .build();
    
    Call call = instrumentedCallFactory.newCall(request);
    
    Response response = null;
    try {
        response = call.execute();
    
        if (!response.isSuccessful()) {
            throw new IOException("Unexpected code " + response);
        }
    
        // Print all response headers
        Headers headers = response.headers();
        for (int i = 0; i < headers.size(); i++) {
            System.out.println(headers.name(i) + ": " + headers.value(i));
        }
    
        // Print response body
        if (response.body() != null) {
            System.out.println(response.body().string());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
Capture request and response headers

You can opt-in to capture certain request and response headers using the HTTP instrumentation module. If those headers are available, the resulting span will contain http.request.header.<key> and http.response.header.<key> attributes with the header value(s). See OkHttp3ManualModuleConfiguration , HttpURLModuleConfiguration or OkHttp3AutoModuleConfiguration below for examples.

Kotlin
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_env"
            ),
            moduleConfigurations = arrayOf( 
                // Instruments HttpUrlConnection requests and responses.
                // isEnabled = true to enable instrumentation.
                // capturedRequestHeaders / capturedResponseHeaders lists the headers to capture.
                HttpURLModuleConfiguration(
                    isEnabled = true,
                    capturedRequestHeaders = listOf("Host", "Accept"),
                    capturedResponseHeaders = listOf("Date", "Content-Type", "Content-Length")
                ),

                // Instruments OkHttp3 automatically.
                // isEnabled = true to enable auto-instrumentation.
                // capturedRequestHeaders / capturedResponseHeaders lists the headers to capture.
                OkHttp3AutoModuleConfiguration(
                    isEnabled = true,
                    capturedRequestHeaders = listOf("User-Agent", "Accept"),
                    capturedResponseHeaders = listOf("Date", "Content-Type", "Content-Length")
                ),

                // Instruments OkHttp3 manually.
                // capturedRequestHeaders / capturedResponseHeaders lists the headers to capture.
                OkHttp3ManualModuleConfiguration(
                    capturedRequestHeaders = listOf("Content-Type", "Accept"),
                    capturedResponseHeaders = listOf("Server", "Content-Type", "Content-Length")
                )
            )
        )
    }
}
Java
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        SplunkRum agent = SplunkRum.install(
            this,
            new AgentConfiguration(
                new EndpointConfiguration(
                    "your_splunk_realm",
                    "your_splunk_rum_access_token"
                ),
                "your_app_name",
                "your_deployment_environment"
            ),

            // Instruments HttpUrlConnection requests and responses.
            new HttpURLModuleConfiguration(
                true,
                Arrays.asList("Host", "Accept"),
                Arrays.asList("Date", "Content-Type", "Content-Length")
            ),

            // Instruments OkHttp3 automatically.
            new OkHttp3AutoModuleConfiguration(
                true,
                Arrays.asList("User-Agent", "Accept"),
                Arrays.asList("Date", "Content-Type", "Content-Length")
            ),

            // Instruments OkHttp3 manually.
            new OkHttp3ManualModuleConfiguration(
                Arrays.asList("Content-Type", "Accept"),
                Arrays.asList("Server", "Content-Type", "Content-Length")
            )
        );
    }
}
Tip: See what attributes are included when this module is activated.
Track navigation events automatically

Automatic detection of screen names is deactivated by default. You can activate it through the isAutomatedTrackingEnabled setting as shown in the examples below.

Kotlin
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_env"
            ),
            moduleConfigurations = arrayOf( 
                // Tracks navigation for activities and fragments.
                // isEnabled = true to enable navigation tracking.
                // isAutomatedTrackingEnabled = false disables automated tracking.
                NavigationModuleConfiguration(
                    isEnabled = true,
                    isAutomatedTrackingEnabled = true
                )
            )
        )
    }
}
Java
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        SplunkRum agent = SplunkRum.install(
            this,
            new AgentConfiguration(
                new EndpointConfiguration(
                    "your_splunk_realm",
                    "your_splunk_rum_access_token"
                ),
                "your_app_name",
                "your_deployment_environment"
            ),

            // Tracks screen names
            new NavigationModuleConfiguration(true, true)
        );
    }
}
Track navigation events manually

See Manually track navigation events.

Crash reporting module

The crash reporting module is included in the new Splunk RUM agent and is activated by default. No additional steps are needed to activate crash reporting. If you want to deactivate crash reporting, see an example below on settings.

Kotlin
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_environment"
            ),
            moduleConfigurations = arrayOf( 
                // Reports application crashes.
                // isEnabled = false to disable crash reporting.
                CrashModuleConfiguration(
                    isEnabled = false
                )
            )
        )
    }
}
Java
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        SplunkRum agent = SplunkRum.install(
            this,
            new AgentConfiguration(
                new EndpointConfiguration(
                    "your_splunk_realm",
                    "your_splunk_rum_access_token"
                ),
                "your_app_name",
                "your_deployment_environment"
            ),

            // Disables application crashes.
            new CrashModuleConfiguration(false)
        );
    }
}

Application not responding module

Application not responding (ANR) occurs when an Android application's main thread is blocked for more than five seconds, preventing it from processing user input. The detection of ANRs is activated by default. You can deactivate it by setting AnrModuleConfiguration to false as shown in the examples below.

Kotlin
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_environment"
            ),
            moduleConfigurations = arrayOf( 
                // Reports ANR (Application Not Responding) events.
                // isEnabled = false to disable ANR reporting.
                AnrModuleConfiguration(
                    isEnabled = false
                )
            )
        )
    }
}
Java
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        SplunkRum agent = SplunkRum.install(
            this,
            new AgentConfiguration(
                new EndpointConfiguration(
                    "your_splunk_realm",
                    "your_splunk_rum_access_token"
                ),
                "your_app_name",
                "your_deployment_environment"
            ),

            // Disables ANR (Application Not Responding) events.
            new AnrModuleConfiguration(false)
        );
    }
}

Slow rendering module

The slow rendering module is activated by default. You can configure its frame detection interval as shown in the examples below. See what attributes are included when this module is activated.

Kotlin
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_environment"
            ),
            moduleConfigurations = arrayOf( 
                 // Detects slow or frozen rendering frames.
                // isEnabled = true to enable detection.
                // interval sets the frame detection interval.
                SlowRenderingModuleConfiguration(
                    isEnabled = true,
                    interval = Duration.ofMillis(500)
                )
            )
        )
    }
}
Java
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        SplunkRum agent = SplunkRum.install(
            this,
            new AgentConfiguration(
                new EndpointConfiguration(
                    "your_splunk_realm",
                    "your_splunk_rum_access_token"
                ),
                "your_app_name",
                "your_deployment_environment"
            ),

            // Detects slow or frozen rendering frames.
            new SlowRenderingModuleConfiguration(true, Duration.ofMillis(500))
        );
    }
}

Interaction detection module

Interaction detection is enabled by default. You can deactivate it by setting the isEnabled parameter as in the examples below.

Kotlin
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_environment"
            ),
            moduleConfigurations = arrayOf( 
                // Tracks user interactions.
                // isEnabled = false to disable interaction tracking.
                InteractionsModuleConfiguration(
                    isEnabled = false
                )
            )
        )
    }
}
Java
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        SplunkRum agent = SplunkRum.install(
            this,
            new AgentConfiguration(
                new EndpointConfiguration(
                    "your_splunk_realm",
                    "your_splunk_rum_access_token"
                ),
                "your_app_name",
                "your_deployment_environment"
            ),

            // Disable user interactions.
            new InteractionsModuleConfiguration(false),
        );
    }
}

Application lifecycle monitoring module

The application lifecycle monitoring module is included in the new Splunk RUM agent and is activated by default. To deactivate application lifecycle monitoring, see examples below.

Tip: See the activity lifecycle and fragment lifecycle attributes that are included when this module is activated.
Kotlin
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_environment"
            ),
            moduleConfigurations = arrayOf( 
                // Reports application crashes
                // isEnabled = false to disable application lifecycle detection
                ApplicationLifecycleModuleConfiguration(
                    isEnabled = false
                )
            )
        )
    }
}
Java
class App : Application() {

    override fun onCreate() {
        super.onCreate()

        val agent = SplunkRum.install(
            application = this,
            agentConfiguration = AgentConfiguration(
                endpoint = EndpointConfiguration(
                    realm = "your_splunk_realm",
                    rumAccessToken = "your_splunk_rum_access_token"
                ),
                appName = "your_app_name",
                deploymentEnvironment = "your_deployment_environment"
            ),
            moduleConfigurations = arrayOf( 
                // Reports application crashes
                // isEnabled = false to disable application lifecycle detection
                ApplicationLifecycleModuleConfiguration(
                    isEnabled = false
                )
            )
        )
    }
}