Crash log: development

This commit is contained in:
Alexey Milovidov 2020-07-31 23:16:31 +03:00
parent 59840c725c
commit 9ef9d31f03
7 changed files with 43 additions and 18 deletions

View File

@ -53,6 +53,8 @@
#include <Common/Config/ConfigProcessor.h>
#include <Common/SymbolIndex.h>
#include <Interpreters/CrashLog.h>
#if !defined(ARCADIA_BUILD)
# include <Common/config_version.h>
#endif
@ -308,16 +310,12 @@ private:
/// Write symbolized stack trace line by line for better grep-ability.
stack_trace.toStringEveryLine([&](const std::string & s) { LOG_FATAL(log, s); });
/// Write crash to system.crash_log table if available.
DB::CrashLog::collect(sig, thread_num, query_id, stack_trace);
/// Send crash report to developers (if configured)
#if defined(__ELF__) && !defined(__FreeBSD__)
const String & build_id_hex = DB::SymbolIndex::instance().getBuildIDHex();
#else
String build_id_hex{};
#endif
if (sig != SanitizerTrap)
SentryWriter::onFault(sig, error_message, stack_trace, build_id_hex);
SentryWriter::onFault(sig, error_message, stack_trace);
/// When everything is done, we will try to send these error messages to client.
if (thread_ptr)

View File

@ -8,6 +8,7 @@
#include <common/getFQDNOrHostName.h>
#include <common/logger_useful.h>
#include <Common/SymbolIndex.h>
#include <Common/StackTrace.h>
#if !defined(ARCADIA_BUILD)
@ -157,7 +158,7 @@ void SentryWriter::shutdown()
sentry_shutdown();
}
void SentryWriter::onFault(int sig, const std::string & error_message, const StackTrace & stack_trace, const std::string & build_id_hex)
void SentryWriter::onFault(int sig, const std::string & error_message, const StackTrace & stack_trace)
{
auto * logger = &Poco::Logger::get("SentryWriter");
if (initialized)
@ -165,10 +166,12 @@ void SentryWriter::onFault(int sig, const std::string & error_message, const Sta
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())
{
#if defined(__ELF__) && !defined(__FreeBSD__)
const String & build_id_hex = DB::SymbolIndex::instance().getBuildIDHex();
sentry_set_tag("build_id", build_id_hex.c_str());
}
#endif
setExtras();
/// Prepare data for https://develop.sentry.dev/sdk/event-payloads/stacktrace/
@ -240,6 +243,6 @@ void SentryWriter::onFault(int sig, const std::string & error_message, const Sta
void SentryWriter::initialize(Poco::Util::LayeredConfiguration &) {}
void SentryWriter::shutdown() {}
void SentryWriter::onFault(int, const std::string &, const StackTrace &, const std::string &) {}
void SentryWriter::onFault(int, const std::string &, const StackTrace &) {}
#endif

View File

@ -23,7 +23,5 @@ namespace SentryWriter
void onFault(
int sig,
const std::string & error_message,
const StackTrace & stack_trace,
const std::string & build_id_hex
);
const StackTrace & stack_trace);
};

View File

@ -308,7 +308,8 @@ const StackTrace::FramePointers & StackTrace::getFramePointers() const
return frame_pointers;
}
static void toStringEveryLineImpl(const StackTrace::FramePointers & frame_pointers, size_t offset, size_t size, std::function<void(const std::string &)> callback)
static void toStringEveryLineImpl(
const StackTrace::FramePointers & frame_pointers, size_t offset, size_t size, std::function<void(const std::string &)> callback)
{
if (size == 0)
return callback("<Empty trace>");

View File

@ -141,7 +141,8 @@ void TraceCollector::run()
if (trace_log)
{
TraceLogElement element{std::time(nullptr), clock_gettime_ns(), trace_type, thread_id, query_id, trace, size};
UInt64 time = clock_gettime_ns();
TraceLogElement element{time_t(time / 1000000000), time, trace_type, thread_id, query_id, trace, size};
trace_log->add(element);
}
}

View File

@ -58,4 +58,26 @@ void CrashLogElement::appendToBlock(MutableColumns & columns) const
columns[i++]->insert(build_id_hex);
}
void CrashLog::collect(Int32 signal, UInt64 thread_id, const String & query_id, const StackTrace & stack_trace)
{
UInt64 time = clock_gettime_ns();
size_t stack_trace_size = stack_trace.getSize();
size_t stack_trace_offset = stack_trace.getOffset();
size_t num_frames = stack_trace_size - stack_trace_offset;
Array trace;
Array trace_full;
trace.reserve(num_frames);
trace_full.reserve(num_frames);
for (size_t i = stack_trace_offset; i < stack_trace_size; ++i)
trace.push_back(reinterpret_cast<uintptr_t>(stack_trace.getFramePointers()[i]));
stack_trace.toStringEveryLine([&trace_full](const std::string & line) { trace_full.push_back(line); });
CrashLogElement element{time_t(time / 1000000000), time, signal, thread_id, query_id, trace, trace_full};
}
}

View File

@ -40,6 +40,8 @@ public:
if (auto crash_log_owned = crash_log.lock())
crash_log_owned->add(element);
}
static void collect(Int32 signal, UInt64 thread_id, const String & query_id, const StackTrace & stack_trace);
};
}