Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "nix/util/error.hh"
#include "nix/util/sentry.hh"

#include <cstdio>
#include <cstdlib>
Expand All @@ -13,5 +14,6 @@ __wrap___assert_fail(const char * assertion, const char * file, unsigned int lin
snprintf(buf, sizeof(buf), "Assertion '%s' failed in %s at %s:%" PRIuLEAST32, assertion, function, file, line);
if (n < 0)
nix::panic("Assertion failed and could not format error message");
nix::panic(std::string_view(buf, std::min(static_cast<int>(sizeof(buf)), n)));
nix::setSentryTag("assertion", buf);
nix::panic(buf);
}
1 change: 1 addition & 0 deletions src/libutil/include/nix/util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ headers = [ config_pub_h ] + files(
'ref.hh',
'regex-combinators.hh',
'repair-flag.hh',
'sentry.hh',
'serialise.hh',
'signals.hh',
'signature/local-keys.hh',
Expand Down
9 changes: 9 additions & 0 deletions src/libutil/include/nix/util/sentry.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "nix/util/fun.hh"

namespace nix {

extern fun<void(const char *, const char *)> setSentryTag;

}
2 changes: 2 additions & 0 deletions src/libutil/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,6 @@ std::pair<std::string_view, std::string_view> getLine(std::string_view s)
}
}

fun<void(const char *, const char *)> setSentryTag = [](const char *, const char *) {};

} // namespace nix
9 changes: 4 additions & 5 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "nix/flake/flake.hh"
#include "nix/flake/settings.hh"
#include "nix/util/json-utils.hh"
#include "nix/util/sentry.hh"

#include "self-exe.hh"
#include "crash-handler.hh"
Expand Down Expand Up @@ -420,7 +421,8 @@ void mainWrapped(int argc, char ** argv)
sentry_options_set_auto_session_tracking(options, false);
sentry_options_set_handler_path(options, CRASHPAD_HANDLER_PATH);
sentry_init(options);
sentry_set_tag("nix_command", argc > 0 ? std::string(baseNameOf(argv[0])).c_str() : "");
setSentryTag = [](const char * key, const char * value) { sentry_set_tag(key, value); };
setSentryTag("nix_command", argc > 0 ? std::string(baseNameOf(argv[0])).c_str() : "");
sentryEnabled = true;
}

Expand Down Expand Up @@ -629,10 +631,7 @@ void mainWrapped(int argc, char ** argv)
evalSettings.pureEval = false;
}

#if HAVE_SENTRY
if (sentryEnabled)
sentry_set_tag("nix_subcommand", concatStringsSep(" ", subcommand).c_str());
#endif
setSentryTag("nix_subcommand", concatStringsSep(" ", subcommand).c_str());

try {
args.command->second->run();
Expand Down
Loading