Blog

Mobile SLOs with EDOT Android: Crash-free sessions and ANRs in Elastic Observability

A phone has one user, so the numbers that tell you a backend is healthy tell you almost nothing about an app. Crash-free session rate, ANR rate and screen latency at p95 do, and EDOT Android reports all three, though ANRs arrive one launch late.

Elastic speaks OpenTelemetry natively. Send traces, logs, and metrics over OTLP straight into Elasticsearch, no proprietary agents required. See how it fits together, try it for free in the cloud, or run it locally.

One tap on an Android screen produces four spans across two services, and they all land in the same trace in the same cluster. Three Gradle plugins get you there.

Elastic Distribution of OpenTelemetry (EDOT) Android sends spans and crashes, along with session IDs, to the Elastic Managed OpenTelemetry Protocol (mOTLP) endpoint, which puts them beside your existing service telemetry. Crash-free session rate and screen latency stop being numbers that you check on a separate console once a week and become error-budget signals that you can alert on. Application Not Responding (ANR) errors need one more step, since Android only reports them on the launch after they happen.  We’ll cover that later in this blog post.

There are also the questions of why mobile telemetry belongs in the same cluster as your back end at all and what EDOT Android adds over the upstream OpenTelemetry (OTel) SDK, as well as how the prebuilt Kibana dashboards hold up against one you build yourself.

For the tasks we cover in this post, you need an Elastic cluster and enough familiarity with Kibana to find your way around. You can create a new account for Elastic Cloud; the hosted mOTLP endpoint runs on Elastic Cloud only, so self-hosted clusters are out.

Why mobile telemetry belongs in the same cluster as your back end

Elastic offers a complete suite of observability for enterprises and teams of all sizes. Elastic can collect operational data, such as metrics, logs, traces, and more insights, from the platforms. As shown in the diagram below, we’re using the Elastic mOTLP endpoint:

Figure 1: Combining the backend telemetry and the mobile telemetry allows operations teams to preview the complete picture of the interactions, user journeys, and experiences.

Although Elastic supports cross-cluster search and view, it’s often better and simpler to ingest the data in the same cluster. 

I recommend taking a look at how data streams optimize the data ingestion for append-only time series data.

What SLOs should you set for a mobile app?

As your business expands into the mobile space, your site reliability engineering (SRE) practices and skills can also be applied to mobile markets and platforms. For new entrants to the mobile market, it’s important to provide the same experience on mobile devices as you provide on web platforms. A site reliability engineer (SRE) looks at:

  • Monitors, to track the traceability of the requests and metrics of the performance, as well as any logs from the services. 

  • Service Level Indicators (SLIs) and Service Level Objectives (SLOs), along with (potentially) Service Level Agreements (SLAs). 

    • SLA is a legal / business term that’s often skipped on the technical side of SRE. 

    • Common practice has SREs focusing primarily on the SLOs.

  • Detecting and handling incidents, in addition to preventing them. 

Your mobile apps are deployed on phones and isolated from other devices. Your SRE team is looking for the impact of network coverage on the action that your customer is trying to take, rather than for stress on a single device or the network service coverage alone. . For example, the mobile SRE is interested in knowing which sessions are more likely to finish a purchase and what device and app scenarios help them complete the purchase. Your SRE may have an SLO to ensure that the OrderActivity page:

  • Never lags or gets stuck because of poor network connectivity.

  • Never crashes because of a bug in state, user input, or server outage.

  • Always tracks the interactions that a user is performing on the page. 

If you already have the observability and reporting data from your backend services, you’re likely halfway there. You only need to enrich the service-side analytics with the mobile-side reporting to know the full picture. 

Because the data lives in the same cluster, your Kibana dashboards can report the overall performance of the requests with spans and traces. In the figure below, the trace shows the single interaction from the user’s device’s screen, all the way to the execution: 

  • The interaction starts with the task.create (a tap on the screen).

  • The app sends a POST request to the backend server to create a new task. 

  • The HTTP request (which is out of the mobile app’s control and is part of the web app) runs through completion. 

  • The simulated web app internals mimic the task creation.

Since we’re using the same cluster for mobile app instrumentation and sending our backend OTel signals, we get a complete picture of the event. We can see which segments take the most time and where the biggest bottleneck is:

Figure 2: The tracing of the request and events (spans) shows the complete picture of the interaction of our users with the application.

Instrumenting your Android app with EDOT

EDOT Android versus the upstream OTel SDK

Elastic clusters work natively with the OTel SDKs. Elastic is also among the contributors and supporters of the open source (also known as upstream) OTel SDKs. 

Although you can use either the OTel SDK or EDOT for Android, both can transmit the data to the Elastic cluster. However, the integration of EDOT is straightforward for Elastic clusters. EDOT is preconfigured for Elastic Observability but also offers default standards and better developer experience. For example, EDOT supports R8 mapping uploads so that obfuscated stack traces are readable in Kibana. 

For a complete list of features available in both, check out the comparison reference. 

In this scenario, I ran a demo Android app (the friendly “todos” app). Its goal is to transmit the events and telemetry. After the data is on the Elastic cluster and the Android OTel Assets package is installed, the dashboards start to show the insights. Set the time range so it covers your test run.

Adding the EDOT Android Gradle plugins

You can find the configuration steps in the Android app folder itself, but the following snippet shows how to set up the instrumentation for your Android apps: 

// app/build.gradle.kts
plugins {
    id("com.android.application")
    id("co.elastic.otel.android.agent") version "1.11.0"
    id("co.elastic.otel.android.instrumentation.okhttp") version "1.11.0"
    id("co.elastic.otel.android.instrumentation.crash") version "1.11.0"
}

Note that the crash plugin is optional. It reports the crashes as log events with the session ID and the stack trace. Without it, the dashboards have no crash events to count. Together with the OkHttp plugin, these are the automatic instrumentations that EDOT Android provides.

Then, inside the Application.onCreate method, add:

class DemoApp : Application() {
    override fun onCreate() {
        super.onCreate()
        val agent = ElasticApmAgent.builder(this)
            .setServiceName("mobile-demo-android")
            .setServiceVersion(BuildConfig.VERSION_NAME)
            .setExportUrl(BuildConfig.OTLP_ENDPOINT)
            .setExportAuthentication(Authentication.ApiKey(BuildConfig.OTLP_API_KEY))
            .build()
    }
}

After the agent is running, you can create spans anywhere in the app. A small helper keeps the call sites short:

// agent is the ElasticApmAgent returned by build() above
val tracer = agent.getOpenTelemetry().getTracer("dev.edotdemo.app")

fun <T> action(name: String, block: () -> T): T {
    val span = tracer.spanBuilder(name).startSpan()
    val scope = span.makeCurrent()          // HTTP spans created inside become children
    try {
        return block()
    } catch (e: Throwable) {
        span.recordException(e)
        span.setStatus(StatusCode.ERROR, e.message ?: e.javaClass.simpleName)
        throw e
    } finally {
        scope.close()
        span.end()
    }
}

// Usage: the okhttp span for the sync call is nested under "sync"
action("sync") { api.sync(user) }

makeCurrent() links the tap to the network call. The EDOT SDK for Android configures most of the settings for you. Review the docs to learn the complete details of what’s done for you and what you need to provide.

Installing the Android OTel Assets dashboards in Kibana

Kibana gives you two ways to see the telemetry that your Android app is now sending. The first is the official integration that’s available in Elastic cluster. You can install the packages (for example, Android OpenTelemetry Assets) directly via the Integrations tab in Kibana (/app/integrations) or by visiting the documentation page for each integration, such as the Android OpenTelemetry Assets. 

Figure 3: [Android OTel] Exception Details is an Elastic managed dashboard that works well with EDOT to show you critical details.

This dashboard comes from the Android OpenTelemetry Assets content package. Once your app has sent the data, and you have the package installed, Kibana adds the [Android OTel] Application Overview and [Android OTel] Exception Details dashboards. The dashboards query logs-generic.otel* and traces-generic.otel* data for os.name: "Android"; they aren’t tied to EDOT. They populate as soon as the expected fields (such as session.id, service.name, and the exception.* fields) arrive. EDOT Android sets all these for you. If you use another OTel Android SDK, you can supply them yourself. 

While this dashboard is managed by Elastic, you can create a copy of the dashboard to customize it.

We want to go one step further and we want to create a custom dashboard that gives us a better view of what is happening in our mobile app, how the customers are creating sessions and using the app, along with different stages of the application. 

Building a crash-free sessions dashboard in Kibana

Building your own dashboards lets you report on whatever your operations team actually asks for. Kibana offers you the ability to create dashboards using the data that you have indexed. Once you have the data indices, you can use them in the Kibana dashboards to generate charts and graphs for any reporting. My favorite approach to creating the dashboards is with the Elastic AI Agent in the Elastic Cloud (Elastic Serverless and Elastic Stack 9.4.+).

Figure 4: The “New Dashboard” window that shows the AI Agent sidebar open. The AI Agent uses Elastic’s hosted inference service.

The following video shows a custom dashboard generation using the Elastic’s hosted inference service.

Video Thumbnail

You can have a conversation with the AI Agent, and it pulls the insights from your cluster to suggest the dashboards, visualizations, and the data to report on. You are, of course, always in charge. I wanted to create a dashboard that translates the user journeys and user interactions into insights for the operations teams

  • How many times the app was installed (app.installation.id) or how many sessions (session.id) were created and managed. 

  • How many sessions were crash-free, determined by correlating session ID with crash events (app.crash) in the time duration. (See Automatic instrumentation for the Android apps with EDOT SDK.)

  • How the customers experience the app in terms of performance, including “app not responding” (ANR) events.

Does EDOT Android detect ANRs automatically?

EDOT Android doesn’t automatically detect “apps not responding” automatically. The automatic instrumentation covers OkHttp and crash reporting. In the demo app, I read Android’s ApplicationExitInfo on the next launch (Android 11+) and send an app.anr_previous_run event. So an ANR shows up one launch late.

Just like a slow-performing web page has a degraded impact on your commerce economics, ANRs impact the customer journey in apps. To preview this, I asked the AI Agent to build this dashboard for me: 

Figure 5: A preview of the custom dashboard to detect the impact of the degraded performance on the demo to-do app.

The dashboard expands the reporting and also keeps crashes, performance, page launches, transitions, and user interactions in the reports. In our use case, we have telemetry from the backend service (which holds the tasks) and the mobile front end. The differentiation of telemetry is important, as it’s used to build dashboards and bring clarity to SRE operations.

The mobile telemetry (or mobile-specific telemetry) is telemetry collected from the app and focuses on user interactions with the app, but also on native platform-specific calls; for example:

  • GET/POST calls from the mobile (because these calls are made from the mobile device).

  • Screen, page, or UI control-specific telemetry (task.create, screen.view, etc.).

  • Application-specific tracing and telemetry, such as how long the app was in foreground, sessions, etc.

We also have telemetry that is not mobile-specific such as:

  • HTTP handlers and their traces.

  • Internal database and resource handlers.

Backend telemetry matters just as much as  

Kibana goes beyond and allows us to generate custom dashboards based on the data from our telemetry. We can create any dashboard that our operations and business teams need. 

Figure 6: Group together custom dashboards from the instrumented telemetry in Kibana.

If you don’t have these insights, your teams would need to extract these insights from different resources. The information can be gathered from mobile platforms, such as Google Play Store, Firebase, or other analytics and reporting platforms. But you miss out on two things:

  1. The data ingested on other platforms, while can also be ingested on Elastic, is not standardized according to your Elastic cluster defaults, and it is not related to the traces and sessions information generated and produced by your backend services. 

  2. The platforms maintain a custom structure to the logs, so to generate a big-picture view of the reporting, you always need to translate the source data to a normalized view. 

But if you ingest the data to Elastic cluster together with the back end, you can start looking at the big-picture view on your product in minutes. 

Conclusion: Mobile observability changes what latency and load mean

In this article, we explored what it means to have observability in your mobile applications. The typical concepts of latency, load,  a reason to use asynchronous code on mobile apps to keep the app UI responsive. 

Figure 7: The observability and traces don’t have to leave out your mobile apps and platforms. You can start the journey from the user’s screens and interactions to check your platform’s impact on customer experience.

With Elastic, you can identify which user sessions are facing problems by merging and enriching the data from backend systems and the mobile platforms. 

You can use the official Android OTel integration in Elastic to install ready-made dashboards that automatically use the data ingested by the OpenTelemetry SDK for Android to build the dashboard for you. We’d also appreciate your feedback on this article via our Discuss, or happy to continue the conversation over at X @afzaalvirgoboy.

How helpful was this content?

Related Content

Meet the new Elastic Streams: Managed data pipelines for telemetry

Meet the new Elastic Streams: Managed data pipelines for telemetry

Marcin Stożek
From a checkout alert to the failing span: Investigating with the Elastic AI Agent and Elastic APM flyouts

From a checkout alert to the failing span: Investigating with the Elastic AI Agent and Elastic APM flyouts

Costas Pipilas
Two changes to the OpenTelemetry Kafka receiver that stop one slow tenant stalling the rest

Two changes to the OpenTelemetry Kafka receiver that stop one slow tenant stalling the rest

Constanca Manteigas

Elastic Observability Labs Newsletter