From 3ed76a388e20636441472331c1a7a73f43f9b5fe Mon Sep 17 00:00:00 2001 From: Ivan Blinkov Date: Wed, 24 Jun 2020 00:27:04 +0300 Subject: [PATCH] send build_id to sentry as well + fix some minor issues --- base/daemon/BaseDaemon.cpp | 9 ++++++++- base/daemon/SentryWriter.cpp | 6 +++++- base/daemon/SentryWriter.h | 3 ++- src/Common/StackTrace.cpp | 2 +- src/Common/StackTrace.h | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/base/daemon/BaseDaemon.cpp b/base/daemon/BaseDaemon.cpp index 204f16078cb..e7ccf84d7da 100644 --- a/base/daemon/BaseDaemon.cpp +++ b/base/daemon/BaseDaemon.cpp @@ -298,7 +298,14 @@ private: stack_trace.toStringEveryLine([&](const std::string & s) { LOG_FATAL(log, s); }); /// Send crash report to developers (if configured) - SentryWriter::onFault(sig, info, context, stack_trace); + + #if defined(__ELF__) && !defined(__FreeBSD__) + const String & build_id_hex = DB::SymbolIndex::instance().getBuildIDHex(); + #else + String build_id_hex{}; + #endif + + SentryWriter::onFault(sig, info, context, stack_trace, build_id_hex); /// When everything is done, we will try to send these error messages to client. if (thread_ptr) diff --git a/base/daemon/SentryWriter.cpp b/base/daemon/SentryWriter.cpp index ab560f4d8a1..298e069092a 100644 --- a/base/daemon/SentryWriter.cpp +++ b/base/daemon/SentryWriter.cpp @@ -161,7 +161,7 @@ void SentryWriter::shutdown() #endif } -void SentryWriter::onFault(int sig, const siginfo_t & info, const ucontext_t & context, const StackTrace & stack_trace) +void SentryWriter::onFault(int sig, const siginfo_t & info, const ucontext_t & context, const StackTrace & stack_trace, const String & build_id_hex) { #if USE_SENTRY auto * logger = &Poco::Logger::get("SentryWriter"); @@ -171,6 +171,10 @@ void SentryWriter::onFault(int sig, const siginfo_t & info, const ucontext_t & c sentry_value_t event = sentry_value_new_message_event(SENTRY_LEVEL_FATAL, "fault", error_message.c_str()); sentry_set_tag("signal", strsignal(sig)); sentry_set_extra("signal_number", sentry_value_new_int32(sig)); + if (!build_id_hex.empty()) + { + sentry_set_tag("build_id", build_id_hex.c_str()); + } setExtras(); /// Prepare data for https://develop.sentry.dev/sdk/event-payloads/stacktrace/ diff --git a/base/daemon/SentryWriter.h b/base/daemon/SentryWriter.h index 655a4e93bfd..a7b255e72bf 100644 --- a/base/daemon/SentryWriter.h +++ b/base/daemon/SentryWriter.h @@ -27,6 +27,7 @@ public: int sig, const siginfo_t & info, const ucontext_t & context, - const StackTrace & stack_trace + const StackTrace & stack_trace, + const String & build_id_hex ); }; diff --git a/src/Common/StackTrace.cpp b/src/Common/StackTrace.cpp index 1ea5d100440..9c6904b884c 100644 --- a/src/Common/StackTrace.cpp +++ b/src/Common/StackTrace.cpp @@ -308,7 +308,7 @@ const StackTrace::FramePointers & StackTrace::getFramePointers() const return frame_pointers; } -static void toStringEveryLineImpl(const void * const * frame_pointers, size_t offset, size_t size, std::function callback) +static void toStringEveryLineImpl(const StackTrace::FramePointers & frame_pointers, size_t offset, size_t size, std::function callback) { if (size == 0) return callback(""); diff --git a/src/Common/StackTrace.h b/src/Common/StackTrace.h index 374f0314533..3ae4b964838 100644 --- a/src/Common/StackTrace.h +++ b/src/Common/StackTrace.h @@ -54,7 +54,7 @@ public: std::string toString() const; static std::string toString(void ** frame_pointers, size_t offset, size_t size); - static void symbolize(const void * const * frame_pointers, size_t offset, size_t size, StackTrace::Frames & frames); + static void symbolize(const FramePointers & frame_pointers, size_t offset, size_t size, StackTrace::Frames & frames); void toStringEveryLine(std::function callback) const; protected: