Skip to content

App (Desktop): register product user agents when an App is created - #1988

Merged
AustinBenoit merged 5 commits into
mainfrom
fix/desktop-product-user-agents
Nov 25, 2026
Merged

AustinBenoit merged 5 commits into
mainfrom
fix/desktop-product-user-agents

Conversation

@AustinBenoit

Copy link
Copy Markdown
Contributor

Description

On desktop, only Firestore registered a product user-agent key, and only when the first Firestore instance was created—after App::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 AppCallback carry a desktop library key/version via FIREBASE_APP_REGISTER_LIBRARY(...) and register them in AppCallback::NotifyAllAppCreated() before LogHeartbeat() runs:

  • app_check (fire-app-check), auth (fire-auth), database (fire-rtdb), functions (fire-fn), remote_config (fire-rc), storage (fire-gcs) with FIREBASE_VERSION_NUMBER_STRING
  • firestore (fire-fst) with kFirestoreVersionString

Disabling 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

  • Added 3 unit tests in app/tests/app_desktop_test.cc covering enabled registration, disabled exclusion (SetEnabledByName(..., false)), and Unity's disable-all + selective re-enable sequence (SetEnabledAll(false) -> SetEnabledByName(..., true)).
  • Ran firebase_app_desktop_test (12/12 passed) and firebase_app_heartbeat_controller_desktop_test (19/19 passed) on Linux (clang-19), and verified the negative test fails if library_registration_enabled_ = enable is removed.
  • Built firebase_app, firebase_auth, firebase_functions, firebase_storage, firebase_remote_config, firebase_app_check, and compiled database.cc.o and firestore.cc.o on Linux (clang-19).
  • Passed scripts/gha/check_copyright.sh -g. Relying on CI for Windows/macOS/Android/iOS builds.

Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/src/util.h
Comment on lines +148 to +151
LibraryRegistration(AppCallback* callback, const char* name,
const char* version) {
callback->SetLibrary(name, version);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential null pointer dereferences, it is safer to perform a null check on callback before calling SetLibrary on it.

    LibraryRegistration(AppCallback* callback, const char* name,
                        const char* version) {
      if (callback != nullptr) {
        callback->SetLibrary(name, version);
      }
    }

Comment on lines +311 to +313
EXPECT_THAT(std::string(App::GetUserAgent()),
::testing::HasSubstr(kLibraryTestUserAgent));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

@AustinBenoit
AustinBenoit marked this pull request as ready for review November 24, 2026 18:43
Comment thread release_build_files/readme.md Outdated
## Release Notes
### Upcoming
- Changes
- General (Desktop): Firebase products now register themselves in the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the other one, I don't think we need to call this out in the readme.

@AustinBenoit AustinBenoit added the skip-release-notes Skip release notes check label Nov 25, 2026
@AustinBenoit
AustinBenoit enabled auto-merge (squash) November 25, 2026 03:12
@AustinBenoit
AustinBenoit merged commit a235ee1 into main Nov 25, 2026
39 of 55 checks passed
@github-actions github-actions Bot added the tests: in-progress This PR's integration tests are in progress. label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

❌  Integration test FAILED

Requested by @AustinBenoit on commit a235ee1
Last updated: Tue Nov 24 21:36 PST 2026
View integration test log & download artifacts

Failures Configs
missing_log [TEST] [ERROR] [iOS] [macos] [1/2 ios_device: ios_target]

Add flaky tests to go/fpl-cpp-flake-tracker

@github-actions github-actions Bot added the tests: failed This PR's integration tests failed. label Nov 25, 2026
@firebase-workflow-trigger firebase-workflow-trigger Bot removed the tests: in-progress This PR's integration tests are in progress. label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-release-notes Skip release notes check tests: failed This PR's integration tests failed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants