Splunk MINT SDK for Android

Splunk MINT SDK for Android Developer Guide

Download manual as PDF

Download topic as PDF

Generate network events with an OkHTTP Interceptor

For apps that use the MINT OkHTTP client library, you can use the MINT OkHTTP Interceptor to generate network events. This is useful if automatic network instrumentation for the Android SDK fails to successfully generate network events.

When you use the OkHTTP Interceptor, be sure not to use another instrumentation method.

What you need to use the MINT OkHTTP Interceptor

Before continuing, ensure that:

  • You have installed OkHTTP 3.12.1 and are using the OkHTTP library to issue network requests for your app.
  • Your app uses the Retrofit 2 library.

Steps

Follow these steps to use the MINT OkHTTP Interceptor to generate network events.

1. Install the Android SDK

Install the Android SDK with the Maven repository structure. If you already installed the Android SDK, but did not include the Maven repository structure, you must reinstall the Android SDK with the Maven repository structure.

  1. Download the MINT plug-in repository (mint-android-repo-5.2.5.zip).
  2. Unzip the MINT plug-in repository in your mobile app project at the app level. Do not place the repository in the /libs folder.

For more information about installing the Android SDK, see Requirements and installation for Android.

2. Modify the build.gradle file to include the OkHTTP Interceptor

Modify the build.gradle file to include the OkHTTP Interceptor in your app's build:

repositories {
    ...
    maven {
        url uri('mint-plugin-repo-5.2.5')
    }
}

dependencies {
    ....
    implementation 'com.splunk:mint-android-hook-okhttp:5.2.5'
}

3. Add the OkHTTP Interceptor to your app

Add this code snippet to your app's code:

...
import com.splunk.mint.hook.OkHttpInterceptor;
...

OkHttpClient okhttpClient = new OkHttpClient.Builder()
                        .addInterceptor(new OkHttpInterceptor())
                        .build();

//if you are using Retrofit2 library:
...
Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_API_URL)
            .client(okhttpClient)
...
            .build();

4. Disable automatic network instrumentation and initialize the Android SDK

Because the MINT OkHTTP Interceptor will handle network events, you need to disable the default automatic network instrumentation before using the Android SDK.

If you are using the MINT Data Collector, call these methods:

Mint.disableNetworkMonitoring();
Mint.initAndStartSession(this.getApplication(), "YOUR_API_KEY");

If you are using the HEC, call these methods:

Mint.disableNetworkMonitoring();
Mint.initAndStartSessionHEC(this.getApplication(), "HEC_MINT_endpoint_URL", "YOUR_HEC_TOKEN");

For more information about disabling automatic network instrumentation, see Disable network monitoring.

For more information about initializing the Android SDK, see Add Splunk MINT to your Android project.

PREVIOUS
Integrate WebView monitoring
  NEXT
Java code example

This documentation applies to the following versions of Splunk MINT SDK for Android: 5.2.x


Was this documentation topic helpful?

Enter your email address, and someone from the documentation team will respond to you:

Please provide your comments here. Ask a question or make a suggestion.

You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters