The Mobile RUM SDK provides a customizable suite of tools to analyze and optimize the performance of Android applications. Isolate ANR and network changes, quickly detect application crashes, identify slow or frozen frames and more.

To see an example of how to deploy the Mobile RUM Android SDK, navigate to our GitHub repository here.

Prerequisites

Android SDK Version 21 or above. Check your Android SDK version with the following command:

Shell
./sdkmanager --list

Install & Instrument Your Android Application

Step 1: Install Middleware Android SDK

Java
implementation 'io.middleware.android:sdk:+'

Step 2: Add Application Instrumentation Config

To modify your configuration methods, navigate to the Configuration Methods section
Java
class MyApplication extends Application {
  private final String targetUrl = "<target-url>";
  private final String rumAccessToken = "<your-access-token>";

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

    Middleware.builder()
        .setTarget(targetUrl)
        .setServiceName("sample-android-app-1")
        .setProjectName("Mobile-SDK-Android")
        .setRumAccessToken(rumAccessToken)
        .setSlowRenderingDetectionPollInterval(Duration.ofMillis(1000))
        .setDeploymentEnvironment("PROD")
        .build(this);
  }
}

Step 2a: Configuration Methods [Optional]

Understand the behavior of your RUM Android application with the following methods and set particular attributes related to telemetry ingestion, monitoring, and instrumentation.

MethodDescription
setRumAccessToken(String)Authorizes client to send telemetry to Middleware
setTarget(String)Sets target URL to recieve telemetry
setService(String)Sets service name of your application
setDeploymentEnvironment(String)Sets environment attribute on spans generated by instrumentation. Example: PROD, DEV
disableCrashReporting()Disables crash reporting which is enabled by default
disableAnrDetection()Disables Application Not Responding (ANR) detection which is enabled by default
disableNetworkMonitor()Disables network change detection which is enabled by default
disableSlowRenderingDetection()Disables slow or frozen frame render detection which is enabled by default
setSlowRenderingDetectionPollInterval(Duration)Sets default polling for slow or frozen render detection. Default detection interval is 1000 milliseconds

Step 3: HTTP Instrumentation Config [Optional]

Integrate with OkHTTP3 to monitor HTTP events across user devices.

OkHTTP3
private Call.Factory buildOkHttpClient(Middleware middleware) {
  return middleware.createRumOkHttpCallFactory(new OkHttpClient());
}

Custom Configurations

Set Global Attributes

Global attributes serve as metadata or contextual information that can be attached to telemetry, traces, or logs collected by the instrumentation framework or SDK. They are key-value pairs that provide additional details about the application, device, user session, or environment.

Set the following Global Attributes to instrument your application:

Java
Middleware.builder()
        .setGlobalAttributes(
            Attributes.builder()
                    .put("key", "value")
                    .put(StandardAttributes.APP_VERSION, BuildConfig.VERSION_NAME)
                    .build());

Events

Step 1: Setup Your Custom Event

Send custom events and workflows using addEvent

Java
Middleware.getInstance().addEvent("You clicked on Button", BUTTON_ATTRIBUES);

Step 2: Start Custom Event Workflow

Start custom events and workflows using startWorkflow

Java
Span loginWorkflow = Middleware.getInstance().startWorkflow("User Login Flow");

Step 3: End Custom Event Workflow

End custom events and workflows using end

Java
loginWorkflow.end();

Error Reporting

Use addException(Throwable) to report exceptions, errors, and display messages on the Middleware dashboard

Java
Middleware.getInstance().addException(new RuntimeException("Something went wrong!"), Attributes.empty())

Logs

Add custom logs to display on your Middleware dashboard such as debug, error, warning, and info

Java
Middleware logInstance = Middleware.getInstance();
logInstance.d("TAG", "I am debug");
logInstance.e("TAG", "I am error");
logInstance.i("TAG", "I am info");
logInstance.w("TAG", "I am warning");

Session Replay

Control how you capture and replay your users’ browsing experience. To start and stop session replay, override the onResume and onPause methods.

This feature is only available for Android Version 8.0 (Android Oreo) or higher
Java
  final MiddlewareRecorder recorder = Middleware.getInstance().getRecorder();

  @RequiresApi(api = Build.VERSION_CODES.N)
  @Override
  protected void onResume() {
      super.onResume();
      recorder.startRecording(this);
  }

  @RequiresApi(api = Build.VERSION_CODES.N)
  @Override
  protected void onPause() {
      super.onPause();
      recorder.stopRecording();
  }

Session Recording

The maximum session recording duration is four hours. If users are inactive for more than 15 minutes at a time, session recordings will be stopped. If users exceed more than four hours in a single session or become active again after the 15-minute inactivity timeout, a new session will be automatically created.

Session recording is enabled by default. Disable this feature with the following function:

Java
.disableSessionRecording()

Privacy

Blur sensitive information in session recordings by embedding the following method:

User passwords are automatically masked by default. Other sensitive information like credit card data and API keys must be masked manually.
Java
final Middleware instance = Middleware.getInstance();
final TextView someTextView = findViewById(R.id.some_text_view);
instance.addSanitizedElement(someTextView);

Default Attributes

The following Attributes are provided by the Android SDK by default:

NameTypeDescription
project.name , appStringDefines the project name, used as projectName(String)
service.nameStringDefines the service name, used as serviceName(String)
session.idStringRandom session identifier generated by Middleware SDK
rum.sdk.versionStringMiddleware SDK version

Resource Attributes

The following Resource Attributes are applied to all spans by default:

NameTypeDescription
deployment.environmentStringName of deployment environment. Example: DEV, PROD
device.model.identifierStringDevice model identifier. Example: Moto-G30
device.model.nameStringName of device. Example: ONEPLUS A600
device.manufacturerStringName of device manufacturer. Example: OnePlus
os.nameStringName of operating system. Sets to Android
os.descriptionStringOperating System description. Example: Android Version 11 (Build RKQ1.201217.002 API level 30)
os.typeStringOperating System type. Sets to Linux
os.versionStringOperating System version. Example: Android version 11

Instrumentation Attributes

The following Instrumentation Attributes are additional properties the Android SDK provides:

Need assistance or want to learn more about Middleware? Contact us at support[at]middleware.io.