Repository navigation
App (Desktop): register product user agents when an App is created - #1988
Conversation
On desktop only Firestore registered a product library, and only when the first Firestore instance was created, after the App had logged the day's heartbeat. Heartbeats therefore did not list the products in use. Let each module's AppCallback carry a library name and version, and register them in AppCallback::NotifyAllAppCreated(), before the heartbeat is logged. Add libraries for App Check, Auth, Database, Firestore, Functions, Remote Config and Storage. A callback that has been disabled does not register its library. The Unity SDK links every module into one library and disables the modules an application does not use, so this keeps unused modules out of the user agent.
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism for Firebase desktop products to register themselves in the Firebase user agent upon App creation, ensuring desktop usage is properly attributed. This is achieved by adding library registration methods to AppCallback and implementing a new FIREBASE_APP_REGISTER_LIBRARY macro across various modules, along with corresponding unit tests. The review feedback suggests two improvements: adding a null check on the callback pointer in LibraryRegistration to prevent potential null pointer dereferences, and restoring the global callback state at the end of the re-enablement test to avoid side effects on other tests.
| LibraryRegistration(AppCallback* callback, const char* name, | ||
| const char* version) { | ||
| callback->SetLibrary(name, version); | ||
| } |
There was a problem hiding this comment.
| EXPECT_THAT(std::string(App::GetUserAgent()), | ||
| ::testing::HasSubstr(kLibraryTestUserAgent)); | ||
| } |
There was a problem hiding this comment.
The test disables all callbacks using AppCallback::SetEnabledAll(false) but does not restore them at the end of the test. This can leave the global state modified and potentially affect other tests running in the same process. It is recommended to restore the default state of the callbacks by calling AppCallback::SetEnabledAll(true) at the end of the test.
EXPECT_THAT(std::string(App::GetUserAgent()),
::testing::HasSubstr(kLibraryTestUserAgent));
AppCallback::SetEnabledAll(true);
}| ## Release Notes | ||
| ### Upcoming | ||
| - Changes | ||
| - General (Desktop): Firebase products now register themselves in the |
There was a problem hiding this comment.
Similar to the other one, I don't think we need to call this out in the readme.
❌ Integration test FAILEDRequested by @AustinBenoit on commit a235ee1
Add flaky tests to go/fpl-cpp-flake-tracker |
Description
On desktop, only Firestore registered a product user-agent key, and only when the first
Firestoreinstance was created—afterApp::Create()had already logged the day's heartbeat. As a result, desktop heartbeats did not report which Firebase products an application uses.Let each module's
AppCallbackcarry a desktop library key/version viaFIREBASE_APP_REGISTER_LIBRARY(...)and register them inAppCallback::NotifyAllAppCreated()beforeLogHeartbeat()runs:app_check(fire-app-check),auth(fire-auth),database(fire-rtdb),functions(fire-fn),remote_config(fire-rc),storage(fire-gcs) withFIREBASE_VERSION_NUMBER_STRINGfirestore(fire-fst) withkFirestoreVersionStringDisabling a callback (
AppCallback::set_enabled(false)) also suppresses library registration so the Unity SDK—which links all C++ modules into one library and disables unused ones—only reports modules in use. Android and iOS builds are unchanged.Testing
app/tests/app_desktop_test.cccovering enabled registration, disabled exclusion (SetEnabledByName(..., false)), and Unity's disable-all + selective re-enable sequence (SetEnabledAll(false)->SetEnabledByName(..., true)).firebase_app_desktop_test(12/12 passed) andfirebase_app_heartbeat_controller_desktop_test(19/19 passed) on Linux (clang-19), and verified the negative test fails iflibrary_registration_enabled_ = enableis removed.firebase_app,firebase_auth,firebase_functions,firebase_storage,firebase_remote_config,firebase_app_check, and compileddatabase.cc.oandfirestore.cc.oon Linux (clang-19).scripts/gha/check_copyright.sh -g. Relying on CI for Windows/macOS/Android/iOS builds.Type of Change
Place an
xthe applicable box: