Skip to content

[FirebaseAI] Add heartbeat info #1248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/src/swig/app.i
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,23 @@ static firebase::AppOptions* AppOptionsLoadFromJsonConfig(const char* config) {
userAgentMap[libraryPrefix + "-buildsrc"] =
Firebase.VersionInfo.BuildSource;

try {
// FirebaseAI doesn't depend on the other platforms, so the heartbeat
// logic needs to check for it here, using reflection.
const string firebaseAIClassName = "Firebase.AI.FirebaseAI";
// Iterate over the loaded assemblies, since we don't have a known DLL name.
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) {
Copy link
Member

Choose a reason for hiding this comment

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

For Apple, if there's a way to associate an Objective-C class and method with the library, we could potentially extend the code at https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseCore/Sources/FIRApp.m#L816 to handle this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that is what inspired me to do it this way. It is assuming the "FirebaseAI" class will be there, so maybe I should use another name in case that changes, but since that is a public facing class it isn't likely to change, so I think it should be fine.

System.Type foundType = assembly.GetType(firebaseAIClassName, throwOnError: false, ignoreCase: false);
if (foundType != null) {
// Found the class, add the FirebaseAI heartbeat to the user agent.
userAgentMap["fire-vertex"] = Firebase.VersionInfo.SdkVersion;
break;
}
}
} catch {
// Don't actually want to do anything if it fails
}

RegisterLibrariesInternal(userAgentMap);
}

Expand Down
Loading