Add Sentry as an alternative to handling minidumps manually (#2857)

This commit is contained in:
David Capello 2021-09-21 11:29:48 -03:00
parent f687ddef72
commit 911589111e
5 changed files with 61 additions and 3 deletions

View File

@ -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(FULLSCREEN_PLATFORM "Enable fullscreen by default" off)
option(ENABLE_CLANG_TIDY "Enable static analysis" off) option(ENABLE_CLANG_TIDY "Enable static analysis" off)
option(ENABLE_CCACHE "Use CCache to improve recompilation speed (optional)" on) 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") 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) if(ENABLE_NEWS OR ENABLE_UPDATER)
set(REQUIRE_CURL ON) set(REQUIRE_CURL ON)
else() else()

View File

@ -402,6 +402,11 @@ if(ENABLE_UI)
endif() endif()
endif() endif()
set(send_crash_files)
if(NOT ENABLE_SENTRY)
set(send_crash_files send_crash.cpp)
endif()
add_library(app-lib add_library(app-lib
active_site_handler.cpp active_site_handler.cpp
app.cpp app.cpp
@ -575,7 +580,6 @@ add_library(app-lib
res/resources_loader.cpp res/resources_loader.cpp
resource_finder.cpp resource_finder.cpp
restore_visible_layers.cpp restore_visible_layers.cpp
send_crash.cpp
shade.cpp shade.cpp
site.cpp site.cpp
snap_to_grid.cpp snap_to_grid.cpp
@ -617,6 +621,7 @@ add_library(app-lib
util/wrap_point.cpp util/wrap_point.cpp
xml_document.cpp xml_document.cpp
xml_exception.cpp xml_exception.cpp
${send_crash_files}
${ui_app_files} ${ui_app_files}
${app_platform_files} ${app_platform_files}
${data_recovery_files} ${data_recovery_files}
@ -677,3 +682,10 @@ if(ENABLE_STEAM)
add_definitions(-DENABLE_STEAM) add_definitions(-DENABLE_STEAM)
target_link_libraries(app-lib steam-lib) target_link_libraries(app-lib steam-lib)
endif() 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()

View File

@ -418,8 +418,10 @@ void App::run()
checkUpdate.launch(); checkUpdate.launch();
#endif #endif
#if !ENABLE_SENTRY
app::SendCrash sendCrash; app::SendCrash sendCrash;
sendCrash.search(); sendCrash.search();
#endif
// Keep the console alive the whole program execute (just in case // Keep the console alive the whole program execute (just in case
// we've to print errors). // we've to print errors).

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2020 Igara Studio S.A. // Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
@ -16,6 +16,8 @@
namespace app { namespace app {
#if !ENABLE_SENTRY
class SendCrash class SendCrash
#ifdef ENABLE_UI #ifdef ENABLE_UI
: public INotificationDelegate : public INotificationDelegate
@ -43,6 +45,8 @@ namespace app {
std::string m_dumpFilename; std::string m_dumpFilename;
}; };
#endif // !ENABLE_SENTRY
} // namespace app } // namespace app
#endif // APP_SEND_CRASH_H_INCLUDED #endif // APP_SEND_CRASH_H_INCLUDED

View File

@ -16,10 +16,16 @@
#include "app/send_crash.h" #include "app/send_crash.h"
#include "base/exception.h" #include "base/exception.h"
#include "base/memory.h" #include "base/memory.h"
#include "base/memory_dump.h"
#include "base/system_console.h" #include "base/system_console.h"
#include "os/error.h" #include "os/error.h"
#include "os/system.h" #include "os/system.h"
#include "ver/info.h"
#if ENABLE_SENTRY
#include "sentry.h"
#else
#include "base/memory_dump.h"
#endif
#include <clocale> #include <clocale>
#include <cstdlib> #include <cstdlib>
@ -59,6 +65,28 @@ namespace {
}; };
#endif #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.) // Aseprite entry point. (Called from "os" library.)
@ -78,13 +106,18 @@ int app_main(int argc, char* argv[])
#endif #endif
try { try {
#if ENABLE_SENTRY
Sentry sentry;
#else
base::MemoryDump memoryDump; base::MemoryDump memoryDump;
#endif
MemLeak memleak; MemLeak memleak;
base::SystemConsole systemConsole; base::SystemConsole systemConsole;
app::AppOptions options(argc, const_cast<const char**>(argv)); app::AppOptions options(argc, const_cast<const char**>(argv));
os::SystemRef system(os::make_system()); os::SystemRef system(os::make_system());
app::App app; app::App app;
#if !ENABLE_SENTRY
// Change the memory dump filename to save on disk (.dmp // Change the memory dump filename to save on disk (.dmp
// file). Note: Only useful on Windows. // file). Note: Only useful on Windows.
{ {
@ -92,6 +125,7 @@ int app_main(int argc, char* argv[])
if (!fn.empty()) if (!fn.empty())
memoryDump.setFileName(fn); memoryDump.setFileName(fn);
} }
#endif
const int code = app.initialize(options); const int code = app.initialize(options);