Skip to content

Commit

Permalink
Merge pull request #403 from Infomaniak/KDESKTOP-1264-Implement-Sentr…
Browse files Browse the repository at this point in the history
…y-transaction

Kdesktop 1264 implement sentry transaction.
  • Loading branch information
herve-er authored Dec 11, 2024
2 parents bf18aac + fd930f3 commit 3792ea6
Show file tree
Hide file tree
Showing 53 changed files with 1,373 additions and 380 deletions.
7 changes: 4 additions & 3 deletions src/gui/appclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <stdlib.h>

#include <sentry.h>
#include <log/sentry/sentryhandler.h>
#include <log/sentry/handler.h>

#define CONNECTION_TRIALS 3
#define CHECKCOMMSTATUS_TRIALS 5
Expand Down Expand Up @@ -166,6 +166,7 @@ AppClient::AppClient(int &argc, char **argv) : SharedTools::QtSingleApplication(
// Setup Gui
_gui = std::shared_ptr<ClientGui>(new ClientGui(this));
_gui->init();
GuiRequests::reportClientDisplayed();

_theme->setSystrayUseMonoIcons(ParametersCache::instance()->parametersInfo().monoIcons());
connect(_theme, &Theme::systrayUseMonoIconsChanged, this, &AppClient::onUseMonoIconsChanged);
Expand Down Expand Up @@ -671,13 +672,13 @@ void AppClient::updateSentryUser() const {
if (userInfo == _gui->userInfoMap().end()) {
qCWarning(lcAppClient) << "No user found in updateSentryUser()";
SentryUser user("No user logged", "No user logged", "No user logged");
SentryHandler::instance()->setAuthenticatedUser(user);
sentry::Handler::instance()->setAuthenticatedUser(user);
return;
}

SentryUser user(userInfo->second.email().toStdString(), userInfo->second.name().toStdString(),
std::to_string(userInfo->second.userId()));
SentryHandler::instance()->setAuthenticatedUser(user);
sentry::Handler::instance()->setAuthenticatedUser(user);
}

void AppClient::onUseMonoIconsChanged(bool) {
Expand Down
7 changes: 6 additions & 1 deletion src/gui/guirequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ ExitCode GuiRequests::setExclusionAppList(bool def, const QList<ExclusionAppInfo

ExitCode GuiRequests::getFetchingAppList(QHash<QString, QString> &appTable) {
QByteArray results;
if (!CommClient::instance()->execute(RequestNum::GET_FETCHING_APP_LIST, {}, results, COMM_AVERAGE_TIMEOUT)) {
if (!CommClient::instance()->execute(RequestNum::EXCLAPP_GET_FETCHING_APP_LIST, {}, results, COMM_AVERAGE_TIMEOUT)) {
throw std::runtime_error(EXECUTE_ERROR_MSG);
}

Expand Down Expand Up @@ -1252,4 +1252,9 @@ ExitCode GuiRequests::skipUpdate(const std::string &version) {
return ExitCode::Ok;
}

ExitCode GuiRequests::reportClientDisplayed() {
CommClient::instance()->execute(RequestNum::UTILITY_DISPLAY_CLIENT_REPORT);
return ExitCode::Ok;
}

} // namespace KDC
1 change: 1 addition & 0 deletions src/gui/guirequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ struct GuiRequests {
static ExitCode updateState(UpdateState &state);
static ExitCode startInstaller();
static ExitCode skipUpdate(const std::string &version);
static ExitCode reportClientDisplayed();
};
} // namespace KDC
6 changes: 3 additions & 3 deletions src/gui/mainclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "cocoainitializer.h"
#include "libcommon/theme/theme.h"
#include "libcommon/utility/utility.h"
#include "libcommon/log/sentry/sentryhandler.h"
#include "libcommon/log/sentry/handler.h"
#include "libcommongui/utility/utility.h"

#include <QtGlobal>
Expand Down Expand Up @@ -71,8 +71,8 @@ int main(int argc, char **argv) {

// Working dir;
KDC::CommonUtility::_workingDirPath = KDC::SyncPath(argv[0]).parent_path();
KDC::SentryHandler::init(KDC::AppType::Client);
KDC::SentryHandler::instance()->setGlobalConfidentialityLevel(KDC::SentryConfidentialityLevel::Authenticated);
KDC::sentry::Handler::init(KDC::AppType::Client);
KDC::sentry::Handler::instance()->setGlobalConfidentialityLevel(KDC::sentry::ConfidentialityLevel::Authenticated);

#ifdef Q_OS_LINUX
// Bug with multi-screen
Expand Down
6 changes: 3 additions & 3 deletions src/gui/synthesispopover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "parameterscache.h"
#include "config.h"
#include "libcommon/utility/utility.h"
#include "libcommon/log/sentry/sentryhandler.h"
#include "libcommon/log/sentry/handler.h"
#include "guirequests.h"

#include <QActionGroup>
Expand Down Expand Up @@ -1079,8 +1079,8 @@ void SynthesisPopover::onUpdateAvailabilityChange(const UpdateState updateState)
break;
default:
_lockedAppUpdateButton->setText(tr("Unavailable"));
SentryHandler::instance()->captureMessage(SentryLevel::Fatal, "AppLocked",
"426 Error received but unable to fetch an update");
sentry::Handler::captureMessage(sentry::Level::Fatal, "AppLocked",
"HTTP Error426 received but unable to fetch an update");
break;
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/libcommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ set(libcommon_SRCS
info/exclusiontemplateinfo.h info/exclusiontemplateinfo.cpp
info/exclusionappinfo.h info/exclusionappinfo.cpp
info/proxyconfiginfo.h info/proxyconfiginfo.cpp
log/sentry/sentryhandler.h log/sentry/sentryhandler.cpp
log/sentry/sentryuser.h
log/sentry/handler.h log/sentry/handler.cpp
log/sentry/abstractptrace.h
log/sentry/abstractcounterscopedptrace.h
log/sentry/abstractscopedptrace.h
log/sentry/ptraces.h log/sentry/user.h
log/sentry/ptracedescriptor.h
log/sentry/ptrace.h log/sentry/utility.h
log/customlogstreams.h
theme/theme.h theme/theme.cpp
)
Expand Down
19 changes: 11 additions & 8 deletions src/libcommon/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ enum class RequestNum {
#ifdef __APPLE__
EXCLAPP_GETLIST,
EXCLAPP_SETLIST,
GET_FETCHING_APP_LIST,
EXCLAPP_GET_FETCHING_APP_LIST,
#endif
PARAMETERS_INFO,
PARAMETERS_UPDATE,
Expand All @@ -112,13 +112,14 @@ enum class RequestNum {
UTILITY_SEND_LOG_TO_SUPPORT,
UTILITY_CANCEL_LOG_TO_SUPPORT,
UTILITY_GET_LOG_ESTIMATED_SIZE,
UTILITY_CRASH,
UTILITY_QUIT,
UTILITY_DISPLAY_CLIENT_REPORT, // Sent by the Client process as soon the UI is visible for the user.
UPDATER_CHANGE_CHANNEL,
UPDATER_VERSION_INFO,
UPDATER_STATE,
UPDATER_START_INSTALLER,
UPDATER_SKIP_VERSION,
UTILITY_CRASH,
UTILITY_QUIT,
};

inline std::string toString(RequestNum e) {
Expand Down Expand Up @@ -224,7 +225,7 @@ inline std::string toString(RequestNum e) {
return "EXCLAPP_GETLIST";
case RequestNum::EXCLAPP_SETLIST:
return "EXCLAPP_SETLIST";
case RequestNum::GET_FETCHING_APP_LIST:
case RequestNum::EXCLAPP_GET_FETCHING_APP_LIST:
return "GET_FETCHING_APP_LIST";
#endif
case RequestNum::PARAMETERS_INFO:
Expand Down Expand Up @@ -261,6 +262,12 @@ inline std::string toString(RequestNum e) {
return "UTILITY_CANCEL_LOG_TO_SUPPORT";
case RequestNum::UTILITY_GET_LOG_ESTIMATED_SIZE:
return "UTILITY_GET_LOG_ESTIMATED_SIZE";
case RequestNum::UTILITY_CRASH:
return "UTILITY_CRASH";
case RequestNum::UTILITY_QUIT:
return "UTILITY_QUIT";
case RequestNum::UTILITY_DISPLAY_CLIENT_REPORT:
return "UTILITY_DISPLAY_CLIENT_REPORT";
case RequestNum::UPDATER_VERSION_INFO:
return "UPDATER_VERSION_INFO";
case RequestNum::UPDATER_STATE:
Expand All @@ -269,10 +276,6 @@ inline std::string toString(RequestNum e) {
return "UPDATER_START_INSTALLER";
case RequestNum::UPDATER_SKIP_VERSION:
return "UPDATER_SKIP_VERSION";
case RequestNum::UTILITY_CRASH:
return "UTILITY_CRASH";
case RequestNum::UTILITY_QUIT:
return "UTILITY_QUIT";
default:
return "No conversion to string available";
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcommon/keychainmanager/keychainmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool KeyChainManager::writeDummyTest() {
if (!KeyChainManager::instance()->writeToken(dummyKeychainKey, dummyData)) {
std::string error = "Test writing into the keychain failed. Token not refreshed.";
LOG_WARN(Log::instance()->getLogger(), error.c_str());
SentryHandler::instance()->captureMessage(SentryLevel::Warning, "KeyChain::writeDummyTest", error);
sentry::Handler::captureMessage(sentry::Level::Warning, "KeyChain::writeDummyTest", error);

return false;
}
Expand All @@ -74,7 +74,7 @@ bool KeyChainManager::writeToken(const std::string &keychainKey, const std::stri
if (error) {
LOG_DEBUG(KDC::Log::instance()->getLogger(),
"Failed to save authentication info to keychain: " << error.code << " - " << error.message.c_str());
SentryHandler::instance()->captureMessage(SentryLevel::Warning, "KeyChain::writeToken", error.message);
sentry::Handler::captureMessage(sentry::Level::Warning, "KeyChain::writeToken", error.message);

return false;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ bool KeyChainManager::deleteToken(const std::string &keychainKey) {
LOG_DEBUG(KDC::Log::instance()->getLogger(),
"Failed to delete authentication info to keychain: " << error.code << " - " << error.message.c_str());

SentryHandler::instance()->captureMessage(SentryLevel::Warning, "KeyChain::deleteToken", error.message);
sentry::Handler::captureMessage(sentry::Level::Warning, "KeyChain::deleteToken", error.message);

return false;
}
Expand Down
52 changes: 52 additions & 0 deletions src/libcommon/log/sentry/abstractcounterscopedptrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Infomaniak kDrive - Desktop
* Copyright (C) 2023-2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include "libcommon/log/sentry/abstractscopedptrace.h"

namespace KDC::sentry {

class AbstractCounterScopedPTrace : public AbstractScopedPTrace {
public:
void start() final {
if (_counter >= _nbOfCyclesPerTrace) {
AbstractScopedPTrace::stop();
AbstractScopedPTrace::start();
_counter = 0;
} else
_counter++;
}

protected:
explicit AbstractCounterScopedPTrace(const PTraceDescriptor &info, unsigned int nbOfCyclePerTrace) :
AbstractScopedPTrace(info, PTraceStatus::Cancelled), _nbOfCyclesPerTrace(nbOfCyclePerTrace) {}

explicit AbstractCounterScopedPTrace(const PTraceDescriptor &info, unsigned int nbOfCyclePerTrace, int syncDbId) :
AbstractScopedPTrace(info, PTraceStatus::Cancelled, syncDbId), _nbOfCyclesPerTrace(nbOfCyclePerTrace) {}

private:
void stop(PTraceStatus status = PTraceStatus::Ok) final {
assert(false && "stop() should not be called with CounterScopedPTrace.");
}
void restart() final {
assert(false && "restart() should not be called with CounterScopedPTrace.");
}
unsigned int _nbOfCyclesPerTrace = 0; // The number of time start() should be called before stopping the trace.
unsigned int _counter = 0;
};
} // namespace KDC::sentry
68 changes: 68 additions & 0 deletions src/libcommon/log/sentry/abstractptrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Infomaniak kDrive - Desktop
* Copyright (C) 2023-2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include "libcommon/log/sentry/handler.h"
#include "libcommon/log/sentry/ptracedescriptor.h"

namespace KDC::sentry {
class AbstractPTrace;
using PTraceUPtr = std::unique_ptr<AbstractPTrace>;
class AbstractPTrace {
public:
virtual ~AbstractPTrace() = default;

// Return the current performance trace id.
pTraceId id() const { return _pTraceId; }
virtual void start() { _start(); }
virtual void stop(PTraceStatus status = PTraceStatus::Ok) { _stop(status); }
virtual void restart() { _restart(); }

protected:
explicit AbstractPTrace(const PTraceDescriptor &info) : _pTraceInfo(info){};
explicit AbstractPTrace(const PTraceDescriptor &info, int dbId) : _pTraceInfo(info), _syncDbId(dbId){};

// Start a new performance trace.
inline AbstractPTrace &_start() {
_pTraceId = sentry::Handler::instance()->startPTrace(_pTraceInfo, _syncDbId);
return *this;
}

// Stop the performance trace.
void _stop(PTraceStatus status = PTraceStatus::Ok) noexcept {
if (_pTraceId) { // If the performance trace id is set, use it to stop the performance trace (faster).
Handler::instance()->stopPTrace(_pTraceId, status);
_pTraceId = 0;
} else {
Handler::instance()->stopPTrace(_pTraceInfo, _syncDbId, status);
}
}

// Stop the current performance trace (aborted = false) and start a new one.
void _restart() {
_stop();
_start();
}

private:
AbstractPTrace &operator=(AbstractPTrace &&) = delete;
pTraceId _pTraceId{0};
PTraceDescriptor _pTraceInfo;
int _syncDbId = -1;
};
} // namespace KDC::sentry
43 changes: 43 additions & 0 deletions src/libcommon/log/sentry/abstractscopedptrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Infomaniak kDrive - Desktop
* Copyright (C) 2023-2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include "libcommon/log/sentry/abstractptrace.h"

namespace KDC::sentry {

class AbstractScopedPTrace : public AbstractPTrace {
public:
~AbstractScopedPTrace() override { _stop(_autoStopStatus); }

void start() override { _start(); }

protected:
explicit AbstractScopedPTrace(const PTraceDescriptor &info, PTraceStatus autoStopStatus) :
AbstractPTrace(info), _autoStopStatus(autoStopStatus) {
start();
}
explicit AbstractScopedPTrace(const PTraceDescriptor &info, PTraceStatus autoStopStatus, int syncDbId) :
AbstractPTrace(info, syncDbId), _autoStopStatus(autoStopStatus) {
start();
}

private:
PTraceStatus _autoStopStatus = PTraceStatus::Ok; // The status to use when the object is stopped due to its destruction.
};
} // namespace KDC::sentry
Loading

0 comments on commit 3792ea6

Please sign in to comment.