working sentry-native

This commit is contained in:
Lion Kortlepel 2021-08-08 00:28:30 +02:00 committed by Lion
parent d5769ce9be
commit da41862f49
4 changed files with 51 additions and 3 deletions

View File

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

14
include/Sentry.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef SENTRY_H
#define SENTRY_H
#include <string>
// singleton, dont make this twice
class Sentry final {
public:
Sentry(const std::string& SentryUrl);
~Sentry();
private:
};
#endif // SENTRY_H

16
src/Sentry.cpp Normal file
View File

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

View File

@ -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 <sentry.h>
#include <thread>
#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;