@cryptotaxi247 / netdata-1 / commits / 18800a4af

Setup sentry-native SDK. (#16798)

* Setup sentry-native SDK. * Integrate Sentry into our CI Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * minor fix Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * Include sentry field to the build matrix Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * Update the bundle_sentry flag for all the distros Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * more changes Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * NON mergeable change Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * . Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * Enable fetch content. * Abort in profile plugin * Update plugin_profile.cc * NON MERGABLE COMMIT, just for testing purposes * NON MERGEABLE CHANGE, jsut for testing purposes * Bump * Use breakpad backend * Multiple changes - Make DSN variable that we read from the CI from the CI - Upload debug symbols - Fix packaging workflow; include new env vars & fix shecllchecks Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * Modify sentry dif command * fix merge conf Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * Fix merge conflict * Undo file prefix map. * Fix typo * Cleanup stuff. * Add 256-checksum * Renable ML for debs * Finalize CI changes Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * Update rules * final touches Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * merge the two if, no point to have them sep Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> * Update contrib/debian/rules Co-authored-by: Tasos Katsoulas <12612986+tkatsoulas@users.noreply.github.com> * Update contrib/debian/rules Co-authored-by: Tasos Katsoulas <12612986+tkatsoulas@users.noreply.github.com> * Add license * Enable sentry for debian 12. * Update .github/workflows/packaging.yml Co-authored-by: Austin S. Hemmelgarn <ahferroin7@gmail.com> --------- Signed-off-by: Tasos Katsoulas <tasos@netdata.cloud> Co-authored-by: Tasos Katsoulas <tasos@netdata.cloud> Co-authored-by: Tasos Katsoulas <12612986+tkatsoulas@users.noreply.github.com> Co-authored-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>

vkalintiris committed Jan 30, 2024 at 21:02 UTC 18800a4af578e5440574a7f3621d3ece05a824fe
10 files changed +175 -2
.github/data/distros.yml
+15
@@ -34,6 +34,7 @@ include:
34 support_type: Core
35 notes: ''
36 eol_check: true
37 + bundle_sentry: false
38 - <<: *alpine
39 version: "3.18"
40 support_type: Core
@@ -55,6 +56,7 @@ include:
56 support_type: Intermediate
57 notes: ''
58 eol_check: false
59 + bundle_sentry: false
60 env_prep: |
61 pacman --noconfirm -Syu && pacman --noconfirm -Sy grep libffi
62 test:
@@ -66,6 +68,7 @@ include:
68 support_type: Core
69 notes: ''
70 eol_check: 'amazon-linux'
71 + bundle_sentry: false
72 packages: &amzn_packages
73 type: rpm
74 repo_distro: amazonlinux/2
@@ -89,6 +92,7 @@ include:
92 support_type: Core
93 notes: ''
94 eol_check: false
95 + bundle_sentry: false
96 packages:
97 type: rpm
98 repo_distro: el/7
@@ -110,6 +114,7 @@ include:
114 jsonc_removal: |
115 dnf remove -y json-c-devel
116 eol_check: true
117 + bundle_sentry: false
118 packages: &cs_packages
119 type: rpm
120 repo_distro: el/c9s
@@ -132,6 +137,7 @@ include:
137 notes: ''
138 base_image: debian:bookworm
139 eol_check: true
140 + bundle_sentry: true
141 env_prep: |
142 apt-get update
143 jsonc_removal: |
@@ -149,6 +155,7 @@ include:
155 - <<: *debian
156 version: "11"
157 base_image: debian:bullseye
158 + bundle_sentry: false
159 packages:
160 <<: *debian_packages
161 repo_distro: debian/bullseye
@@ -157,6 +164,7 @@ include:
164 - <<: *debian
165 version: "10"
166 base_image: debian:buster
167 + bundle_sentry: false
168 packages:
169 <<: *debian_packages
170 repo_distro: debian/buster
@@ -169,6 +177,7 @@ include:
177 support_type: Core
178 notes: ''
179 eol_check: true
180 + bundle_sentry: false
181 jsonc_removal: |
182 dnf remove -y json-c-devel
183 packages: &fedora_packages
@@ -193,6 +202,7 @@ include:
202 support_type: Core
203 notes: ''
204 eol_check: true
205 + bundle_sentry: false
206 base_image: opensuse/leap:15.5
207 jsonc_removal: |
208 zypper rm -y libjson-c-devel
@@ -211,6 +221,7 @@ include:
221 support_type: Core
222 notes: ''
223 eol_check: true
224 + bundle_sentry: false
225 jsonc_removal: |
226 dnf remove -y json-c-devel
227 packages: &oracle_packages
@@ -235,6 +246,7 @@ include:
246 jsonc_removal: |
247 dnf remove -y json-c-devel
248 eol_check: true
249 + bundle_sentry: false
250 packages: &rocky_packages
251 type: rpm
252 repo_distro: el/9
@@ -263,6 +275,7 @@ include:
275 support_type: Core
276 notes: ''
277 eol_check: true
278 + bundle_sentry: false
279 env_prep: |
280 rm -f /etc/apt/apt.conf.d/docker && apt-get update
281 jsonc_removal: |
@@ -289,11 +302,13 @@ include:
302 legacy: # Info for platforms we used to support and still need to handle packages for
303 - <<: *fedora
304 version: "37"
305 + bundle_sentry: false
306 packages:
307 <<: *fedora_packages
308 repo_distro: fedora/37
309 - <<: *opensuse
310 version: "15.4"
311 + bundle_sentry: false
312 packages:
313 <<: *opensuse_packages
314 repo_distro: opensuse/15.4
.github/scripts/gen-matrix-packaging.py
+1
@@ -28,6 +28,7 @@ for i, v in enumerate(data['include']):
28 'format': data['include'][i]['packages']['type'],
29 'base_image': data['include'][i]['base_image'] if 'base_image' in data['include'][i] else ':'.join([data['include'][i]['distro'], data['include'][i]['version']]),
30 'platform': data['platform_map'][arch],
31 + 'bundle_sentry': data['include'][i]['bundle_sentry'],
32 'arch': arch
33 })
34
.github/workflows/packaging.yml
+15
@@ -205,6 +205,18 @@ jobs:
205 with:
206 fetch-depth: 0 # We need full history for versioning
207 submodules: recursive
208 + - name: Set Sentry telemetry env vars
209 + id: set-telemetry-env-vars
210 + run: |
211 + if [ "${{ github.repository }}" = 'netdata/netdata' ] && \
212 + [ "${{ matrix.bundle_sentry }}" = 'true' ] && \
213 + [ "${{ github.event_name }}" = 'workflow_dispatch' ]; then
214 + echo "RELEASE_PIPELINE=Production" >> "${GITHUB_ENV}"
215 + echo "UPLOAD_SENTRY=true" >> "${GITHUB_ENV}"
216 + else
217 + echo "RELEASE_PIPELINE=Unknown" >> "${GITHUB_ENV}"
218 + echo "UPLOAD_SENTRY=false" >> "${GITHUB_ENV}"
219 + fi
220 - name: Setup QEMU
221 id: qemu
222 if: matrix.platform != 'linux/amd64' && matrix.platform != 'linux/i386' && needs.file-check.outputs.run == 'true'
@@ -233,6 +245,9 @@ jobs:
245 shell: bash
246 run: |
247 docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e VERSION=${{ needs.version-check.outputs.version }} \
248 + -e ENABLE_SENTRY=${{ matrix.bundle_sentry }} -e RELEASE_PIPELINE=${{ env.RELEASE_PIPELINE }} \
249 + -e BUILD_DESTINATION=${{ matrix.distro }}${{ matrix.version }}_${{ matrix.arch }} -e UPLOAD_SENTRY=${{ env.UPLOAD_SENTRY }} \
250 + -e SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_CLI_TOKEN }} -e SENTRY_DSN=${{ secrets.SENTRY_DSN }} \
251 --platform=${{ matrix.platform }} -v "$PWD":/netdata netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-v1
252 - name: Save Packages
253 id: artifacts
CMakeLists.txt
+26
@@ -115,8 +115,27 @@ option(ENABLE_BUNDLED_PROTOBUF "enable bundled protobuf" False)
115
116 option(ENABLE_LOGS_MANAGEMENT_TESTS "enable logs management tests" True)
117
118 +option(ENABLE_SENTRY "enable sentry" False)
119 option(ENABLE_WEBRTC "enable webrtc" False)
120
121 +if(ENABLE_SENTRY)
122 + include(FetchContent)
123 +
124 + # ignore debhelper
125 + set(FETCHCONTENT_FULLY_DISCONNECTED Off)
126 +
127 + set(SENTRY_VERSION 0.6.6)
128 + set(SENTRY_BACKEND "breakpad")
129 + set(SENTRY_BUILD_SHARED_LIBS OFF)
130 +
131 + FetchContent_Declare(
132 + sentry
133 + URL https://github.com/getsentry/sentry-native/releases/download/${SENTRY_VERSION}/sentry-native.zip
134 + URL_HASH SHA256=7a98467c0b2571380a3afc5e681cb13aa406a709529be12d74610b0015ccde0c
135 + )
136 + FetchContent_MakeAvailable(sentry)
137 +endif()
138 +
139 if(ENABLE_WEBRTC)
140 include(FetchContent)
141
@@ -1305,6 +1324,12 @@ if(LINUX)
1324 ${PROC_PLUGIN_FILES}
1325 ${TC_PLUGIN_FILES}
1326 )
1327 +
1328 + if(ENABLE_SENTRY)
1329 + list(APPEND NETDATA_FILES
1330 + daemon/sentry-native/sentry-native.c
1331 + daemon/sentry-native/sentry-native.h)
1332 + endif()
1333 elseif(MACOS)
1334 list(APPEND NETDATA_FILES
1335 daemon/static_threads_macos.c
@@ -2050,6 +2075,7 @@ target_link_libraries(netdata PRIVATE
2075 "$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_LIBRARIES}>"
2076 "$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_LIBRARIES}>"
2077 "$<$<BOOL:${MACOS}>:${IOKIT};${FOUNDATION}>"
2078 + "$<$<BOOL:${ENABLE_SENTRY}>:sentry>"
2079 "$<$<BOOL:${ENABLE_WEBRTC}>:LibDataChannel::LibDataChannelStatic>"
2080 )
2081
config.cmake.h.in
+7
@@ -110,6 +110,13 @@
110 #cmakedefine ENABLE_PLUGIN_CGROUP_NETWORK
111 #cmakedefine ENABLE_PLUGIN_EBPF
112
113 +// enabled sentry
114 +
115 +#cmakedefine ENABLE_SENTRY
116 +#cmakedefine NETDATA_SENTRY_ENVIRONMENT "@NETDATA_SENTRY_ENVIRONMENT@"
117 +#cmakedefine NETDATA_SENTRY_RELEASE "@NETDATA_SENTRY_RELEASE@"
118 +#cmakedefine NETDATA_SENTRY_DIST "@NETDATA_SENTRY_DIST@"
119 +#cmakedefine NETDATA_SENTRY_DSN "@NETDATA_SENTRY_DSN@"
120 // enabled bundling
121
122 #cmakedefine ENABLE_BUNDLED_JSONC
contrib/debian/rules
+23
@@ -2,6 +2,7 @@
2
3 # Find the arch we are building for, as this determines
4 # the location of plugins in /usr/lib
5 +SRC_DIR = /usr/src/netdata
6 TOP = $(CURDIR)/debian/netdata
7 TEMPTOP = $(CURDIR)/debian/tmp
8 BUILDDIR = $(CURDIR)/debian/build
@@ -37,6 +38,20 @@ HAVE_XENSTAT = 1
38 XENSTAT_CONFIG = -DENABLE_PLUGIN_XENSTAT=On
39 endif
40
41 +ifeq ($(ENABLE_SENTRY),true)
42 + RELEASE_PIPELINE ?= Unknown
43 + VERSION ?= Unknown
44 + BUILD_DESTINATION ?= Unknown
45 + SENTRY_CONFIG := -DENABLE_SENTRY=On \
46 + -DNETDATA_SENTRY_ENVIRONMENT=$(RELEASE_PIPELINE) \
47 + -DNETDATA_SENTRY_RELEASE=$(VERSION) \
48 + -DNETDATA_SENTRY_DIST=$(BUILD_DESTINATION) \
49 + -DNETDATA_SENTRY_DSN=$(SENTRY_DSN)
50 +else
51 + SENTRY_CONFIG := -DENABLE_SENTRY=Off
52 +endif
53 +
54 +
55 %:
56 dh $@ --builddirectory=$(BUILDDIR)
57
@@ -56,6 +71,7 @@ override_dh_auto_configure:
71 dh_auto_configure -- -G Ninja \
72 -DCMAKE_INSTALL_PREFIX=/ \
73 -DWEB_DIR=/var/lib/netdata/www \
74 + -DCMAKE_C_FLAGS='-ffile-prefix-map=${SRC_DIR}=${SRC_DIR}' \
75 -DENABLE_ACLK=On \
76 -DENABLE_CLOUD=On \
77 -DENABLE_DBENGINE=On \
@@ -77,11 +93,18 @@ override_dh_auto_configure:
93 -DENABLE_EXPORTER_MONGODB=On \
94 -DENABLE_BUNDLED_PROTOBUF=Off \
95 -DENABLE_BUNDLED_JSONC=Off \
96 + ${SENTRY_CONFIG} \
97 -DENABLE_BUNDLED_YAML=Off
98
99 override_dh_auto_test:
100 true
101
102 +override_dh_strip:
103 + if [ "${ENABLE_SENTRY}" = "true" ] && [ "${UPLOAD_SENTRY}" = "true" ]; then \
104 + sentry-cli debug-files upload -o netdata-inc -p netdata-agent --force-foreground --log-level=debug --wait --include-sources /usr/src/netdata/debian/netdata/usr/sbin/netdata; \
105 + fi
106 + dh_strip
107 +
108 override_dh_install:
109 cp -v $(BASE_CONFIG) debian/netdata.conf
110
daemon/main.c
+13 -1
@@ -6,6 +6,10 @@
6
7 #include "database/engine/page_test.h"
8
9 +#ifdef ENABLE_SENTRY
10 +#include "sentry-native/sentry-native.h"
11 +#endif
12 +
13 #if defined(ENV32BIT)
14 #warning COMPILING 32BIT NETDATA
15 #endif
@@ -510,6 +514,10 @@ void netdata_cleanup_and_exit(int ret, const char *action, const char *action_re
514
515 delta_shutdown_time("exit");
516
517 +#ifdef ENABLE_SENTRY
518 + sentry_native_fini();
519 +#endif
520 +
521 usec_t ended_ut = now_monotonic_usec();
522 netdata_log_info("NETDATA SHUTDOWN: completed in %llu ms - netdata is now exiting - bye bye...", (ended_ut - started_ut) / USEC_PER_MS);
523 exit(ret);
@@ -1890,7 +1898,6 @@ int main(int argc, char **argv) {
1898 for_each_open_fd(OPEN_FD_ACTION_CLOSE, OPEN_FD_EXCLUDE_STDIN | OPEN_FD_EXCLUDE_STDOUT | OPEN_FD_EXCLUDE_STDERR);
1899 }
1900
1893 -
1901 if(!config_loaded) {
1902 load_netdata_conf(NULL, 0, &user);
1903 load_cloud_conf(0);
@@ -2099,6 +2106,11 @@ int main(int argc, char **argv) {
2106 if(become_daemon(dont_fork, user) == -1)
2107 fatal("Cannot daemonize myself.");
2108
2109 + // init sentry
2110 +#ifdef ENABLE_SENTRY
2111 + sentry_native_init();
2112 +#endif
2113 +
2114 // The "HOME" env var points to the root's home dir because Netdata starts as root. Can't use "HOME".
2115 struct passwd *pw = getpwuid(getuid());
2116 if (config_exists(CONFIG_SECTION_DIRECTORIES, "home") || !pw || !pw->pw_dir) {
daemon/sentry-native/sentry-native.c new
+51
@@ -0,0 +1,51 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "sentry-native.h"
4 +#include "daemon/common.h"
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 +
22 +void sentry_native_init(void)
23 +{
24 + if (sentry_telemetry_disabled())
25 + return;
26 +
27 + // path where sentry should save stuff
28 + char path[FILENAME_MAX];
29 + snprintfz(path, FILENAME_MAX - 1, "%s/%s", netdata_configured_cache_dir, ".sentry-native");
30 +
31 + sentry_options_t *options = sentry_options_new();
32 + sentry_options_set_dsn(options, NETDATA_SENTRY_DSN);
33 + sentry_options_set_database_path(options, path);
34 + sentry_options_set_auto_session_tracking(options, false);
35 + sentry_options_set_environment(options, NETDATA_SENTRY_ENVIRONMENT);
36 + sentry_options_set_release(options, NETDATA_SENTRY_RELEASE);
37 + sentry_options_set_dist(options, NETDATA_SENTRY_DIST);
38 +#ifdef NETDATA_INTERNAL_CHECKS
39 + sentry_options_set_debug(options, 1);
40 +#endif
41 +
42 + sentry_init(options);
43 +}
44 +
45 +void sentry_native_fini(void)
46 +{
47 + if (sentry_telemetry_disabled())
48 + return;
49 +
50 + sentry_close();
51 +}
daemon/sentry-native/sentry-native.h new
+9
@@ -0,0 +1,9 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef SENTRY_NATIVE_H
4 +#define SENTRY_NATIVE_H
5 +
6 +void sentry_native_init(void);
7 +void sentry_native_fini(void);
8 +
9 +#endif /* SENTRY_NATIVE_H */
integrations/schemas/distros.json
+15 -1
@@ -77,6 +77,19 @@
77 }
78 ]
79 },
80 + "bundle_sentry": {
81 + "description": "Set to true to build an Agent with Sentry telemetry from the CI.",
82 + "oneOf": [
83 + {
84 + "type": "boolean",
85 + "default": false
86 + },
87 + {
88 + "type": "string",
89 + "pattern": "^[a-z][a-z0-9._-]*$"
90 + }
91 + ]
92 + },
93 "base_image": {
94 "type": "string",
95 "description": "A string specifying the Docker image to be used for testing this platform.",
@@ -146,7 +159,8 @@
159 "distro",
160 "version",
161 "support_type",
149 - "notes"
162 + "notes",
163 + "bundle_sentry"
164 ]
165 }
166 }