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_enabledtotruein your app'sInfo.plistfile. - To completely deactivate Performance Monitoring with no option to enable it at runtime,
set
firebase_performance_collection_deactivatedtotruein your app'sInfo.plistfile. This setting overrides thefirebase_performance_collection_enabledsetting and must be removed from your app'sInfo.plistfile 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.
- Ensure that Remote Config is used in your
Podfile: pod 'Firebase/RemoteConfig' -
Add the following to the top of your app's
AppDelegatefile:Swift
import FirebaseRemoteConfig
Objective-C
@import FirebaseRemoteConfig;
-
In your
AppDelegatefile, add the following code to thelaunchOptionsstatements in theapplication: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]; -
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); } }]; -
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 tofalse, 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.
- Ensure that Remote Config is in the
dependenciessection of your module Gradle file (usuallyapp/build.gradle):compile 'com.google.firebase:firebase-config:10.2.5'
-
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;
-
Next, set up Remote Config, and disable Performance Monitoring if
perf_disableis set totrue: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); } -
Finally, add the following code to
MainActivity.javato 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 { } } }); -
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 tofalse, Performance Monitoring will remain enabled.

