Firebase Performance Monitoring for Android

Waiting for things to load is part of everyone’s mobile app experience.But it’s never a good experience for your user and how would you even know what the experience is? Your user is on a wide variety of devices, in a wide variety of networks, in a wide variety of locations all over the world.If you want to optimize the performance of your app, you metrics that tell you exactly what’s happening during the critical moments of your app’s use.You need that information to come directly from users.Now, You can get using Firebase Performance Monitoring.By integrating the SDK into your app, and without writing any code, your performance dashboard in the Firebase console will collect information about your app’s performance, as seen by your users.You’ll get data about your app’s startup time and details about its HTTP transactions.Using the provided API, you can instrument your app to measure those critical moments that you want to understand and improve.Then, in the dashboard, you can break down the data by Country, Version, Device, OS, Radio, Carrier, MIME type.

Install Firebase SDK in APP

This guide shows you how to use Firebase Performance Monitoring with your app.

1 Prerequisites

You need a few things set up in your environment:

  • A device running Android 4.0 +, and Google Play services 11.0.4 +
  • The Google Play services SDK from the Google Repository, available in the Android SDK Manager
  • The latest version of Android Studio 2.2+

2 Add Firebase to your Android project

Add Firebase to your app from Android Studio using the Firebase Assistant.To open the Firebase Assistant in Android Studio:

  1. Click Tools > Firebase to open the Assistant window.
  2. Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
  3. Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.

Firebase Performance Monitor

3 Add Performance Monitoring to your app

  • Add the following dependencies project-level build.gradle :

Add the following dependencies app-level build.gradle :

  1. Below apply plugin: '', add the following line:
  2. Add the following to the dependencies section:
  3. If your app uses other Firebase SDKs, you should also change the version to 11.0.4 for those SDKs.


Recompile your app. Automatic traces and HTTP/S network requests are now monitored.

If you just install the SDK, you still get a few out-of-the box traces, the most important one being app start.This is the time between the app code start loading until the app is responsive to the user.Firebase also has a trace that monitors the foreground session so anytime the app is available to the user.and we do the same for the background as well.

Performance issues that can impact you as a developer falls under one of two buckets.The first one has to do with your app code performance.

So this is a thing like what kind of delays your user see as they interact with the app, or how much frame drops they see in the animation to monitor that Firebase built feature called Traces.

The other category of issues is about network activity between your app and the backends that it uses for that Firebase monitor network requests.


The easiest way to define a trace is its performance report between two points in your app.Imagine you have a record button and a stop button, and in between those two points you just pick up metrics, So these two points can be anything in your app, anything that you care about and you think is worth monitoring.So it could be something like the time between the user taps on one of the shoes until they see the full product details page.It could be as fine grained as a database fetch to get a piece of string and put it on the screen or it could be as long as the full checkout flow.

All you need to do is create a trace name or a trace object, give it a name, start it and stop it.That name you give it becomes your context.

Add the @AddTrace annotation to trace specific methods

You can add the @AddTrace annotation to methods in your app and provide a string to identify the resulting trace. This causes a trace to start at the beginning of this method, and to stop when the method completes. Traces created in this way do not have counters available.

Trace Metrics

In terms of metrics, by default you get the trace duration, so how much time took place between the start from the stop.So essentially, you can use it a time.But it’s actually more than that because you can attach custom metrics using counter API.which you see an example of here.So here think any example of countable events that are relevant to your performance how many times you called the local disk, how many times you called the GPS, how many times you dropped a frame, how many times you made a network call, and so on.


Any one of these events you can just give it a name, You can count it increment it and we’ll tally up those events and report them as custom metrics attached to your trace.

Network Monitor

An HTTP/S network request is a report that captures the time between when your app issues a request to a service endpoint and when the response from that endpoint is complete. For any endpoint that your app makes a request to, the SDK will capture several metrics:

  • Response time: Time between when the request is made and when the response is fully received
  • Payload size: Byte size of the network payload downloaded and uploaded by the app
  • Success rate: Percentage of successful responses compared to total responses (to measure network or server failures)


Disable the Firebase Performance Monitoring SDK

You can disable the Performance Monitoring SDK when building your app with the option to re-enable it at runtime, or build your app with Performance Monitoring enabled and then have the option to disable it at runtime using Firebase Remote Config. You can also completely deactivate Performance Monitoring, with no option to enable it at runtime.

Disable during your app build process

Disabling Performance Monitoring during your app build process could be useful is to avoid reporting performance data from a pre-release version of your app during app development and testing.

Add the following property to your app’s file to disable automatic traces and HTTP/S network request monitoring (but not custom traces) at build time:

Changing this property to true re-enables automatic traces and HTTP/S network request monitoring.

Allow your app to enable it at runtime, by adding a <meta-data> element to the <application> element of your app’s AndroidManifest.xml file, as follows:

To completely deactivate Performance Monitoring with no option to enable it at runtime, add a <meta-data>element to the <application> element of your app’s AndroidManifest.xml file, as follows:


Related Post

Phone Number Authentication with Firebase Auth


Memory Leak


Leave a Reply

Your email address will not be published. Required fields are marked *