aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/sentryintegration.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-11-15 10:14:45 +0100
committerGitHub <[email protected]>2023-11-15 10:14:45 +0100
commitd984d8dde355bca92dfe2e85484fd60b12199f1d (patch)
treebfd6da60fba5eb3d61765fe5eefb7f3e2fdd438e /src/zenserver/sentryintegration.cpp
parent0.2.33 (diff)
downloadzen-d984d8dde355bca92dfe2e85484fd60b12199f1d.tar.xz
zen-d984d8dde355bca92dfe2e85484fd60b12199f1d.zip
add host name to sentry (#537)
* add hostname to sentry user id
Diffstat (limited to 'src/zenserver/sentryintegration.cpp')
-rw-r--r--src/zenserver/sentryintegration.cpp56
1 files changed, 49 insertions, 7 deletions
diff --git a/src/zenserver/sentryintegration.cpp b/src/zenserver/sentryintegration.cpp
index 755fe97db..05e80bb17 100644
--- a/src/zenserver/sentryintegration.cpp
+++ b/src/zenserver/sentryintegration.cpp
@@ -231,14 +231,25 @@ SentryIntegration::Initialize(std::string SentryDatabasePath, std::string Sentry
if (m_AllowPII)
{
# if ZEN_PLATFORM_WINDOWS
- CHAR UserNameBuffer[511 + 1];
- DWORD UserNameLength = sizeof(UserNameBuffer) / sizeof(CHAR);
- BOOL OK = GetUserNameA(UserNameBuffer, &UserNameLength);
- if (OK && UserNameLength)
+ CHAR Buffer[511 + 1];
+ DWORD BufferLength = sizeof(Buffer) / sizeof(CHAR);
+ BOOL OK = GetUserNameA(Buffer, &BufferLength);
+ if (OK && BufferLength)
{
- m_SentryUserName = std::string(UserNameBuffer, UserNameLength - 1);
+ m_SentryUserName = std::string(Buffer, BufferLength - 1);
+ }
+ BufferLength = sizeof(Buffer) / sizeof(CHAR);
+ OK = GetComputerNameA(Buffer, &BufferLength);
+ if (OK && BufferLength)
+ {
+ m_SentryHostName = std::string(Buffer, BufferLength - 1);
+ }
+ else
+ {
+ m_SentryHostName = "unknown";
}
# endif // ZEN_PLATFORM_WINDOWS
+
# if (ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC)
uid_t uid = geteuid();
struct passwd* pw = getpwuid(uid);
@@ -246,9 +257,24 @@ SentryIntegration::Initialize(std::string SentryDatabasePath, std::string Sentry
{
m_SentryUserName = std::string(pw->pw_name);
}
+ else
+ {
+ m_SentryUserName = "unknown";
+ }
+ char HostNameBuffer[1023 + 1];
+ int err = gethostname(HostNameBuffer, sizeof(HostNameBuffer));
+ if (err == 0)
+ {
+ m_SentryHostName = std::string(HostNameBuffer);
+ }
+ else
+ {
+ m_SentryHostName = "unknown";
+ }
# endif
+ m_SentryId = fmt::format("{}@{}", m_SentryUserName, m_SentryHostName);
sentry_value_t SentryUserObject = sentry_value_new_object();
- sentry_value_set_by_key(SentryUserObject, "id", sentry_value_new_string(m_SentryUserName.c_str()));
+ sentry_value_set_by_key(SentryUserObject, "id", sentry_value_new_string(m_SentryId.c_str()));
sentry_value_set_by_key(SentryUserObject, "username", sentry_value_new_string(m_SentryUserName.c_str()));
sentry_value_set_by_key(SentryUserObject, "ip_address", sentry_value_new_string("{{auto}}"));
sentry_set_user(SentryUserObject);
@@ -266,13 +292,29 @@ SentryIntegration::Initialize(std::string SentryDatabasePath, std::string Sentry
void
SentryIntegration::LogStartupInformation()
{
+# if (ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC)
+ uid_t uid = geteuid();
+ struct passwd* pw = getpwuid(uid);
+ if (pw)
+ {
+ m_SentryUserName = std::string(pw->pw_name);
+ }
+ ZEN_INFO("Username: '{}'", m_SentryUserName);
+
+ char HostNameBuffer[1023 + 1];
+ int err = gethostname(HostNameBuffer, sizeof(HostNameBuffer));
+ if (err == 0)
+ {
+ ZEN_INFO("Hostname: '{}'", HostNameBuffer);
+ }
+# endif
if (m_IsInitialized)
{
if (m_SentryErrorCode == 0)
{
if (m_AllowPII)
{
- ZEN_INFO("sentry initialized, username: '{}'", m_SentryUserName);
+ ZEN_INFO("sentry initialized, username: '{}', hostname: '{}', id: '{}'", m_SentryUserName, m_SentryHostName, m_SentryId);
}
else
{