Associate sentry events with guid. (#17420)
* Refactor sentry-native api. * Constify returned string * Fill id on sentry crashes. * Fix missed rename.
vkalintiris committed
Apr 18, 2024 at 13:32 UTC
f0215f41df16a6f75560fc4dc3b60fa836fd4db6
5 files changed
+28
-12
src/daemon/main.c
+10
-3
@@ -475,7 +475,7 @@ void netdata_cleanup_and_exit(int ret, const char *action, const char *action_re
475
if (ret)
476
abort();
477
else {
478
- sentry_native_fini();
478
+ nd_sentry_fini();
479
exit(ret);
480
}
481
#else
@@ -2111,7 +2111,7 @@ int main(int argc, char **argv) {
2111
2112
// init sentry
2113
#ifdef ENABLE_SENTRY
2114
- sentry_native_init();
2114
+ nd_sentry_init();
2115
#endif
2116
2117
// 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) {
2158
struct rrdhost_system_info *system_info = callocz(1, sizeof(struct rrdhost_system_info));
2159
__atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
2160
get_system_info(system_info);
2161
- (void) registry_get_this_machine_guid();
2161
+
2162
+ const char *guid = registry_get_this_machine_guid();
2163
+#ifdef ENABLE_SENTRY
2164
+ nd_sentry_set_user(guid);
2165
+#else
2166
+ UNUSED(guid);
2167
+#endif
2168
+
2169
system_info->hops = 0;
2170
get_install_type(&system_info->install_type, &system_info->prebuilt_arch, &system_info->prebuilt_dist);
2171
src/daemon/sentry-native/sentry-native.c
+9
-2
@@ -19,7 +19,7 @@ static bool sentry_telemetry_disabled(void)
19
return getenv("DISABLE_TELEMETRY") != NULL;
20
}
21
22
-void sentry_native_init(void)
22
+void nd_sentry_init(void)
23
{
24
if (sentry_telemetry_disabled())
25
return;
@@ -41,10 +41,17 @@ void sentry_native_init(void)
41
sentry_init(options);
42
}
43
44
-void sentry_native_fini(void)
44
+void nd_sentry_fini(void)
45
{
46
if (sentry_telemetry_disabled())
47
return;
48
49
sentry_close();
50
}
51
+
52
+void nd_sentry_set_user(const char *guid)
53
+{
54
+ sentry_value_t user = sentry_value_new_object();
55
+ sentry_value_set_by_key(user, "id", sentry_value_new_string(guid));
56
+ sentry_set_user(user);
57
+}
src/daemon/sentry-native/sentry-native.h
+7
-5
@@ -1,9 +1,11 @@
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
-#ifndef SENTRY_NATIVE_H
4
-#define SENTRY_NATIVE_H
3
+#ifndef ND_SENTRY_H
4
+#define ND_SENTRY_H
5
6
-void sentry_native_init(void);
7
-void sentry_native_fini(void);
6
+void nd_sentry_init(void);
7
+void nd_sentry_fini(void);
8
9
-#endif /* SENTRY_NATIVE_H */
9
+void nd_sentry_set_user(const char *guid);
10
+
11
+#endif /* ND_SENTRY_H */
src/registry/registry.h
+1
-1
@@ -74,7 +74,7 @@ void registry_update_cloud_base_url();
74
// update the registry monitoring charts
75
void registry_statistics(void);
76
77
-char *registry_get_this_machine_guid(void);
77
+const char *registry_get_this_machine_guid(void);
78
char *registry_get_mgmt_api_key(void);
79
char *registry_get_this_machine_hostname(void);
80
src/registry/registry_internals.c
+1
-1
@@ -270,7 +270,7 @@ char *registry_get_this_machine_hostname(void) {
270
return registry.hostname;
271
}
272
273
-char *registry_get_this_machine_guid(void) {
273
+const char *registry_get_this_machine_guid(void) {
274
static char guid[GUID_LEN + 1] = "";
275
276
if(likely(guid[0]))