- Access to OpenTelemetry APIs
- OkHttp3 instrumentation for monitoring HTTP events
- Middleware APIs for sending custom events & recording exceptions
- Slow / Freeze render detection
- Custom logging
- Network Change Detection
- ANR Detection
- Crash Reporting
- Android Activity & Fragment lifecycle events
- Android Minimum SDK Version : 21
Before using the Middleware Android SDK, ensure you have:
An account with Middleware to obtain the RUM (Real User Monitoring) access token and target URL. Visit installation docs section of Real-User-Monitoring from Middleware dashboard.
- Create New Application
- Obtain the accountKey & target once application is created.
The Middleware Android SDK provides instrumentation for monitoring various aspects of your Android application. With this SDK, you can track and analyze the features listed above, viewing the results in the Middleware RUM section and RUM dashboard.
implementation 'io.github.middleware-labs:android-sdk:+'
class MiddlewareApplication extends Application {
private final String targetUrl = "<target-url>";
private final String rumAccessToken = "<your-access-token>";
@Override
public void onCreate() {
super.onCreate();
Middleware.builder()
.setGlobalAttributes(Attributes.of(APP_VERSION, BuildConfig.VERSION_NAME))
.setTarget(targetUrl)
.setServiceName("sample-android-app-1")
.setProjectName("Mobile-SDK-Android")
.setRumAccessToken(rumAccessToken)
.setSlowRenderingDetectionPollInterval(Duration.ofMillis(1000))
.setDeploymentEnvironment("PROD")
.build(this);
}
Methods that can be used for setting instrumentation & configure your application.
Option | Description |
setRumAccessToken(String)
|
Sets the RUM account access token to authorize client to send telemetry data to Middleware |
setTarget(String)
|
Sets the target URL to which you want to send telemetry data. For example - https://app.middleware.io |
setService(String)
|
Sets the service name for your application. This can be used furthur for filtering by service name. |
setDeploymentEnvironment(String)
|
Sets the environment attribute on the spans that are generated by the instrumentation. For Example - PROD | DEV
|
disableCrashReporting()
|
Disable crash reporting. By default it is enabled. |
disableAnrDetection()
|
Disable Application Not Responding Detection. By default it is enabled. |
disableNetworkMonitor()
|
Disable network change detection. By default it is enabled. |
disableSlowRenderingDetection()
|
Disable slow or frozen frame renders. By default it is enabled. |
setSlowRenderingDetectionPollInterval(Duration)
|
Sets the default polling for slow or frozen render detection. Default value in milliseconds is 1000
|
private Call.Factory buildOkHttpClient(Middleware middleware) {
return middleware.createRumOkHttpCallFactory(new OkHttpClient());
}
Global attributes are key-value pairs that are used for attaching the global information for the reported data. These values can be useful for custom or user specific tags that can be attached while sending data to Middleware.
Middleware.builder()
.setGlobalAttributes(
Attributes.builder()
.put("key", "value")
.put(StandardAttributes.APP_VERSION, BuildConfig.VERSION_NAME)
.build());
You can also send custom events and workflows using addEvent
and
startWorkflow
APIs respectively
Middleware.getInstance().addEvent("You clicked on Button", BUTTON_ATTRIBUES);
Span loginWorkflow = Middleware.getInstance().startWorkflow("User Login Flow");
loginWorkflow.end();
You can report exceptions, errors and any messages using addException(Throwable)
We will show this
on our Middleware Dashboard.
Middleware.getInstance().addException(new RuntimeException("Something went wrong!"), Attributes.empty())
You can add custom logs such as debug, error, warn, info these logs will be shown on Middleware Logs Dashboard
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 warn");
By default session recording is enabled capture all activities. To disable session recording you can use .disableSessionRecording()
To blur sensitive information in session recording use the following method :
final Middleware instance = Middleware.getInstance();
final TextView someTextView = findViewById(R.id.some_text_view;
instance.addSanitizedElement(someTextView);