Skip to content

Commit 18b58b2

Browse files
committed
WIP sentry support
1 parent c0e2d1f commit 18b58b2

8 files changed

Lines changed: 42 additions & 10 deletions

File tree

nix-meson-build-support/common/assert-fail/meson.build

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ can_wrap_assert_fail = cxx.links(
2424
name : 'linker can wrap __assert_fail',
2525
)
2626

27-
if can_wrap_assert_fail
28-
deps_other += declare_dependency(
29-
sources : 'wrap-assert-fail.cc',
30-
link_args : wrap_assert_fail_args,
31-
)
32-
endif
27+
#if can_wrap_assert_fail
28+
# deps_other += declare_dependency(
29+
# sources : 'wrap-assert-fail.cc',
30+
# link_args : wrap_assert_fail_args,
31+
# )
32+
#endif

packaging/dependencies.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,9 @@ scope: {
147147
pslSupport = !stdenv.hostPlatform.isStatic;
148148
idnSupport = !stdenv.hostPlatform.isStatic;
149149
};
150+
151+
sentry-native = pkgs.sentry-native.override {
152+
# Avoid having two curls in our closure.
153+
inherit (scope) curl;
154+
};
150155
}

packaging/everything.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
testers,
4545

4646
patchedSrc ? null,
47+
48+
curl,
49+
boehmgc,
50+
sentry-native,
4751
}:
4852

4953
let
@@ -155,7 +159,7 @@ stdenv.mkDerivation (finalAttrs: {
155159
let
156160
devPaths = lib.mapAttrsToList (_k: lib.getDev) finalAttrs.finalPackage.libs;
157161
debugPaths = lib.map (lib.getOutput "debug") (
158-
lib.attrValues finalAttrs.finalPackage.libs ++ [ nix-cli ]
162+
lib.attrValues finalAttrs.finalPackage.libs ++ [ nix-cli curl boehmgc sentry-native ]
159163
);
160164
in
161165
''

src/libmain/unix/stack.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void sigsegvHandler(int signo, siginfo_t * info, void * ctx)
4545

4646
void detectStackOverflow()
4747
{
48-
#if defined(SA_SIGINFO) && defined(SA_ONSTACK)
48+
#if defined(SA_SIGINFO) && defined(SA_ONSTACK) && 0
4949
/* Install a SIGSEGV handler to detect stack overflows. This
5050
requires an alternative stack, otherwise the signal cannot be
5151
delivered when we're out of stack space. */

src/nix/main.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sys/types.h>
3030
#include <regex>
3131
#include <nlohmann/json.hpp>
32+
#include <sentry.h>
3233

3334
#ifndef _WIN32
3435
# include <sys/socket.h>
@@ -378,7 +379,24 @@ void mainWrapped(int argc, char ** argv)
378379
{
379380
savedArgv = argv;
380381

381-
registerCrashHandler();
382+
bool sentryEnabled = false;
383+
384+
if (getEnv("NIX_DISABLE_SENTRY").value_or("") != "1") {
385+
sentry_options_t * options = sentry_options_new();
386+
sentry_options_set_dsn(
387+
options, "https://ca42fa4b6b08ae1caf3d96b998af6bac@o4506062689927168.ingest.us.sentry.io/4511151087878144");
388+
sentry_options_set_database_path(options, (getCacheDir() / "sentry").string().c_str());
389+
sentry_options_set_release(options, fmt("nix@%s", determinateNixVersion).c_str());
390+
sentry_options_set_traces_sample_rate(options, 0);
391+
sentry_options_set_auto_session_tracking(options, false);
392+
sentry_init(options);
393+
sentryEnabled = true;
394+
}
395+
396+
Finally cleanupSentry([]() { sentry_shutdown(); });
397+
398+
if (!sentryEnabled)
399+
registerCrashHandler();
382400

383401
/* The chroot helper needs to be run before any threads have been
384402
started. */

src/nix/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ this_exe = executable(
191191
sources,
192192
dependencies : deps_private_subproject + deps_private + deps_other,
193193
include_directories : include_dirs,
194-
link_args : linker_export_flags,
194+
link_args : linker_export_flags + [ '-lsentry' ],
195195
install : true,
196196
cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [],
197197
)

src/nix/package.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
nix-expr,
99
nix-main,
1010
nix-cmd,
11+
sentry-native,
1112

1213
# Configuration Options
1314

@@ -70,6 +71,7 @@ mkMesonExecutable (finalAttrs: {
7071
nix-expr
7172
nix-main
7273
nix-cmd
74+
sentry-native
7375
]
7476
++ lib.optional (
7577
stdenv.cc.isClang

tests/functional/common/init.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# for shellcheck
44
: "${test_nix_conf_dir?}" "${test_nix_conf?}"
55

6+
# Don't upload crashes from tests to Sentry.
7+
export NIX_DISABLE_SENTRY=1
8+
69
if isTestOnNixOS; then
710

811
mkdir -p "$test_nix_conf_dir" "$TEST_HOME"

0 commit comments

Comments
 (0)