diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b45e9e..fe4aba8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,19 +47,19 @@ add_executable(BeamMP-Server include/TResourceManager.h src/TResourceManager.cpp include/THeartbeatThread.h src/THeartbeatThread.cpp include/Http.h src/Http.cpp - #include/SocketIO.h src/SocketIO.cpp + include/Sentry.h src/Sentry.cpp include/TPPSMonitor.h src/TPPSMonitor.cpp include/TNetwork.h src/TNetwork.cpp) target_include_directories(BeamMP-Server PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/commandline") find_package(Lua REQUIRED) -target_include_directories(BeamMP-Server PUBLIC ${Boost_INCLUDE_DIRS} ${LUA_INCLUDE_DIR} "socket.io-client-cpp/src" "include/tomlplusplus") +target_include_directories(BeamMP-Server PUBLIC ${Boost_INCLUDE_DIRS} ${LUA_INCLUDE_DIR} "socket.io-client-cpp/src" "include/tomlplusplus" "include/sentry-native") find_package(OpenSSL REQUIRED) if (UNIX) - target_link_libraries(BeamMP-Server z pthread stdc++fs ${LUA_LIBRARIES} crypto ${OPENSSL_LIBRARIES} commandline sioclient_tls) + target_link_libraries(BeamMP-Server z pthread stdc++fs ${LUA_LIBRARIES} crypto ${OPENSSL_LIBRARIES} commandline sioclient_tls sentry) elseif (WIN32) include(FindLua) find_package(ZLIB REQUIRED) diff --git a/include/Sentry.h b/include/Sentry.h new file mode 100644 index 0000000..40006ee --- /dev/null +++ b/include/Sentry.h @@ -0,0 +1,14 @@ +#ifndef SENTRY_H +#define SENTRY_H + +#include + +// singleton, dont make this twice +class Sentry final { +public: + Sentry(const std::string& SentryUrl); + ~Sentry(); +private: +}; + +#endif // SENTRY_H diff --git a/src/Sentry.cpp b/src/Sentry.cpp new file mode 100644 index 0000000..ed593b8 --- /dev/null +++ b/src/Sentry.cpp @@ -0,0 +1,16 @@ +#include "Sentry.h" +#include "Common.h" + +#include "sentry.h" + +Sentry::Sentry(const std::string& SentryUrl) { + sentry_options_t* options = sentry_options_new(); + sentry_options_set_dsn(options, SentryUrl.c_str()); + auto ReleaseString = "BeamMP-Server@" + Application::ServerVersion(); + sentry_options_set_release(options, ReleaseString.c_str()); + sentry_init(options); +} + +Sentry::~Sentry() { + sentry_close(); +} diff --git a/src/main.cpp b/src/main.cpp index b78446f..9d064f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include "Common.h" #include "Http.h" +#include "Sentry.h" #include "TConfig.h" #include "THeartbeatThread.h" #include "TLuaEngine.h" @@ -7,6 +8,8 @@ #include "TPPSMonitor.h" #include "TResourceManager.h" #include "TServer.h" + +#include #include #ifdef __unix @@ -44,6 +47,21 @@ int main(int argc, char** argv) { #endif // DEBUG #endif // __unix + // FIXME: this is not prod ready, needs to be compile-time value + char* sentry_url = getenv("SENTRY_URL"); + if (!sentry_url) { + error("no sentry url supplied in environment, this is not a fatal error"); + } else { + info("sentry url has length " + std::to_string(std::string(sentry_url).size())); + } + + Sentry sentry(sentry_url); + + sentry_capture_event(sentry_value_new_message_event( + /* level */ SENTRY_LEVEL_INFO, + /* logger */ "custom", + /* message */ "It works!")); + setlocale(LC_ALL, "C"); bool Shutdown = false;