Konsola git

Disable Firebase Performance Monitoring

During app development and testing, you might find it useful to disable Performance Monitoring.

For example, by disabling Performance Monitoring during your app build process, you can:

  • Disable certain functionalities of Performance Monitoring (such as those provided by the Performance Monitoring Gradle plugin) in your debug builds, but re-enable the functionalities for your release build.

  • Disable Performance Monitoring when building your app, but allow your app to re-enable it at runtime.

  • Disable Performance Monitoring when building your app, and do not allow your app to re-enable it at runtime.

You can also build your app with Performance Monitoring enabled, but use Firebase Remote Config to give you flexibility to disable (and re-enable) Performance Monitoring in your production app. With this option, you can even configure your app to let users opt-in or opt-out of using Performance Monitoring.

Disable Performance Monitoring during your app build process

You can disable Performance Monitoring during your build process by disabling the Performance Monitoring Gradle plugin and/or by disabling the Performance Monitoring Android library.

During development and debugging, disabling the plugin is useful because instrumentation by the plugin can contribute to increased build time. You might, though, consider keeping the library enabled so that you can still view performance data from automatic duration traces and any custom traces in your app.

Disable the Performance Monitoring Gradle Plugin

You can disable the Performance Monitoring plugin by adding an instrumentationEnabled flag using the following options:

Disable the plugin via an Extension Property flag

By using an Extensions Property flag, you can disable the Performance Monitoring plugin for a specific build variant at compile time.

  1. In your root-level (project-level) build.gradle file, make sure your Android Gradle Plugin dependency is specified as v3.4.0 or later.

    For earlier versions of the Android Gradle Plugin, you can still disable the Performance Monitoring plugin for a specific build variant, but the build time contribution for that variant won’t be completely eliminated.

  2. Add the following flag to your module (app-level) build.gradle file, then set it to false to disable the Performance Monitoring plugin.

    android {
      // ...
      buildTypes {
        debug {
          FirebasePerformance {
            // Set this flag to 'false' to disable @AddTrace annotation processing and
            // automatic HTTP/S network request monitoring
            // for a specific build variant at compile time.
            instrumentationEnabled false
          }
        }
      }
    }
    

Disable the plugin via a Project Property flag

By using a Project Property flag, you can disable the Performance Monitoring plugin for all build variants at compile time.

Add the following flag to your gradle.properties file, then set it to false to disable the Performance Monitoring plugin.

// ...

// Set this flag to 'false' to disable @AddTrace annotation processing and
// automatic HTTP/S network request monitoring
// for all build variants at compile time.
firebasePerformanceInstrumentationEnabled=false

Disable the Performance Monitoring Android library

If you disable the Performance Monitoring library at compile time, you can choose whether to allow your app to enable the library at runtime.

Disable the library at compile time, but allow your app to enable it at runtime

Add the following <meta-data> element to your app’s AndroidManifest.xml file:

  <application>
    <meta-data
      android:name="firebase_performance_collection_enabled"
      android:value="false" />
  </application>

Disable the library at compile time, but do not allow your app to enable it at runtime

Add the following <meta-data> element to your app’s AndroidManifest.xml file:

  <application>
    <meta-data
      android:name="firebase_performance_collection_deactivated"
      android:value="true" />
  </application>

Disable your app at runtime using Remote Config

Firebase Remote Config lets you make changes to the behavior and appearance of your app, so it provides an ideal way to let you disable Performance Monitoring in deployed instances of your app.

To disable Performance Monitoring data collection the next time that your Android app starts, use the example code shown below. For more information about using Remote Config in an Android app, see Use Firebase Remote Config on Android.

  1. Ensure that Remote Config is in the dependencies section of your module Gradle file (usually app/build.gradle):

    implementation 'com.google.firebase:firebase-config:19.0.2'
    
  2. Set up Remote Config and disable Performance Monitoring if perf_disable is set to true:

    Java

    // Setup remote config
    FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
    
    // You can uncomment the following two statements to permit more fetches when
    // validating your app, but you should comment out or delete these lines before
    // distributing your app in production.
    // FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
    //       .setDeveloperModeEnabled(BuildConfig.DEBUG)
    //       .build();
    // mFirebaseRemoteConfig.setConfigSettings(configSettings);
    // Load in-app defaults from an XML file that sets perf_disable to false until you update
    // values in the Firebase Console
    
    //Observe the remote config parameter "perf_disable" and disable Performance Monitoring if true
    config.setDefaults(R.xml.remote_config_defaults);
    if (config.getBoolean("perf_disable")) {
        FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false);
    } else {
        FirebasePerformance.getInstance().setPerformanceCollectionEnabled(true);
    }

    Kotlin

    // Setup remote config
    val config = FirebaseRemoteConfig.getInstance()
    
    // You can uncomment the following two statements to permit more fetches when
    // validating your app, but you should comment out or delete these lines before
    // distributing your app in production.
    // FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
    //       .setDeveloperModeEnabled(BuildConfig.DEBUG)
    //       .build();
    // mFirebaseRemoteConfig.setConfigSettings(configSettings);
    // Load in-app defaults from an XML file that sets perf_disable to false until you update
    // values in the Firebase Console
    
    // Observe the remote config parameter "perf_disable" and disable Performance Monitoring if true
    config.setDefaults(R.xml.remote_config_defaults)
    FirebasePerformance.getInstance().isPerformanceCollectionEnabled = !config.getBoolean("perf_disable")
  3. Add the following code to MainActivity.java to fetch and activate Remote Config values:

    Java

    //Remote Config fetches and activates parameter values from the service
    final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance();
    config.fetch(3600)
            .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        config.activateFetched();
                    } else {
                        // ...
                    }
                }
            });

    Kotlin

    // Remote Config fetches and activates parameter values from the service
    val config = FirebaseRemoteConfig.getInstance()
    config.fetch(3600)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    config.activateFetched()
                } else {
                    // ...
                }
            }
  4. To disable Performance Monitoring in the Firebase console, create a perf_disable parameter in your app's project, then set its value to true.

    This change will make calls to the Performance Monitoring SDK "no operation" calls (NOOPs), eliminating any significant effects on app performance from using the Performance Monitoring SDK in your app.

    If you set the value of perf_disable to false, Performance Monitoring remains enabled.