fixed sentry dedup (#19867)
Costa Tsaousis committed
Mar 14, 2025 at 21:23 UTC
9e1a16d3b5374b5a8b4a411c8071dfdde3451907
4 files changed
+17
-21
src/daemon/analytics.c
+10
-1
@@ -869,7 +869,16 @@ bool analytics_check_enabled(void) {
869
870
char filename[FILENAME_MAX + 1];
871
snprintfz(filename, sizeof(filename), "%s/.opt-out-from-anonymous-statistics", netdata_configured_user_config_dir);
872
- netdata_anonymous_statistics_enabled = access(filename, R_OK) != 0;
872
+
873
+ if(access(filename, R_OK) != 0) {
874
+ // the file is not there, check the environment variable
875
+ const char *s = getenv("DISABLE_TELEMETRY");
876
+ netdata_anonymous_statistics_enabled = !s || !*s;
877
+ }
878
+ else
879
+ // the file is there, disable telemetry
880
+ netdata_anonymous_statistics_enabled = false;
881
+
882
return netdata_anonymous_statistics_enabled;
883
}
884
src/daemon/daemon-status-file.c
+1
-1
@@ -1269,7 +1269,7 @@ bool daemon_status_file_deadly_signal_received(EXIT_REASON reason, SIGNAL_CODE c
1269
bool duplicate = false;
1270
if(chained_handler) {
1271
uint64_t hash = daemon_status_file_hash(&session_status, NULL, NULL);
1272
- duplicate = !dedup_already_posted(&session_status, hash);
1272
+ duplicate = dedup_already_posted(&session_status, hash);
1273
if (!duplicate) {
1274
// save this hash, so that we won't post it again to sentry
1275
dedup_keep_hash(&session_status, hash);
src/daemon/sentry-native/sentry-native.c
+4
-18
@@ -5,28 +5,14 @@
5
6
#include "sentry.h"
7
8
-static bool sentry_telemetry_disabled(void)
9
-{
10
- char path[FILENAME_MAX + 1];
11
- sprintf(path, "%s/%s", netdata_configured_user_config_dir, ".opt-out-from-anonymous-statistics");
12
-
13
- struct stat buffer;
14
- bool opt_out_file_exists = (stat(path, &buffer) == 0);
15
-
16
- if (opt_out_file_exists)
17
- return true;
18
-
19
- return getenv("DISABLE_TELEMETRY") != NULL;
20
-}
21
-
8
void nd_sentry_init(void)
9
{
24
- if (sentry_telemetry_disabled())
10
+ if (!analytics_check_enabled())
11
return;
12
13
// path where sentry should save stuff
14
char path[FILENAME_MAX];
29
- snprintfz(path, FILENAME_MAX - 1, "%s/%s", netdata_configured_cache_dir, ".sentry-native");
15
+ snprintfz(path, FILENAME_MAX - 1, "%s/.sentry-native", netdata_configured_cache_dir);
16
17
sentry_options_t *options = sentry_options_new();
18
sentry_options_set_dsn(options, NETDATA_SENTRY_DSN);
@@ -48,7 +34,7 @@ void nd_sentry_init(void)
34
35
void nd_sentry_fini(void)
36
{
51
- if (sentry_telemetry_disabled())
37
+ if (!analytics_check_enabled())
38
return;
39
40
sentry_close();
@@ -63,7 +49,7 @@ void nd_sentry_set_user(const char *guid)
49
50
void nd_sentry_add_breadcrumb(const char *message)
51
{
66
- if (sentry_telemetry_disabled())
52
+ if (!analytics_check_enabled())
53
return;
54
55
sentry_value_t crumb = sentry_value_new_breadcrumb("fatal", message);
src/daemon/signal-handler.c
+2
-1
@@ -61,9 +61,10 @@ void nd_signal_handler(int signo, siginfo_t *info, void *context __maybe_unused)
61
62
// Update the status file
63
SIGNAL_CODE sc = info ? signal_code(signo, info->si_code) : 0;
64
- if(daemon_status_file_deadly_signal_received(signals_waiting[i].reason, sc, chained_handler))
64
+ if(daemon_status_file_deadly_signal_received(signals_waiting[i].reason, sc, chained_handler)) {
65
// this is a duplicate event, do not send it to sentry
66
chained_handler = false;
67
+ }
68
69
// log it
70
char b[1024];