summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvkalintiris <vasilis@netdata.cloud>2024-04-18 13:32:07 +0300
committerGitHub <noreply@github.com>2024-04-18 13:32:07 +0300
commitf0215f41df16a6f75560fc4dc3b60fa836fd4db6 (patch)
treeb66aaaca5318a3d49acbcaf83bfdee7afe928981
parent9e4a0596141e094f9a5186c452184127aaf91081 (diff)
Associate sentry events with guid. (#17420)
* Refactor sentry-native api. * Constify returned string * Fill id on sentry crashes. * Fix missed rename.
-rw-r--r--src/daemon/main.c13
-rw-r--r--src/daemon/sentry-native/sentry-native.c11
-rw-r--r--src/daemon/sentry-native/sentry-native.h12
-rw-r--r--src/registry/registry.h2
-rw-r--r--src/registry/registry_internals.c2
5 files changed, 28 insertions, 12 deletions
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 768065fd15..6aa13adf65 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -475,7 +475,7 @@ void netdata_cleanup_and_exit(int ret, const char *action, const char *action_re
if (ret)
abort();
else {
- sentry_native_fini();
+ nd_sentry_fini();
exit(ret);
}
#else
@@ -2111,7 +2111,7 @@ int main(int argc, char **argv) {
// init sentry
#ifdef ENABLE_SENTRY
- sentry_native_init();
+ nd_sentry_init();
#endif
// The "HOME" env var points to the root's home dir because Netdata starts as root. Can't use "HOME".
@@ -2158,7 +2158,14 @@ int main(int argc, char **argv) {
struct rrdhost_system_info *system_info = callocz(1, sizeof(struct rrdhost_system_info));
__atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
get_system_info(system_info);
- (void) registry_get_this_machine_guid();
+
+ const char *guid = registry_get_this_machine_guid();
+#ifdef ENABLE_SENTRY
+ nd_sentry_set_user(guid);
+#else
+ UNUSED(guid);
+#endif
+
system_info->hops = 0;
get_install_type(&system_info->install_type, &system_info->prebuilt_arch, &system_info->prebuilt_dist);
diff --git a/src/daemon/sentry-native/sentry-native.c b/src/daemon/sentry-native/sentry-native.c
index 3594c1fffa..2d984fa36d 100644
--- a/src/daemon/sentry-native/sentry-native.c
+++ b/src/daemon/sentry-native/sentry-native.c
@@ -19,7 +19,7 @@ static bool sentry_telemetry_disabled(void)
return getenv("DISABLE_TELEMETRY") != NULL;
}
-void sentry_native_init(void)
+void nd_sentry_init(void)
{
if (sentry_telemetry_disabled())
return;
@@ -41,10 +41,17 @@ void sentry_native_init(void)
sentry_init(options);
}
-void sentry_native_fini(void)
+void nd_sentry_fini(void)
{
if (sentry_telemetry_disabled())
return;
sentry_close();
}
+
+void nd_sentry_set_user(const char *guid)
+{
+ sentry_value_t user = sentry_value_new_object();
+ sentry_value_set_by_key(user, "id", sentry_value_new_string(guid));
+ sentry_set_user(user);
+}
diff --git a/src/daemon/sentry-native/sentry-native.h b/src/daemon/sentry-native/sentry-native.h
index 861c5b9595..81f909d9fb 100644
--- a/src/daemon/sentry-native/sentry-native.h
+++ b/src/daemon/sentry-native/sentry-native.h
@@ -1,9 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later
-#ifndef SENTRY_NATIVE_H
-#define SENTRY_NATIVE_H
+#ifndef ND_SENTRY_H
+#define ND_SENTRY_H
-void sentry_native_init(void);
-void sentry_native_fini(void);
+void nd_sentry_init(void);
+void nd_sentry_fini(void);
-#endif /* SENTRY_NATIVE_H */
+void nd_sentry_set_user(const char *guid);
+
+#endif /* ND_SENTRY_H */
diff --git a/src/registry/registry.h b/src/registry/registry.h
index 746fe430f6..848eb0ac00 100644
--- a/src/registry/registry.h
+++ b/src/registry/registry.h
@@ -74,7 +74,7 @@ void registry_update_cloud_base_url();
// update the registry monitoring charts
void registry_statistics(void);
-char *registry_get_this_machine_guid(void);
+const char *registry_get_this_machine_guid(void);
char *registry_get_mgmt_api_key(void);
char *registry_get_this_machine_hostname(void);
diff --git a/src/registry/registry_internals.c b/src/registry/registry_internals.c
index afa6286bff..dbe9c3e3eb 100644
--- a/src/registry/registry_internals.c
+++ b/src/registry/registry_internals.c
@@ -270,7 +270,7 @@ char *registry_get_this_machine_hostname(void) {
return registry.hostname;
}
-char *registry_get_this_machine_guid(void) {
+const char *registry_get_this_machine_guid(void) {
static char guid[GUID_LEN + 1] = "";
if(likely(guid[0]))