diff --git a/libraries/networking/src/crash-handler/CrashHandler.cpp b/libraries/networking/src/crash-handler/CrashHandler.cpp index 71ab38ec1a..4dc724fe1c 100644 --- a/libraries/networking/src/crash-handler/CrashHandler.cpp +++ b/libraries/networking/src/crash-handler/CrashHandler.cpp @@ -50,6 +50,20 @@ bool CrashHandler::start() { if ( started ) { qCInfo(crash_handler) << "Crash handler started"; + std::size_t countAdded = 0; + + { + std::lock_guard 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"; } @@ -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) { @@ -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 lock(_annotationsMutex); + _annotations[key] = value; return; } diff --git a/libraries/networking/src/crash-handler/CrashHandler.h b/libraries/networking/src/crash-handler/CrashHandler.h index 3f863326ad..d2e8a4b5b5 100644 --- a/libraries/networking/src/crash-handler/CrashHandler.h +++ b/libraries/networking/src/crash-handler/CrashHandler.h @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include @@ -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 */ @@ -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 */ @@ -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 */ @@ -214,8 +227,10 @@ private: void setStarted(bool started) { _crashMonitorStarted = started; } - bool _crashMonitorStarted {false}; - bool _crashReportingEnabled {false}; + std::atomic _crashMonitorStarted {false}; + std::atomic _crashReportingEnabled {false}; + std::unordered_map _annotations{}; + std::mutex _annotationsMutex{}; QString _path; QString _crashUrl;