|
From: <fli...@li...> - 2026-05-03 09:49:49
|
unknown user pushed a commit to branch release/2024.1
in repository flightgear.
The following commit(s) were added to refs/heads/release/2024.1 by this push:
new eb41dd5ab Use Sentry's real logging support
eb41dd5ab is described below
SF URL: http://sourceforge.net/p/flightgear/flightgear/ci/eb41dd5ab3ec99c1a00828dead065e8c9debf1aa/
Commit: eb41dd5ab3ec99c1a00828dead065e8c9debf1aa
Author: James Turner
Committer: James Turner
AuthorDate: Tue Apr 28 13:07:34 2026 +0100
Use Sentry's real logging support
---
CMakeLists.txt | 15 +++--
src/Main/ErrorReporter.cxx | 8 ++-
src/Main/sentryIntegration.cxx | 149 +++++++++++++++++------------------------
src/Main/sentryIntegration.hxx | 16 ++++-
4 files changed, 91 insertions(+), 97 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 985d9a3fb..138e39731 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -305,7 +305,8 @@ find_package(OpenSceneGraph 3.6.0 REQUIRED
##############################################################################
## Sentry.io setup
if (ENABLE_SENTRY)
- find_package(sentry QUIET)
+ # logging API needs sentry-native >= 0.11.1
+ find_package(sentry 0.11.1 QUIET)
# Worth nothing that while this *looks* sketchy, DSNs are fundamentally public ingestion
# endpoints and not truly protectable secrets.
@@ -315,7 +316,7 @@ if (ENABLE_SENTRY)
message(STATUS "Sentry.io crash reporting enabled")
set(HAVE_SENTRY 1)
else()
- message(STATUS "Sentry.io crash reporting disabled, Sentry SDK not found")
+ message(STATUS "Sentry.io crash reporting disabled, Sentry SDK not found (required version is 0.11.1 or higher)")
endif()
else()
message(STATUS "Sentry.io crash reporting disabled")
@@ -374,7 +375,7 @@ if (ENABLE_QT)
# short-circuit the check in FindWrapOpenGL.cmake, to avoid looking for
# AGL.frameowkr, which is removed from the Apple SDKs now
set(WrapOpenGL_AGL "-framework OpenGL")
-
+
find_package(QT NAMES ${qtNames} COMPONENTS Core)
if (QT_FOUND)
if (${QT_VERSION_MAJOR} EQUAL "5")
@@ -385,7 +386,7 @@ if (ENABLE_QT)
if (NOT Qt${QT_VERSION_MAJOR}Widgets_FOUND)
message(FATAL_ERROR "Qt support enabled, Qt was found but some required packages are missing, stopping.")
endif()
-
+
set(HAVE_QT 1)
include (Translations)
@@ -397,7 +398,7 @@ if (ENABLE_QT)
endif()
set(CMAKE_AUTOMOC OFF)
-
+
message(STATUS "Qt GUI enabled, found Qt at: ${FG_QT_ROOT_DIR}")
else()
message(STATUS "Qt support disabled, Qt/qmake not found in PATH/CMAKE_PREFIX_PATH")
@@ -425,7 +426,7 @@ message(STATUS "Min Simgear version is ${MIN_SIMGEAR_VERSION}")
if (TARGET SimGearCore)
message(STATUS "Simgear targets exist, assuming superbuild")
- # since we don't find(SimGear), we need to
+ # since we don't find(SimGear), we need to
# find a few dependencies directly
if (SG_SOUND_USES_OPENALSOFT)
message((STATUS "Finding OpenAL"))
@@ -468,7 +469,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
if(HAVE_QT)
- # if Qt is built with reduce-relocations, applicatino code
+ # if Qt is built with reduce-relocations, applicatino code
# needs to be compiled with -fPIC to match
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
diff --git a/src/Main/ErrorReporter.cxx b/src/Main/ErrorReporter.cxx
index a952321b3..3b56cbaf8 100644
--- a/src/Main/ErrorReporter.cxx
+++ b/src/Main/ErrorReporter.cxx
@@ -513,10 +513,16 @@ public:
}
}
+ std::vector<SentryExceptionData> occurrences;
+ for (const auto& e : report.errors) {
+ const auto m = static_errorIds.at(static_cast<int>(e.code)) + "-" + static_errorTypeIds.at(static_cast<int>(e.type));
+ occurrences.emplace_back(m, e.detailedInfo, e.origin.asString());
+ }
+
const int catId = static_cast<int>(report.type);
flightgear::sentryReportUserError(static_categoryIds.at(catId),
report.parameter,
- _displayNode->getStringValue());
+ occurrences);
}
void writeReportToStream(const AggregateReport& report, std::ostream& os) const;
diff --git a/src/Main/sentryIntegration.cxx b/src/Main/sentryIntegration.cxx
index 914a000f9..22de885b0 100644
--- a/src/Main/sentryIntegration.cxx
+++ b/src/Main/sentryIntegration.cxx
@@ -84,10 +84,9 @@ void sentryTraceSimgearThrow(const std::string& msg, const std::string& origin,
return;
}
- sentry_value_t exc = sentry_value_new_object();
- sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception"));
+ sentry_value_t exc = sentry_value_new_exception("Exception", msg.c_str());
+ sentry_value_set_stacktrace(exc, NULL, 0);
- std::string message = msg;
sentry_value_t info = sentry_value_new_object();
if (!origin.empty()) {
sentry_value_set_by_key(info, "origin", sentry_value_new_string(origin.c_str()));
@@ -99,12 +98,9 @@ void sentryTraceSimgearThrow(const std::string& msg, const std::string& origin,
}
sentry_set_context("what", info);
- 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);
-
- sentry_event_value_add_stacktrace(event, nullptr, 0);
+ sentry_event_add_exception(event, exc);
sentry_capture_event(event);
}
@@ -120,30 +116,40 @@ public:
// we need original priority here, so we don't record MANDATORY_INFO
// or DEV_ messages, which would get noisy.
const auto op = e.originalPriority;
- if ((op != SG_WARN) && (op != SG_ALERT)) {
- return true;
+ if ((op == SG_MANDATORY_INFO) || (op == SG_DEV_WARN) || (op == SG_DEV_ALERT)) {
+ return false;
}
if ((e.debugClass == SG_OSG) && doesStringMatchPrefixes(e.message, OSG_messageWhitelist)) {
- return true;
+ return false;
}
if (doesStringMatchPrefixes(e.message, general_messageWhitelist)) {
- return true;
+ return false;
}
- if (e.message == _lastLoggedMessage) {
- _lastLoggedCount++;
- return true;
- }
+ const auto message = e.message.c_str();
+ switch (e.debugPriority) {
+ case SG_INFO:
+ sentry_log_info(message);
+ break;
+
+ case SG_WARN:
+ sentry_log_warn(message);
+ break;
+
+ case SG_ALERT:
+ sentry_log_error(message);
+ break;
- if (_lastLoggedCount > 0) {
- flightgear::addSentryBreadcrumb("(repeats " + std::to_string(_lastLoggedCount) + " times)", "info");
- _lastLoggedCount = 0;
+ case SG_DEBUG:
+ sentry_log_debug(message);
+ break;
+
+ default:
+ return false;
}
- _lastLoggedMessage = e.message;
- flightgear::addSentryBreadcrumb(e.message, (op == SG_WARN) ? "warning" : "error");
return true;
}
@@ -178,33 +184,22 @@ void sentrySimgearReportCallback(const std::string& msg, const std::string& more
}
}
- sentry_value_t exc = sentry_value_new_object();
- if (isFatal) {
- sentry_value_set_by_key(exc, "type", sentry_value_new_string("Fatal Error"));
- } else {
- sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception"));
- }
-
- sentry_value_set_by_key(exc, "value", sentry_value_new_string(msg.c_str()));
+ sentry_value_t exc = sentry_value_new_exception(isFatal ? "Fatal Error" : "Exception", msg.c_str());
+ sentry_value_set_stacktrace(exc, NULL, 0);
sentry_value_t event = sentry_value_new_event();
- sentry_value_set_by_key(event, "exception", exc);
-
- sentry_event_value_add_stacktrace(event, nullptr, 0);
+ sentry_event_add_exception(event, exc);
sentry_capture_event(event);
}
void sentryReportBadAlloc()
{
if (simgear::ReportBadAllocGuard::isSet()) {
- sentry_value_t sentryMessage = sentry_value_new_object();
- sentry_value_set_by_key(sentryMessage, "type", sentry_value_new_string("Fatal Error"));
- sentry_value_set_by_key(sentryMessage, "formatted", sentry_value_new_string("bad allocation"));
+ sentry_value_t exc = sentry_value_new_exception("Fatal Error", "bad allocation");
+ sentry_value_set_stacktrace(exc, NULL, 0);
sentry_value_t event = sentry_value_new_event();
- sentry_value_set_by_key(event, "message", sentryMessage);
-
- sentry_event_value_add_stacktrace(event, nullptr, 0);
+ sentry_event_add_exception(event, exc);
sentry_capture_event(event);
}
@@ -222,18 +217,11 @@ bool sentryReportCommand(const SGPropertyNode* args, SGPropertyNode* root)
return false;
}
- sentry_value_t exc = sentry_value_new_object();
- sentry_value_set_by_key(exc, "type", sentry_value_new_string("Report"));
-
const auto 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);
+ // TODO: make the level settable via an argument?
+ sentry_value_t msgEv = sentry_value_new_message_event(SENTRY_LEVEL_INFO, nullptr, message.c_str());
+ sentry_capture_event(msgEv);
return true;
}
@@ -302,9 +290,10 @@ void initSentry(bool quiet)
// unknown build type
sentry_options_set_environment(options, "dev");
}
-
+
const auto buildString = std::to_string(JENKINS_BUILD_NUMBER);
sentry_options_set_dist(options, buildString.c_str());
+ sentry_options_set_enable_logs(options, 1);
// for dev / nightly builds, put Sentry in debug mode
if (!quiet && strcmp(FG_BUILD_TYPE, "Release")) {
@@ -378,7 +367,7 @@ void delayedSentryInit()
// 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();
+ sentry_close();
static_sentryEnabled = false;
return;
}
@@ -394,7 +383,7 @@ void delayedSentryInit()
void shutdownSentry()
{
if (static_sentryEnabled) {
- sentry_shutdown();
+ sentry_close();
static_sentryEnabled = false;
}
}
@@ -471,23 +460,13 @@ void sentryReportException(const std::string& msg, const std::string& location)
if (!static_sentryEnabled)
return;
- sentry_value_t exc = sentry_value_new_object();
- sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception"));
-
+ sentry_value_t exc = sentry_value_new_exception("Exception", msg.c_str());
+ sentry_value_set_stacktrace(exc, NULL, 0);
- sentry_value_t info = sentry_value_new_object();
- if (!location.empty()) {
- sentry_value_set_by_key(info, "location", sentry_value_new_string(location.c_str()));
- }
- sentry_set_context("what", info);
-
- sentry_value_set_by_key(exc, "value", sentry_value_new_string(msg.c_str()));
+ sentry_value_set_by_key(exc, "location", sentry_value_new_string(location.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_event_add_exception(event, exc);
sentry_capture_event(event);
}
@@ -496,45 +475,38 @@ void sentryReportFatalError(const std::string& msg, const std::string& more)
if (!static_sentryEnabled)
return;
- sentry_value_t sentryMessage = sentry_value_new_object();
- sentry_value_set_by_key(sentryMessage, "type", sentry_value_new_string("Fatal Error"));
+ sentry_value_t exc = sentry_value_new_exception("FatalError", msg.c_str());
+ sentry_value_set_stacktrace(exc, NULL, 0);
- sentry_value_t info = sentry_value_new_object();
if (!more.empty()) {
- sentry_value_set_by_key(info, "more", sentry_value_new_string(more.c_str()));
+ sentry_value_set_by_key(exc, "more", sentry_value_new_string(more.c_str()));
}
- sentry_set_context("what", info);
- sentry_value_set_by_key(sentryMessage, "formatted", sentry_value_new_string(msg.c_str()));
-
sentry_value_t event = sentry_value_new_event();
- sentry_value_set_by_key(event, "message", sentryMessage);
-
- sentry_event_value_add_stacktrace(event, nullptr, 0);
+ sentry_event_add_exception(event, exc);
sentry_capture_event(event);
}
-void sentryReportUserError(const std::string& aggregate, const std::string& parameter, const std::string& details)
+void sentryReportUserError(const std::string& aggregate, const std::string& parameter,
+ const std::vector<SentryExceptionData>& exceptions)
{
- if (!static_sentryEnabled)
- return;
-
- sentry_value_t sentryMessage = sentry_value_new_object();
- sentry_value_set_by_key(sentryMessage, "type", sentry_value_new_string("Error"));
-
- sentry_value_t info = sentry_value_new_object();
- sentry_value_set_by_key(info, "details", sentry_value_new_string(details.c_str()));
-
- sentry_set_context("what", info);
+ sentry_value_t event = sentry_value_new_event();
auto m = aggregate;
if (!parameter.empty()) {
m += ":" + parameter;
}
- sentry_value_t event = sentry_value_new_event();
- sentry_value_set_by_key(event, "message", sentry_value_new_string(m.c_str()));
+ sentry_value_set_by_key(event, "aggregate", sentry_value_new_string(m.c_str()));
+ for (const auto& ex : exceptions) {
+ sentry_value_t exc = sentry_value_new_exception(ex.type.c_str(), ex.value.c_str());
+ if (!ex.location.empty()) {
+ sentry_value_set_by_key(exc, "location", sentry_value_new_string(ex.location.c_str()));
+ }
+
+ sentry_event_add_exception(event, exc);
+ }
sentry_capture_event(event);
}
@@ -594,7 +566,8 @@ void sentryReportFatalError(const std::string&, const std::string&)
{
}
-void sentryReportUserError(const std::string&, const std::string&, const std::string&)
+void sentryReportUserError(const std::string& aggregate, const std::string& parameter,
+ const std::vector<SentryExceptionData>& exceptions)
{
}
diff --git a/src/Main/sentryIntegration.hxx b/src/Main/sentryIntegration.hxx
index d75ae19f9..e9bdbe412 100644
--- a/src/Main/sentryIntegration.hxx
+++ b/src/Main/sentryIntegration.hxx
@@ -33,7 +33,21 @@ void sentryReportException(const std::string& msg, const std::string& location =
void sentryReportFatalError(const std::string& msg, const std::string& more = {});
-void sentryReportUserError(const std::string& aggregate, const std::string& parameter, const std::string& details);
+/**
+ * information about a specific error / failure, to be sent as part of a user-facing
+ * error.
+ */
+struct SentryExceptionData {
+ SentryExceptionData(const std::string& type, const std::string& value, const std::string& location)
+ : type(type), value(value), location(location) {}
+
+ std::string type;
+ std::string value;
+ std::string location;
+};
+
+void sentryReportUserError(const std::string& aggregate, const std::string& parameter,
+ const std::vector<SentryExceptionData>& exceptions);
/**
* @brief retrive the anonymous user ID (a UUID) for this installation.
|