Skip to content

Commit 4c13211

Browse files
var-consta-maurice
authored andcommitted
Temporarily add a platform token to the Cloud API headers.
Until b/135633112 is resolved and support for Firebase platform logging is rolled out on the Firestore backend, there is no good way to estimate the number of users of the Firestore C++ SDK by platform. As a workaround, add a platform token to the Cloud headers. Proper support for platform tokens was actually never added to Cloud headers, but the data processing pipeline simply ignores unknown tokens so there is no harm in doing this addition. The implementation reuses the notion of a client language in the Core API to lump together two tokens (the language and the platform). This is deemed acceptable only due to the temporary nature of this workaround. Sample of the header values I'm seeing: - running C++ tests on Linux in google3: `gl-cpp/Clang-9999.0.0-noex-2017-libcpp gl-linux/ fire/1.17.1 grpc/1.33.0-dev` (notice the `gl-linux/` token); - in Unity: `gl-dotnet/4.0.30319 gl-macos/ fire/1.17.1 grpc/1.33.0-dev` (notice the `gl-mac/` token); PiperOrigin-RevId: 332094253
1 parent ebb43ad commit 4c13211

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

firestore/src/common/firestore.cc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,33 @@
2020
#include "firestore/src/ios/firestore_ios.h"
2121
#endif // defined(__ANDROID__)
2222

23+
#ifdef __APPLE__
24+
#include "TargetConditionals.h"
25+
#endif // __APPLE__
26+
2327
namespace firebase {
2428
namespace firestore {
2529

2630
DEFINE_FIREBASE_VERSION_STRING(FirebaseFirestore);
2731

2832
namespace {
2933

34+
const char* GetPlatform() {
35+
#if defined(__ANDROID__)
36+
return "gl-android/";
37+
#elif TARGET_OS_IOS
38+
return "gl-ios/";
39+
#elif TARGET_OS_OSX
40+
return "gl-macos/";
41+
#elif defined(_WIN32)
42+
return "gl-windows/";
43+
#elif defined(__linux__)
44+
return "gl-linux/";
45+
#else
46+
return "";
47+
#endif
48+
}
49+
3050
Mutex g_firestores_lock; // NOLINT
3151
std::map<App*, Firestore*>* g_firestores = nullptr;
3252

@@ -287,7 +307,13 @@ ListenerRegistration Firestore::AddSnapshotsInSyncListener(
287307
#endif // defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN)
288308

289309
void Firestore::SetClientLanguage(const std::string& language_token) {
290-
FirestoreInternal::SetClientLanguage(language_token);
310+
// TODO(b/135633112): this is a temporary measure until the Firestore backend
311+
// rolls out Firebase platform logging.
312+
// Note: this implementation lumps together the language and platform tokens,
313+
// relying on the fact that `SetClientLanguage` doesn't validate or parse its
314+
// input in any way. This is deemed acceptable because reporting the platform
315+
// this way is a temporary measure.
316+
FirestoreInternal::SetClientLanguage(language_token + " " + GetPlatform());
291317
}
292318

293319
} // namespace firestore

0 commit comments

Comments
 (0)