Merge pull request #518 from daleglass-overte/store-annotations-before-crash-init

Store annotations before the crash handler initializes
This commit is contained in:
ksuprynowicz 2023-07-16 23:20:52 +02:00 committed by GitHub
commit 7b39475ce9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 4 deletions

View file

@ -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";
}
@ -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<std::mutex> lock(_annotationsMutex);
_annotations[key] = value;
return;
}

View file

@ -14,6 +14,9 @@
#include <QObject>
#include <QCoreApplication>
#include <SettingHandle.h>
#include <atomic>
#include <unordered_map>
#include <mutex>
@ -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<bool> _crashMonitorStarted {false};
std::atomic<bool> _crashReportingEnabled {false};
std::unordered_map<std::string, std::string> _annotations{};
std::mutex _annotationsMutex{};
QString _path;
QString _crashUrl;