Disable the Firebase Performance Monitoring SDK

To let you users opt-in or opt-out of using Firebase Performance Monitoring, you might want to configure your app so that you can enable and disable Performance Monitoring. You might also find this capability to be useful during app development and testing.

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.

Performance Monitoring is currently in beta release.

Disable Performance Monitoring during your app build process

One situation where 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.

iOS

You can add one of two keys to the property list file (Info.plist) for your iOS app to disable or deactivate Performance Monitoring:

  • To disable Performance Monitoring, but allow your app to enable it at runtime, set firebase_performance_collection_enabled to true in your app's Info.plist file.
  • To completely deactivate Performance Monitoring with no option to enable it at runtime, set firebase_performance_collection_deactivated to true in your app's Info.plist file. This setting overrides the firebase_performance_collection_enabled setting and must be removed from your app's Info.plist file to re-enable Performance Monitoring.

Android

You can add the following property to your app's gradle.properties file to disable automatic traces and HTTP/S network request monitoring (but not custom traces) at build time:

firebasePerformanceInstrumentationEnabled=false

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

You can also disable Performance Monitoring at build time, but 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:

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

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:

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

Disable your app at runtime using Remote Config

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.

iOS

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

  1. Ensure that Remote Config is used in your Podfile: pod 'Firebase/RemoteConfig'
  2. Add the following to the top of your app's AppDelegate file:

    Swift

    import FirebaseRemoteConfig

    Objective-C

    @import FirebaseRemoteConfig;

  3. In your AppDelegate file, add the following code to the launchOptions statements in the application:didFinishLaunchingWithOptions: instance method:

    Swift

    remoteConfig = RemoteConfig.remoteConfig()
    // You can change the "false" below to "true" to permit more fetches when validating
    // your app, but you should change it back to "false" or remove this statement before
    // distributing your app in production.
    let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: false)
    remoteConfig.configSettings = remoteConfigSettings!
    // Load in-app defaults from a plist file that sets perf_disable to false until
    // you update values in the Firebase Console.
    remoteConfig.setDefaultsFromPlistFileName("RemoteConfigDefaults")
    // Important! This needs to be applied before FirebaseApp.configure()
    if !remoteConfig["perf_disable"].boolValue {
        // The following line disables automatic traces and HTTP/S network monitoring
        Performance.sharedInstance().isInstrumentationEnabled = false
        // The following line disables custom traces
        Performance.sharedInstance().isDataCollectionEnabled = false
    }
    else {
        Performance.sharedInstance().isInstrumentationEnabled = true
        Performance.sharedInstance().isDataCollectionEnabled = true
    }
    // Use Firebase library to configure APIs
    FirebaseApp.configure()
    

    Objective-C

    self.remoteConfig = [FIRRemoteConfig remoteConfig];
    // You can change the NO below to YES to permit more fetches when validating
    // your app, but you should change it back to NO or remove this statement before
    // distributing your app in production.
    FIRRemoteConfigSettings *remoteConfigSettings =
        [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:NO];
    self.remoteConfig.configSettings = remoteConfigSettings;
    // Load in-app defaults from a plist file that sets perf_disable to false until
    // you update values in the Firebase Console.
    [self.remoteConfig setDefaultsFromPlistFileName:@"RemoteConfigDefaults"];
    // Important! This needs to be applied before [FIRApp configure]
    if (!self.remoteConfig[@"perf_disable"].numberValue.boolValue) {
        // The following line disables automatic traces and HTTP/S network monitoring
        [FIRPerformance sharedInstance].instrumentationEnabled = NO;
        // The following line disables custom traces
        [FIRPerformance sharedInstance].dataCollectionEnabled = NO;
    }
    else {
        [FIRPerformance sharedInstance].instrumentationEnabled = YES;
        [FIRPerformance sharedInstance].dataCollectionEnabled = YES;
    }
    // Use Firebase library to configure APIs
    [FIRApp configure];
    

  4. In ViewController.m, or another implementation file used by your app, add the following code to fetch and activate Remote Config values:

    Swift

    //RemoteConfig fetch and activation in your app, shortly after startup
        remoteConfig.fetch(withExpirationDuration: TimeInterval(30.0)) { (status, error) -> Void in
          if status == .success {
            print("Config fetched!")
            self.remoteConfig.activateFetched()
          } else {
            print("Config not fetched")
            print("Error (error!.localizedDescription)")
          }
    }

    Objective-C

    //RemoteConfig fetch and activation in your app, shortly after startup
    [self.remoteConfig fetchWithExpirationDuration:30.0 completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) {
        if (status == FIRRemoteConfigFetchStatusSuccess) {
          NSLog(@"Config fetched!");
          [self.remoteConfig activateFetched];
        } else {
          NSLog(@"Config not fetched");
          NSLog(@"Error %@", error.localizedDescription);
        }
    }];

  5. To disable Performance Monitoring in the Firebase console, create a perf_disable parameter in your app's project, and then set its value to true. If you set the value of perf_disable to false, Performance Monitoring will remain enabled.

Disable automatic or manual data collection separately

You could make some changes to the code shown above and in the Firebase console to let you disable automatic data collection (app start traces and HTTP/S network requests) separately from manual data collection (custom traces). To do this, you would add the following code to the launchOptions statements in the application:didFinishLaunchingWithOptions: instance method, instead of what is shown in step 3 above:

Swift

remoteConfig = FIRRemoteConfig.remoteConfig()
let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: true)
remoteConfig.configSettings = remoteConfigSettings!
// Important! This needs to be applied before FirebaseApp.configure()
if !remoteConfig["perf_disable_auto"].boolValue {
    // The following line disables automatic traces and HTTP/S network monitoring
    Performance.sharedInstance().isInstrumentationEnabled = false
}
else {
    Performance.sharedInstance().isInstrumentationEnabled = true
}
if !remoteConfig["perf_disable_manual"].boolValue {
    // The following line disables custom traces
    Performance.sharedInstance().isDataCollectionEnabled = false
}
else {
    Performance.sharedInstance().isDataCollectionEnabled = true
}
// Use Firebase library to configure APIs
FirebaseApp.configure()

Objective-C

self.remoteConfig = [FIRRemoteConfig remoteConfig];
FIRRemoteConfigSettings *remoteConfigSettings =
    [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
self.remoteConfig.configSettings = remoteConfigSettings;
// Important! This needs to be applied before [FirebaseApp configure]
if (!self.remoteConfig[@"perf_disable_auto"].numberValue.boolValue) {
    // The following line disables automatic traces and HTTP/S network monitoring
    [FIRPerformance sharedInstance].instrumentationEnabled = NO;
}
else {
    [FIRPerformance sharedInstance].instrumentationEnabled = YES;
}
if (!self.remoteConfig[@"perf_disable_manual"].numberValue.boolValue) {
    // The following line disables custom traces
    [FIRPerformance sharedInstance].dataCollectionEnabled = NO;
}
else {
    [FIRPerformance sharedInstance].dataCollectionEnabled = YES;
}
// Use Firebase library to configure APIs
[FirebaseApp configure];

Then, do the following in the Firebase console:

  • To disable automatic traces and HTTP/S network monitoring, create a perf_disable_auto parameter in your app's project, and then set its value to true.
  • To disable custom traces, create a perf_disable_manual parameter in your app's project, and then set its value to true.

To enable either of these aspects of Performance Monitoring in your app, set the value of the corresponding parameter to false in the Firebase console.

Android

You can use the example code shown below to disable Performance Monitoring data collection the next time that your Android app starts. 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):
    compile 'com.google.firebase:firebase-config:10.2.5'
  2. Import the following classes to your app:

    Java

    import com.google.android.gms.tasks.OnCompleteListener;
    import com.google.android.gms.tasks.Task;
    import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
    import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
    

  3. Next, set up Remote Config, and disable Performance Monitoring if perf_disable is set to true:

    Java

    //Setup remote config
    final FirebaseRemoteConfig mFirebaseRemoteConfig = 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
    mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
    //Observe the remote config parameter "perf_disable" and disable Performance Monitoring if true
    if (mFirebaseRemoteConfig.getBoolean("perf_disable")) {
       FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false);
    } else {
       FirebasePerformance.getInstance().setPerformanceCollectionEnabled(true);
    }

  4. Finally, 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
    mFirebaseRemoteConfig.fetch(3600)
           .addOnCompleteListener(this, new OnCompleteListener() {
               @Override
               public void onComplete(@NonNull Task task) {
                   if (task.isSuccessful()) {
                       mFirebaseRemoteConfig.activateFetched();
                   } else {
                   }
               }
           });
    

  5. To disable Performance Monitoring in the Firebase console, create a perf_disable parameter in your app's project, and 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 will remain enabled.

Send feedback about...

Need help? Visit our support page.