Add anonymize option and version tag

This commit is contained in:
Ivan Blinkov 2020-05-30 11:02:13 +03:00
parent 6dfe44f437
commit 77d8c9baca
4 changed files with 16 additions and 4 deletions

View File

@ -18,10 +18,16 @@
namespace
{
static bool initialized = false;
static bool anonymize = false;
void setExtras()
{
#if USE_SENTRY
if (!anonymize)
{
sentry_set_extra("server_name", sentry_value_new_string(getFQDNOrHostName().c_str()));
}
sentry_set_tag("version", VERSION_STRING_SHORT);
sentry_set_extra("version_githash", sentry_value_new_string(VERSION_GITHASH));
sentry_set_extra("version_describe", sentry_value_new_string(VERSION_DESCRIBE));
sentry_set_extra("version_integer", sentry_value_new_int32(VERSION_INTEGER));
@ -69,15 +75,19 @@ void SentryWriter::initialize(Poco::Util::LayeredConfiguration & config)
{
sentry_options_set_environment(options, "test");
}
int init_status = sentry_init(options);
if (!init_status)
{
initialized = true;
anonymize = config.getBool("send_crash_reports.anonymize", false);
const std::string& anonymize_status = anonymize ? " (anonymized)" : "";
LOG_INFO(
&Logger::get("SentryWriter"),
"Sending crash reports is initialized with {} endpoint and {} temp folder",
"Sending crash reports is initialized with {} endpoint and {} temp folder{}",
endpoint,
temp_folder_path);
temp_folder_path,
anonymize_status);
}
else
{
@ -109,7 +119,6 @@ void SentryWriter::onFault(int sig, const siginfo_t & info, const ucontext_t & c
const std::string & error_message = signalToErrorMessage(sig, info, context);
sentry_value_t event = sentry_value_new_message_event(SENTRY_LEVEL_FATAL, "fault", error_message.c_str());
sentry_set_tag("signal", strsignal(sig));
sentry_set_tag("server_name", getFQDNOrHostName().c_str());
sentry_set_extra("signal_number", sentry_value_new_int32(sig));
setExtras();
@ -175,4 +184,4 @@ void SentryWriter::onFault(int sig, const siginfo_t & info, const ucontext_t & c
LOG_INFO(&Logger::get("SentryWriter"), "Not sending crash report");
}
#endif
}
}

View File

@ -14,6 +14,7 @@ endif ()
set (VERSION_NAME "${PROJECT_NAME}")
set (VERSION_FULL "${VERSION_NAME} ${VERSION_STRING}")
set (VERSION_SO "${VERSION_STRING}")
set (VERSION_STRING_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}")
math (EXPR VERSION_INTEGER "${VERSION_PATCH} + ${VERSION_MINOR}*1000 + ${VERSION_MAJOR}*1000000")

View File

@ -357,6 +357,7 @@ Keys:
- `enabled` Boolean flag to enable the feature. Set to `true` to allow sending crash reports.
- `endpoint` Overrides the Sentry endpoint.
- `anonymize` - Avoid attaching the server hostname to crash report.
- `debug` - Sets the Sentry client into debug mode.
- `tmp_path` - Filesystem path for temporary crash report state.

View File

@ -20,6 +20,7 @@
#cmakedefine VERSION_MINOR @VERSION_MINOR@
#cmakedefine VERSION_PATCH @VERSION_PATCH@
#cmakedefine VERSION_STRING "@VERSION_STRING@"
#cmakedefine VERSION_STRING_SHORT "@VERSION_STRING_SHORT@"
#cmakedefine VERSION_OFFICIAL "@VERSION_OFFICIAL@"
#cmakedefine VERSION_FULL "@VERSION_FULL@"
#cmakedefine VERSION_DESCRIBE "@VERSION_DESCRIBE@"