1
0
Fork 0

Adjust how we enable/disable Sentry.io

This allows for crash-reporting in the launcher,
but still disabling via default.xml or the command line.
This commit is contained in:
Automatic Release Builder 2020-08-17 13:10:12 +01:00 committed by James Turner
parent 04ee8c34a4
commit 439c5bf4f4
6 changed files with 58 additions and 5 deletions

View file

@ -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);
}
}
}

View file

@ -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

View file

@ -881,6 +881,8 @@ bool fgInitGeneral() {
sgUserDataInit( globals->get_props() );
flightgear::delayedSentryInit();
return true;
}

View file

@ -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 },

View file

@ -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;

View file

@ -27,6 +27,8 @@ void initSentry();
void shutdownSentry();
void delayedSentryInit();
bool isSentryEnabled();
void addSentryBreadcrumb(const std::string& msg, const std::string& level);