1
0
Fork 0

Sentry: generate a UUID for report tracking

Because we don’t have any user-identifier, generate a UUID so that
we can filter reports by it.
This commit is contained in:
Automatic Release Builder 2020-10-26 17:57:39 +00:00 committed by James Turner
parent f78d644a61
commit 5b3f0e5cbb

View file

@ -28,6 +28,7 @@
#include <simgear/props/props.hxx>
#include <simgear/structure/commands.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/io/iostreams/sgstream.hxx>
#include <Main/fg_init.hxx>
#include <Main/fg_props.hxx>
@ -61,6 +62,7 @@ auto OSG_messageWhitelist = {
auto XML_messageWhitelist = {
"Cannot open file",
"not well-formed (invalid token)",
"mismatched tag (from 'SimGear XML Parser')"
};
// we don't want sentry enabled for the test suite
@ -212,6 +214,38 @@ void initSentry()
sentry_options_add_attachment(options, logPath.c_str());
#endif
sentry_value_t user = sentry_value_new_object();
const auto uuidPath = fgHomePath() / "sentry_uuid.txt";
bool generateUuid = true;
std::string uuid;
if (uuidPath.exists()) {
sg_ifstream f(uuidPath);
std::getline(f, uuid);
// if we read enough bytes, that this is a valid UUID, then accept it
if ( uuid.length() >= 36) {
generateUuid = false;
}
}
// we need to generate a new UUID
if (generateUuid) {
// use the Sentry APi to generate one
sentry_uuid_t su = sentry_uuid_new_v4();
char bytes[38];
sentry_uuid_as_string(&su, bytes);
bytes[37] = 0;
uuid = std::string{bytes};
// write it back to disk for next time
sg_ofstream f(uuidPath);
f << uuid << endl;
}
sentry_value_t userUuidV = sentry_value_new_string(uuid.c_str());
sentry_value_set_by_key(user, "id", userUuidV);
sentry_set_user(user);
sentry_init(options);
static_sentryEnabled = true;