Skip to content

Commit

Permalink
Merge pull request #518 from daleglass-overte/store-annotations-befor…
Browse files Browse the repository at this point in the history
…e-crash-init

Store annotations before the crash handler initializes
  • Loading branch information
ksuprynowicz authored Jul 16, 2023
2 parents 3164e71 + 273d4a3 commit 7b39475
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
18 changes: 16 additions & 2 deletions libraries/networking/src/crash-handler/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ bool CrashHandler::start() {

if ( started ) {
qCInfo(crash_handler) << "Crash handler started";
std::size_t countAdded = 0;

{
std::lock_guard<std::mutex> lock(_annotationsMutex);
for(const auto &item : _annotations) {
setCrashAnnotation(item.first, item.second);
}

countAdded = _annotations.size();
_annotations.clear();
}

qCDebug(crash_handler) << "Forwarded" << countAdded << "annotations";

} else {
qCWarning(crash_handler) << "Crash handler failed to start";
}
Expand Down Expand Up @@ -94,7 +108,6 @@ void CrashHandler::setToken(const QString &token) {

void CrashHandler::setAnnotation(const std::string &key, const char *value) {
setAnnotation(key, std::string(value));
setCrashAnnotation(key, std::string(value));
}

void CrashHandler::setAnnotation(const std::string &key, const QString &value) {
Expand All @@ -103,7 +116,8 @@ void CrashHandler::setAnnotation(const std::string &key, const QString &value) {

void CrashHandler::setAnnotation(const std::string &key, const std::string &value) {
if (!isStarted()) {
qCWarning(crash_handler) << "Can't set annotation" << QString::fromStdString(key) << "to" << QString::fromStdString(value) << "crash handler not yet started";
std::lock_guard<std::mutex> lock(_annotationsMutex);
_annotations[key] = value;
return;
}

Expand Down
19 changes: 17 additions & 2 deletions libraries/networking/src/crash-handler/CrashHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <QObject>
#include <QCoreApplication>
#include <SettingHandle.h>
#include <atomic>
#include <unordered_map>
#include <mutex>



Expand Down Expand Up @@ -162,6 +165,9 @@ public slots:
* Annotations add extra information, such as the application's version number,
* the current user, or any other information of interest.
*
* @note Annotations made before the crash handler are remembered, and sent to the
* crash handler as soon as it's initialized.
*
* @param key Key
* @param value Value
*/
Expand All @@ -173,6 +179,9 @@ public slots:
* Annotations add extra information, such as the application's version number,
* the current user, or any other information of interest.
*
* @note Annotations made before the crash handler are remembered, and sent to the
* crash handler as soon as it's initialized.
*
* @param key Key
* @param value Value
*/
Expand All @@ -184,6 +193,10 @@ public slots:
* Annotations add extra information, such as the application's version number,
* the current user, or any other information of interest.
*
* @note Annotations made before the crash handler are remembered, and sent to the
* crash handler as soon as it's initialized.
*
*
* @param key Key
* @param value Value
*/
Expand Down Expand Up @@ -214,8 +227,10 @@ public slots:
void setStarted(bool started) { _crashMonitorStarted = started; }


bool _crashMonitorStarted {false};
bool _crashReportingEnabled {false};
std::atomic<bool> _crashMonitorStarted {false};
std::atomic<bool> _crashReportingEnabled {false};
std::unordered_map<std::string, std::string> _annotations{};
std::mutex _annotationsMutex{};

QString _path;
QString _crashUrl;
Expand Down

0 comments on commit 7b39475

Please sign in to comment.