diff --git a/src/GUI/qml/Settings.qml b/src/GUI/qml/Settings.qml index 360e4f825..858b8d929 100644 --- a/src/GUI/qml/Settings.qml +++ b/src/GUI/qml/Settings.qml @@ -136,7 +136,9 @@ Item { onApply: { if (!showConsoleWin.hidden && showConsoleWin.checked) _config.setArg("console"); - if (!enableCrashReporting.hidden && enableCrashReporting.checked) _config.setArg("enable-sentry"); + if (!enableCrashReporting.hidden) { + _config.setEnableDisableOption("sentry", enableCrashReporting.checked); + } } } diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index d6295dc0f..7d4119761 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -266,9 +266,7 @@ int main ( int argc, char **argv ) _bootstrap_OSInit = 0; #if defined(HAVE_SENTRY) - if (flightgear::Options::checkForArg(argc, argv, "enable-sentry")) { - flightgear::initSentry(); - } + flightgear::initSentry(); #endif // if we're not using the normal crash-reported, install our diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 914a557d9..514ef684d 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -881,6 +881,8 @@ bool fgInitGeneral() { sgUserDataInit( globals->get_props() ); + flightgear::delayedSentryInit(); + return true; } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 9bf164a7f..8c8cbbcd8 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -1650,7 +1650,8 @@ struct OptionDesc { {"language", true, OPTION_IGNORE, "", false, "", 0 }, {"console", false, OPTION_FUNC, "", false, "", fgOptConsole }, {"launcher", false, OPTION_IGNORE, "", false, "", 0 }, - {"enable-sentry", false, OPTION_IGNORE, "", false, "", nullptr }, + {"enable-sentry", false, OPTION_BOOL, "/sim/startup/sentry-crash-reporting-enabled", true, "", nullptr }, + {"disable-sentry", false, OPTION_BOOL, "/sim/startup/sentry-crash-reporting-enabled", false, "", nullptr }, {"allow-nasal-from-sockets", false, OPTION_IGNORE, "", false, "", 0 }, {"disable-rembrandt", false, OPTION_BOOL, "/sim/rendering/rembrandt/enabled", false, "", 0 }, {"enable-rembrandt", false, OPTION_BOOL, "/sim/rendering/rembrandt/enabled", true, "", 0 }, diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx index e2fcc03e8..195f8b6a0 100644 --- a/src/Main/sentryIntegration.cxx +++ b/src/Main/sentryIntegration.cxx @@ -20,10 +20,15 @@ #include "sentryIntegration.hxx" +#include <simgear/debug/logstream.hxx> #include <simgear/misc/sg_path.hxx> +#include <simgear/props/props.hxx> +#include <simgear/structure/commands.hxx> #include <Include/version.h> #include <Main/fg_init.hxx> +#include <Main/fg_props.hxx> +#include <Main/globals.hxx> using namespace std; @@ -37,6 +42,29 @@ static bool static_sentryEnabled = false; namespace flightgear { +bool sentryReportCommand(const SGPropertyNode* args, SGPropertyNode* root) +{ + if (!static_sentryEnabled) { + SG_LOG(SG_GENERAL, SG_WARN, "Sentry.io not enabled at startup"); + return false; + } + + sentry_value_t exc = sentry_value_new_object(); + sentry_value_set_by_key(exc, "type", sentry_value_new_string("Report")); + + const string message = args->getStringValue("message"); + sentry_value_set_by_key(exc, "value", sentry_value_new_string(message.c_str())); + + sentry_value_t event = sentry_value_new_event(); + sentry_value_set_by_key(event, "exception", exc); + // capture the C++ stack-trace. Probably not that useful but can't hurt + sentry_event_value_add_stacktrace(event, nullptr, 0); + + sentry_capture_event(event); + + return true; +} + void initSentry() { sentry_options_t *options = sentry_options_new(); @@ -70,6 +98,22 @@ void initSentry() static_sentryEnabled = true; } +void delayedSentryInit() +{ + if (!static_sentryEnabled) + return; + + // allow the user to opt-out of sentry.io features + if (!fgGetBool("/sim/startup/sentry-crash-reporting-enabled", true)) { + SG_LOG(SG_GENERAL, SG_INFO, "Disabling Sentry.io reporting"); + sentry_shutdown(); + static_sentryEnabled = false; + return; + } + + globals->get_commands()->addCommand("sentry-report", &sentryReportCommand); +} + void shutdownSentry() { if (static_sentryEnabled) { @@ -150,6 +194,10 @@ void shutdownSentry() { } +void delayedSentryInit() +{ +} + bool isSentryEnabled() { return false; diff --git a/src/Main/sentryIntegration.hxx b/src/Main/sentryIntegration.hxx index 5b4d6cfe2..cfbb436dc 100644 --- a/src/Main/sentryIntegration.hxx +++ b/src/Main/sentryIntegration.hxx @@ -27,6 +27,8 @@ void initSentry(); void shutdownSentry(); +void delayedSentryInit(); + bool isSentryEnabled(); void addSentryBreadcrumb(const std::string& msg, const std::string& level);