forked from Silverfish/proton-bridge
feat(GODT-2446): Attach logs to sentry reports for relevant bridge-gui exceptions.
Cherry picked from release/perth_narrows (2aa4e7c)
# Conflicts:
# internal/frontend/bridge-gui/bridge-gui/AppController.cpp
# internal/frontend/bridge-gui/bridge-gui/AppController.h
# internal/frontend/bridge-gui/bridge-gui/LogUtils.cpp
# internal/frontend/bridge-gui/bridge-gui/LogUtils.h
# internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp
# internal/frontend/bridge-gui/bridge-gui/SentryUtils.cpp
# internal/frontend/bridge-gui/bridge-gui/SentryUtils.h
# internal/frontend/bridge-gui/bridge-gui/main.cpp
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
#include "SentryUtils.h"
|
||||
#include "BuildConfig.h"
|
||||
#include <bridgepp/BridgeUtils.h>
|
||||
#include <bridgepp/Exception/Exception.h>
|
||||
|
||||
|
||||
using namespace bridgepp;
|
||||
@ -26,6 +27,23 @@ using namespace bridgepp;
|
||||
static constexpr const char *LoggerName = "bridge-gui";
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The temporary file used for sentry attachment.
|
||||
//****************************************************************************************************************************************************
|
||||
QString sentryAttachmentFilePath() {
|
||||
static QString path;
|
||||
if (!path.isEmpty()) {
|
||||
return path;
|
||||
}
|
||||
while (true) {
|
||||
path = QDir::temp().absoluteFilePath(QUuid::createUuid().toString(QUuid::WithoutBraces) + ".txt"); // Sentry does not offer preview for .log files.
|
||||
if (!QFileInfo::exists(path)) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Get a hash of the computer's host name
|
||||
//****************************************************************************************************************************************************
|
||||
@ -96,6 +114,8 @@ sentry_options_t* newSentryOptions(const char *sentryDNS, const char *cacheDir)
|
||||
sentry_options_set_release(sentryOptions, appVersion(PROJECT_VER).toUtf8());
|
||||
sentry_options_set_max_breadcrumbs(sentryOptions, 50);
|
||||
sentry_options_set_environment(sentryOptions, PROJECT_BUILD_ENV);
|
||||
QByteArray const array = sentryAttachmentFilePath().toLocal8Bit();
|
||||
sentry_options_add_attachment(sentryOptions, array.constData());
|
||||
// Enable this for debugging sentry.
|
||||
// sentry_options_set_debug(sentryOptions, 1);
|
||||
|
||||
@ -132,3 +152,30 @@ sentry_uuid_t reportSentryException(sentry_level_t level, const char *message, c
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] message The message for the exception.
|
||||
/// \param[in] function The name of the function that triggered the exception.
|
||||
/// \param[in] exception The exception.
|
||||
/// \return The Sentry exception UUID.
|
||||
//****************************************************************************************************************************************************
|
||||
sentry_uuid_t reportSentryException(QString const &message, bridgepp::Exception const exception) {
|
||||
QByteArray const attachment = exception.attachment();
|
||||
QFile file(sentryAttachmentFilePath());
|
||||
bool const hasAttachment = !attachment.isEmpty();
|
||||
if (hasAttachment) {
|
||||
if (file.open(QIODevice::Text | QIODevice::WriteOnly)) {
|
||||
file.write(attachment);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
sentry_uuid_t const uuid = reportSentryException(SENTRY_LEVEL_ERROR, message.toLocal8Bit(), "Exception",
|
||||
exception.detailedWhat().toLocal8Bit());
|
||||
|
||||
if (hasAttachment) {
|
||||
file.remove();
|
||||
}
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user