Firebase Performance Monitoring 사용 중지

앱 개발 및 테스트 중에 Performance Monitoring을 사용 중지하는 것이 유용할 수 있습니다.

예를 들어 앱 빌드 시 Performance Monitoring을 사용 중지하여 다음 작업을 할 수 있습니다.

  • 디버그 빌드에서는 Performance Monitoring Gradle 플러그인에서 제공하는 것과 같은 Performance Monitoring의 특정 기능을 사용 중지하고 출시 빌드에서는 기능을 다시 사용 설정합니다.

  • 앱을 빌드할 때 Performance Monitoring을 사용 중지하고 런타임에 앱에서 다시 사용 설정하도록 허용합니다.

  • 앱을 빌드할 때 Performance Monitoring을 사용 중지하고 런타임에 앱에서 다시 사용 설정하도록 허용하지 않습니다.

또한 Performance Monitoring을 사용 설정한 상태에서 앱을 빌드하고 Firebase 원격 구성을 사용하여 프로덕션 앱에서 Performance Monitoring을 원하는 대로 사용 중지하고 다시 사용 설정할 수 있습니다. 이 옵션을 통해 사용자가 Performance Monitoring 사용 여부를 선택할 수 있도록 앱을 구성할 수도 있습니다.

앱 빌드 시 Performance Monitoring 사용 중지

앱 빌드 시 Performance Monitoring Gradle 플러그인을 사용 중지하거나 Performance Monitoring Android 라이브러리를 사용 중지하여 Performance Monitoring을 사용 중지할 수 있습니다.

플러그인을 사용한 계측은 빌드 시간 증가에 영향을 미칠 수 있으므로 개발 및 디버깅 중에는 플러그인을 사용 중지하는 것이 유용할 수 있습니다. 하지만 앱 시작, 포그라운드 앱, 백그라운드 앱 trace와 더불어 앱의 커스텀 코드 trace의 성능 데이터를 계속 확인할 수 있도록 라이브러리를 사용 설정한 상태로 유지할 수도 있습니다.

Performance Monitoring Gradle 플러그인 사용 중지

다음 옵션으로 instrumentationEnabled 플래그를 추가하여 Performance Monitoring 플러그인을 사용 중지할 수 있습니다.

  • 확장 속성 — 컴파일 시점에 특정 빌드 변형에 플러그인 사용 중지

  • 프로젝트 속성 — 컴파일 시점에 모든 빌드 변형에 플러그인 사용 중지

확장 속성 플래그를 사용하여 플러그인 사용 중지

확장 속성 플래그를 사용하여 컴파일 시점에 특정 빌드 변형에 Performance Monitoring 플러그인을 사용 중지할 수 있습니다.

  1. 루트 수준(프로젝트 수준) Gradle 파일(<project>/build.gradle.kts 또는 <project>/build.gradle)에서 Android Gradle 플러그인 종속 항목이 v3.4.0 이상으로 지정되어 있는지 확인합니다.

    이전 버전의 Android Gradle 플러그인의 경우 특정 빌드 변형에 Performance Monitoring 플러그인을 사용 중지할 수 있지만 해당 빌드 변형의 빌드 시간에 대한 영향은 완전히 없앨 수 없습니다.

  2. 다음 플래그를 모듈(앱 수준) Gradle 파일(일반적으로 <project>/<app-module>/build.gradle.kts 또는 <project>/<app-module>/build.gradle)에 추가한 다음 false로 설정하여 Performance Monitoring 플러그인을 사용 중지합니다.

    Kotlin

    import com.google.firebase.perf.plugin.FirebasePerfExtension
    
    // ...
    
    android {
      // ...
      buildTypes {
        getByName("debug") {
          configure<FirebasePerfExtension> {
            // 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.
            setInstrumentationEnabled(false)
          }
        }
      }
    }
    

    Groovy

    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
          }
        }
      }
    }
    

프로젝트 속성 플래그를 사용하여 플러그인 사용 중지

프로젝트 속성 플래그를 사용하여 컴파일 시점에 모든 빌드 변형에 Performance Monitoring 플러그인을 사용 중지할 수 있습니다.

다음 플래그를 gradle.properties 파일에 추가한 다음 false로 설정하여 Performance Monitoring 플러그인을 사용 중지합니다.

// ...

// 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

Performance Monitoring Android 라이브러리 사용 중지

컴파일 시점에 Performance Monitoring 라이브러리를 사용 중지하는 경우 런타임에 앱에서 라이브러리를 사용 설정하도록 허용할지 여부를 선택할 수 있습니다.

컴파일 시점에 라이브러리를 사용 중지하지만 런타임에 앱에서 사용 설정하도록 허용

앱의 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 원격 구성은 앱의 동작과 모양을 변경할 수 있으므로 앱의 배포된 인스턴스에서 Performance Monitoring을 사용 중지하는 이상적인 방법을 제공합니다.

아래와 같은 예시 코드를 사용하면 다음 번에 Android 앱이 시작될 때 Performance Monitoring 데이터 수집을 중지할 수 있습니다. Android 앱에서 원격 구성을 사용하는 방법에 관한 자세한 내용은 Android에서 Firebase 원격 구성 사용을 참조하세요.

  1. 원격 구성이 모듈(앱 수준) Gradle 파일(일반적으로 <project>/<app-module>/build.gradle.kts 또는 <project>/<app-module>/build.gradle)의 dependencies 섹션에 있는지 확인합니다.

    Kotlin+KTX

      implementation("com.google.firebase:firebase-config-ktx:21.6.0")
    

    Java

      implementation("com.google.firebase:firebase-config:21.6.0")
    
  2. 원격 구성을 설정하고 perf_disabletrue이면 Performance Monitoring을 사용 중지합니다.

    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
                    }
                }
            });
  3. 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
                    }
                }
            });
  4. Firebase Console에서 Performance Monitoring을 사용 중지하려면 앱의 프로젝트에 perf_disable 매개변수를 만들고 그 값을 true로 설정합니다.

    이렇게 변경하면 Performance Monitoring SDK 호출이 '작업 없음' 호출(NOOP)로 바뀌므로 앱에서 Performance Monitoring SDK를 사용하는 데 따르는 앱 성능 저하를 방지할 수 있습니다.

    perf_disable 값을 false로 설정하면 Performance Monitoring은 사용 설정된 상태로 유지됩니다.