Associate sentry events with guid. (#17420)

* Refactor sentry-native api.

* Constify returned string

* Fill id on sentry crashes.

* Fix missed rename.
This commit is contained in:
vkalintiris 2024-04-18 13:32:07 +03:00 committed by GitHub
parent 9e4a059614
commit f0215f41df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 12 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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 */

View File

@ -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);

View File

@ -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]))