앱 개발 및 테스트 중에 성능 모니터링을 비활성화하는 것이 유용할 수 있습니다.
예를 들어 앱 빌드 프로세스 중에 성능 모니터링을 비활성화 하면 다음을 수행할 수 있습니다.
디버그 빌드에서 Performance Monitoring의 특정 기능(예: Performance Monitoring Gradle 플러그인 에서 제공하는 기능)을 비활성화하지만 릴리스 빌드의 기능은 다시 활성화합니다.
앱을 빌드할 때 성능 모니터링을 비활성화하지만 앱이 런타임에 다시 활성화하도록 허용하십시오.
앱을 빌드할 때 성능 모니터링을 비활성화하고 런타임에 앱이 다시 활성화하지 않도록 하십시오.
Performance Monitoring이 활성화된 상태에서 앱을 빌드할 수도 있지만 Firebase 원격 구성 을 사용하면 프로덕션 앱에서 Performance Monitoring을 유연하게 비활성화(및 재활성화)할 수 있습니다. 이 옵션을 사용하면 사용자가 Performance Monitoring 사용을 옵트인하거나 옵트아웃할 수 있도록 앱을 구성할 수도 있습니다.
앱 빌드 프로세스 중 성능 모니터링 비활성화
Performance Monitoring Gradle 플러그인 을 비활성화하거나 Performance Monitoring Android 라이브러리 를 비활성화하여 빌드 프로세스 중에 Performance Monitoring을 비활성화할 수 있습니다.
개발 및 디버깅 중에 플러그인을 비활성화하면 플러그인에 의한 계측 이 빌드 시간 증가에 기여할 수 있으므로 유용합니다. 그러나 앱 시작, 포그라운드 앱, 백그라운드 앱 추적 및 앱의 모든 사용자 지정 코드 추적 에서 성능 데이터를 계속 볼 수 있도록 라이브러리를 활성화 상태로 유지하는 것을 고려할 수 있습니다.
성능 모니터링 Gradle 플러그인 비활성화
다음 옵션을 사용하여 instrumentationEnabled
플래그를 추가하여 성능 모니터링 플러그인을 비활성화할 수 있습니다.
확장 속성 플래그를 통해 플러그인 비활성화
확장 속성 플래그를 사용하여 컴파일 시간에 특정 빌드 변형에 대한 성능 모니터링 플러그인을 비활성화할 수 있습니다.
루트 수준(프로젝트 수준)
build.gradle
파일에서 Android Gradle 플러그인 종속성이 v3.4.0 이상으로 지정되었는지 확인하세요.이전 버전의 Android Gradle 플러그인의 경우 여전히 특정 빌드 변형에 대한 성능 모니터링 플러그인을 비활성화할 수 있지만 해당 변형에 대한 빌드 시간 기여도가 완전히 제거되지는 않습니다.
모듈(앱 수준)
build.gradle
파일에 다음 플래그를 추가한 다음false
로 설정하여 성능 모니터링 플러그인을 비활성화합니다.android { // ... buildTypes { debug { FirebasePerformance { // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for a specific build variant at compile time. instrumentationEnabled false } } } }
프로젝트 속성 플래그를 통해 플러그인 비활성화
프로젝트 속성 플래그를 사용하여 컴파일 시간에 모든 빌드 변형에 대한 성능 모니터링 플러그인을 비활성화할 수 있습니다.
gradle.properties
파일에 다음 플래그를 추가한 다음 false
로 설정하여 성능 모니터링 플러그인을 비활성화합니다.
// ... // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for all build variants at compile time. firebasePerformanceInstrumentationEnabled=false
성능 모니터링 Android 라이브러리 비활성화
컴파일 시간에 성능 모니터링 라이브러리를 비활성화하는 경우 앱이 런타임에 라이브러리를 활성화하도록 허용할지 여부를 선택할 수 있습니다.
컴파일 시간에 라이브러리를 비활성화하지만 앱이 런타임에 활성화하도록 허용
앱의 AndroidManifest.xml
파일에 다음 <meta-data>
요소를 추가합니다.
<application> <meta-data android:name="firebase_performance_collection_enabled" android:value="false" /> </application>
컴파일 시간에 라이브러리를 비활성화하지만 앱이 런타임에 라이브러리를 활성화하지 않도록 합니다.
앱의 AndroidManifest.xml
파일에 다음 <meta-data>
요소를 추가합니다.
<application> <meta-data android:name="firebase_performance_collection_deactivated" android:value="true" /> </application>
원격 구성을 사용하여 런타임 시 앱 비활성화
Firebase 원격 구성을 사용하면 앱의 동작과 모양을 변경할 수 있으므로 앱의 배포된 인스턴스에서 성능 모니터링을 비활성화할 수 있는 이상적인 방법을 제공합니다.
다음에 Android 앱을 시작할 때 Performance Monitoring 데이터 수집을 비활성화하려면 아래 표시된 예제 코드를 사용하십시오. Android 앱에서 원격 구성을 사용하는 방법에 대한 자세한 내용은 Android에서 Firebase 원격 구성 사용 을 참조하세요.
원격 구성이 모듈 Gradle 파일(일반적으로
app/build.gradle
)의dependencies
섹션에 있는지 확인합니다.implementation 'com.google.firebase:firebase-config:21.2.1'
원격 구성을 설정하고
perf_disable
이true
로 설정된 경우 성능 모니터링을 비활성화합니다.Kotlin+KTX
// Setup remote config val config = Firebase.remoteConfig // 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. // val configSettings = remoteConfigSettings { // minimumFetchIntervalInSeconds = 3600 // } // config.setConfigSettingsAsync(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.setDefaultsAsync(R.xml.remote_config_defaults) .addOnCompleteListener { task -> if (task.isSuccessful) { Firebase.performance.isPerformanceCollectionEnabled = !config.getBoolean("perf_disable") } else { // An error occurred while setting default parameters } }
Java
// Setup remote config final 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() // .setMinimumFetchIntervalInSeconds(3600) // .build(); // config.setConfigSettingsAsync(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.setDefaultsAsync(R.xml.remote_config_defaults) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { if (config.getBoolean("perf_disable")) { FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false); } else { FirebasePerformance.getInstance().setPerformanceCollectionEnabled(true); } } else { // An error occurred while setting default parameters } } });
MainActivity.java
에 다음 코드를 추가하여 원격 구성 값을 가져오고 활성화합니다.Kotlin+KTX
// Remote Config fetches and activates parameter values from the service val config = Firebase.remoteConfig config.fetch(3600) .continueWithTask { task -> if (!task.isSuccessful) { task.exception?.let { throw it } } config.activate() } .addOnCompleteListener(this) { task -> if (task.isSuccessful) { // Parameter values successfully activated // ... } else { // Handle errors } }
Java
//Remote Config fetches and activates parameter values from the service final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance(); config.fetch(3600) .continueWithTask(new Continuation<Void, Task<Boolean>>() { @Override public Task<Boolean> then(@NonNull Task<Void> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return config.activate(); } }) .addOnCompleteListener(new OnCompleteListener<Boolean>() { @Override public void onComplete(@NonNull Task<Boolean> task) { if (task.isSuccessful()) { // Parameter values successfully activated // ... } else { // Handle errors } } });
Firebase 콘솔에서 Performance Monitoring을 비활성화하려면 앱 프로젝트에서 perf_disable 매개변수를 만든 다음 해당 값을
true
로 설정합니다.이 변경으로 인해 성능 모니터링 SDK "작업 없음" 호출(NOOP)이 호출되어 앱에서 성능 모니터링 SDK를 사용할 때 앱 성능에 미치는 중대한 영향이 제거됩니다.
perf_disable 값을
false
로 설정하면 성능 모니터링이 활성화된 상태로 유지됩니다.