From 911589111e1774a66c66c11013c41b78b523445b Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 21 Sep 2021 11:29:48 -0300 Subject: [PATCH] Add Sentry as an alternative to handling minidumps manually (#2857) --- CMakeLists.txt | 6 ++++++ src/app/CMakeLists.txt | 14 +++++++++++++- src/app/app.cpp | 2 ++ src/app/send_crash.h | 6 +++++- src/main/main.cpp | 36 +++++++++++++++++++++++++++++++++++- 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 749f8359c..3af0bd074 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,8 +79,14 @@ option(ENABLE_UI "Compile UI (turn off to compile CLI-only version)" o option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off) option(ENABLE_CLANG_TIDY "Enable static analysis" off) option(ENABLE_CCACHE "Use CCache to improve recompilation speed (optional)" on) +option(ENABLE_SENTRY "Use Sentry SDK to report crashes" off) set(CUSTOM_WEBSITE_URL "" CACHE STRING "Enable custom local webserver to check updates") +if(ENABLE_SENTRY) + set(SENTRY_DIR "" CACHE STRING "Sentry native location") + set(SENTRY_DNS "" CACHE STRING "Sentry DNS URL") +endif() + if(ENABLE_NEWS OR ENABLE_UPDATER) set(REQUIRE_CURL ON) else() diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 826072348..24af3321d 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -402,6 +402,11 @@ if(ENABLE_UI) endif() endif() +set(send_crash_files) +if(NOT ENABLE_SENTRY) + set(send_crash_files send_crash.cpp) +endif() + add_library(app-lib active_site_handler.cpp app.cpp @@ -575,7 +580,6 @@ add_library(app-lib res/resources_loader.cpp resource_finder.cpp restore_visible_layers.cpp - send_crash.cpp shade.cpp site.cpp snap_to_grid.cpp @@ -617,6 +621,7 @@ add_library(app-lib util/wrap_point.cpp xml_document.cpp xml_exception.cpp + ${send_crash_files} ${ui_app_files} ${app_platform_files} ${data_recovery_files} @@ -677,3 +682,10 @@ if(ENABLE_STEAM) add_definitions(-DENABLE_STEAM) target_link_libraries(app-lib steam-lib) endif() + +if(ENABLE_SENTRY) + target_compile_definitions(app-lib PUBLIC -DENABLE_SENTRY -DSENTRY_BUILD_STATIC=1) + target_compile_definitions(app-lib PUBLIC -DSENTRY_DNS="${SENTRY_DNS}" -DSENTRY_BUILD_STATIC=1) + add_subdirectory(${SENTRY_DIR} sentry) + target_link_libraries(app-lib sentry) +endif() diff --git a/src/app/app.cpp b/src/app/app.cpp index 814c99ab0..905a2202a 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -418,8 +418,10 @@ void App::run() checkUpdate.launch(); #endif +#if !ENABLE_SENTRY app::SendCrash sendCrash; sendCrash.search(); +#endif // Keep the console alive the whole program execute (just in case // we've to print errors). diff --git a/src/app/send_crash.h b/src/app/send_crash.h index 01c29d5f0..c8b9ce3fc 100644 --- a/src/app/send_crash.h +++ b/src/app/send_crash.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -16,6 +16,8 @@ namespace app { +#if !ENABLE_SENTRY + class SendCrash #ifdef ENABLE_UI : public INotificationDelegate @@ -43,6 +45,8 @@ namespace app { std::string m_dumpFilename; }; +#endif // !ENABLE_SENTRY + } // namespace app #endif // APP_SEND_CRASH_H_INCLUDED diff --git a/src/main/main.cpp b/src/main/main.cpp index 1c18a3df7..c8af5c2a1 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -16,10 +16,16 @@ #include "app/send_crash.h" #include "base/exception.h" #include "base/memory.h" -#include "base/memory_dump.h" #include "base/system_console.h" #include "os/error.h" #include "os/system.h" +#include "ver/info.h" + +#if ENABLE_SENTRY + #include "sentry.h" +#else + #include "base/memory_dump.h" +#endif #include #include @@ -59,6 +65,28 @@ namespace { }; #endif +#if ENABLE_SENTRY + class Sentry { + public: + Sentry() { + sentry_options_t* options = sentry_options_new(); + sentry_options_set_dsn(options, SENTRY_DNS); + + std::string release = "aseprite@"; + release += get_app_version(); + sentry_options_set_release(options, release.c_str()); + +#if _DEBUG + sentry_options_set_debug(options, 1); +#endif + sentry_init(options); + } + ~Sentry() { + sentry_close(); + } + }; +#endif + } // Aseprite entry point. (Called from "os" library.) @@ -78,13 +106,18 @@ int app_main(int argc, char* argv[]) #endif try { +#if ENABLE_SENTRY + Sentry sentry; +#else base::MemoryDump memoryDump; +#endif MemLeak memleak; base::SystemConsole systemConsole; app::AppOptions options(argc, const_cast(argv)); os::SystemRef system(os::make_system()); app::App app; +#if !ENABLE_SENTRY // Change the memory dump filename to save on disk (.dmp // file). Note: Only useful on Windows. { @@ -92,6 +125,7 @@ int app_main(int argc, char* argv[]) if (!fn.empty()) memoryDump.setFileName(fn); } +#endif const int code = app.initialize(options);