aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-05-06 16:50:57 +0200
committerGitHub Enterprise <[email protected]>2025-05-06 16:50:57 +0200
commit6d9ff7e404a22ed1cc7e529cfa77ef7d593d9547 (patch)
tree5cfea359c44b02fe72ab5b166e9b03900444fcba /src
parentcleanup changelog (diff)
downloadzen-6d9ff7e404a22ed1cc7e529cfa77ef7d593d9547.tar.xz
zen-6d9ff7e404a22ed1cc7e529cfa77ef7d593d9547.zip
add sentry for zen command (#373)
* refactor sentry integration and add to zen command line tool * move add_ldflags("-framework Security")
Diffstat (limited to 'src')
-rw-r--r--src/zen/xmake.lua4
-rw-r--r--src/zen/zen.cpp35
-rw-r--r--src/zencore/include/zencore/sentryintegration.h (renamed from src/zenserver/sentryintegration.h)0
-rw-r--r--src/zencore/sentryintegration.cpp (renamed from src/zenserver/sentryintegration.cpp)11
-rw-r--r--src/zencore/xmake.lua21
-rw-r--r--src/zenserver/main.cpp2
-rw-r--r--src/zenserver/xmake.lua15
-rw-r--r--src/zenserver/zenserver.cpp3
8 files changed, 68 insertions, 23 deletions
diff --git a/src/zen/xmake.lua b/src/zen/xmake.lua
index 78b2a3c2b..bf595a21d 100644
--- a/src/zen/xmake.lua
+++ b/src/zen/xmake.lua
@@ -18,13 +18,15 @@ target("zen")
add_ldflags("/subsystem:console,5.02")
add_ldflags("/LTCG")
add_links("crypt32", "wldap32", "Ws2_32")
+
+ add_links("dbghelp", "winhttp", "version") -- for Sentry
end
if is_plat("macosx") then
add_ldflags("-framework CoreFoundation")
+ add_ldflags("-framework Foundation")
add_ldflags("-framework Security")
add_ldflags("-framework SystemConfiguration")
- add_syslinks("bsm")
end
add_packages("vcpkg::cpr", "vcpkg::cxxopts", "vcpkg::mimalloc", "vcpkg::fmt")
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp
index 399c43990..7c21035c0 100644
--- a/src/zen/zen.cpp
+++ b/src/zen/zen.cpp
@@ -32,6 +32,7 @@
#include <zencore/logging.h>
#include <zencore/process.h>
#include <zencore/scopeguard.h>
+#include <zencore/sentryintegration.h>
#include <zencore/string.h>
#include <zencore/trace.h>
#include <zencore/windows.h>
@@ -581,6 +582,8 @@ ProgressBar::HasActiveTask() const
int
main(int argc, char** argv)
{
+ zen::SetCurrentThreadName("main");
+
std::vector<std::string> Args;
#if ZEN_PLATFORM_WINDOWS
LPWSTR RawCommandLine = GetCommandLine();
@@ -838,6 +841,38 @@ main(int argc, char** argv)
#endif // ZEN_WITH_TRACE
Options.parse_positional({"command"});
+#if ZEN_USE_SENTRY
+ bool NoSentry = false;
+ bool SentryAllowPII = false;
+ Options.add_options()("no-sentry", "Disable Sentry crash handler", cxxopts::value<bool>(NoSentry)->default_value("false"));
+ Options.add_options()("sentry-allow-personal-info",
+ "Allow personally identifiable information in sentry crash reports",
+ cxxopts::value<bool>(SentryAllowPII)->default_value("false"));
+#endif
+
+#if ZEN_USE_SENTRY
+ SentryIntegration Sentry;
+
+ if (NoSentry == false)
+ {
+ std::string SentryDatabasePath = (GetRunningExecutablePath().parent_path() / ".sentry-native").string();
+
+ ExtendableStringBuilder<512> SB;
+ for (int i = 0; i < argc; ++i)
+ {
+ if (i)
+ {
+ SB.Append(' ');
+ }
+
+ SB.Append(argv[i]);
+ }
+
+ Sentry.Initialize(SentryDatabasePath, {}, SentryAllowPII, SB.ToString());
+
+ SentryIntegration::ClearCaches();
+ }
+#endif
const bool IsNullInvoke = (argc == 1); // If no arguments are passed we want to print usage information
diff --git a/src/zenserver/sentryintegration.h b/src/zencore/include/zencore/sentryintegration.h
index 40e22af4e..40e22af4e 100644
--- a/src/zenserver/sentryintegration.h
+++ b/src/zencore/include/zencore/sentryintegration.h
diff --git a/src/zenserver/sentryintegration.cpp b/src/zencore/sentryintegration.cpp
index 7996f25bb..d08fb7f1d 100644
--- a/src/zenserver/sentryintegration.cpp
+++ b/src/zencore/sentryintegration.cpp
@@ -1,6 +1,6 @@
// Copyright Epic Games, Inc. All Rights Reserved.
-#include "sentryintegration.h"
+#include <zencore/sentryintegration.h>
#include <zencore/config.h>
#include <zencore/logging.h>
@@ -207,11 +207,14 @@ SentryIntegration::Initialize(std::string SentryDatabasePath,
sentry_options_set_dsn(SentryOptions, "https://[email protected]/5919284");
sentry_options_set_database_path(SentryOptions, SentryDatabasePath.c_str());
sentry_options_set_logger(SentryOptions, SentryLogFunction, this);
- if (SentryAttachmentsPath.starts_with("\\\\?\\"))
+ if (!SentryAttachmentsPath.empty())
{
- SentryAttachmentsPath = SentryAttachmentsPath.substr(4);
+ if (SentryAttachmentsPath.starts_with("\\\\?\\"))
+ {
+ SentryAttachmentsPath = SentryAttachmentsPath.substr(4);
+ }
+ sentry_options_add_attachment(SentryOptions, SentryAttachmentsPath.c_str());
}
- sentry_options_add_attachment(SentryOptions, SentryAttachmentsPath.c_str());
sentry_options_set_release(SentryOptions, ZEN_CFG_VERSION);
// sentry_options_set_debug(SentryOptions, 1);
diff --git a/src/zencore/xmake.lua b/src/zencore/xmake.lua
index 13611a2e9..b3a33e052 100644
--- a/src/zencore/xmake.lua
+++ b/src/zencore/xmake.lua
@@ -64,6 +64,27 @@ target('zencore')
{public=true}
)
+ if has_config("zensentry") then
+ add_packages("vcpkg::sentry-native")
+
+ if is_plat("windows") then
+ add_links("dbghelp", "winhttp", "version") -- for Sentry
+ end
+
+ if is_plat("linux") then
+ -- As sentry_native uses symbols from breakpad_client, the latter must
+ -- be specified after the former with GCC-like toolchains. xmake however
+ -- is unaware of this and simply globs files from vcpkg's output. The
+ -- line below forces breakpad_client to be to the right of sentry_native
+ add_syslinks("breakpad_client")
+ end
+
+ if is_plat("macosx") then
+ add_syslinks("bsm")
+ end
+
+ end
+
if is_plat("linux") then
add_syslinks("rt")
end
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp
index 78ddd39a0..0f647cd5c 100644
--- a/src/zenserver/main.cpp
+++ b/src/zenserver/main.cpp
@@ -10,6 +10,7 @@
#include <zencore/fmtutils.h>
#include <zencore/logging.h>
#include <zencore/scopeguard.h>
+#include <zencore/sentryintegration.h>
#include <zencore/session.h>
#include <zencore/string.h>
#include <zencore/thread.h>
@@ -25,7 +26,6 @@
#include "config.h"
#include "diag/logging.h"
-#include "sentryintegration.h"
#if ZEN_PLATFORM_WINDOWS
# include <zencore/windows.h>
diff --git a/src/zenserver/xmake.lua b/src/zenserver/xmake.lua
index a3d7aa124..470fbd24e 100644
--- a/src/zenserver/xmake.lua
+++ b/src/zenserver/xmake.lua
@@ -28,8 +28,6 @@ target("zenserver")
add_cxxflags("/bigobj")
add_links("delayimp", "projectedfslib")
add_ldflags("/delayload:ProjectedFSLib.dll")
-
- add_links("dbghelp", "winhttp", "version") -- for Sentry
else
remove_files("windows/**")
end
@@ -41,7 +39,6 @@ target("zenserver")
add_ldflags("-framework Foundation")
add_ldflags("-framework Security")
add_ldflags("-framework SystemConfiguration")
- add_syslinks("bsm")
end
add_options("compute")
@@ -57,18 +54,6 @@ target("zenserver")
"vcpkg::sol2"
)
- if has_config("zensentry") then
- add_packages("vcpkg::sentry-native")
- end
-
- if is_plat("linux") then
- -- As sentry_native uses symbols from breakpad_client, the latter must
- -- be specified after the former with GCC-like toolchains. xmake however
- -- is unaware of this and simply globs files from vcpkg's output. The
- -- line below forces breakpad_client to be to the right of sentry_native
- add_syslinks("breakpad_client")
- end
-
-- to work around some unfortunate Ctrl-C behaviour on Linux/Mac due to
-- our use of setsid() at startup we pass in `--no-detach` to zenserver
-- ensure that it recieves signals when the user requests termination
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 3f2f01d5a..366944ffc 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -2,8 +2,6 @@
#include "zenserver.h"
-#include "sentryintegration.h"
-
#include <zenbase/refcount.h>
#include <zencore/basicfile.h>
#include <zencore/compactbinarybuilder.h>
@@ -16,6 +14,7 @@
#include <zencore/jobqueue.h>
#include <zencore/logging.h>
#include <zencore/scopeguard.h>
+#include <zencore/sentryintegration.h>
#include <zencore/session.h>
#include <zencore/string.h>
#include <zencore/thread.h>