From ed99fe8ae47176cb5108ea02116fdcf439c1c6a8 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 20 Jun 2019 00:58:20 +0200 Subject: [PATCH 1/2] ref: Make GNU backtrace integration more lenient --- sentry_sdk/integrations/gnu_backtrace.py | 13 +- tests/integrations/test_gnu_backtrace.py | 228 +++++++---------------- 2 files changed, 72 insertions(+), 169 deletions(-) diff --git a/sentry_sdk/integrations/gnu_backtrace.py b/sentry_sdk/integrations/gnu_backtrace.py index 840d6c7543..b32bb16e0b 100644 --- a/sentry_sdk/integrations/gnu_backtrace.py +++ b/sentry_sdk/integrations/gnu_backtrace.py @@ -20,7 +20,7 @@ (?P{MODULE_RE})\( (?P{TYPE_RE}\ )? ((?P{TYPE_RE}) - (?P\([^)]*\))? + (?P\(.*\))? )? ((?P\ const)?\+0x(?P{HEXVAL_RE}))? \)\s @@ -89,13 +89,10 @@ def _process_gnu_backtrace(event, hint): }, ) ) - elif additional_frames and line.strip(): - # If we already started parsing a stacktrace, it must be at the - # end of the message and must not contain random garbage lines - # between the frames - del additional_frames[:] - break - else: + elif additional_frames: + # Skip garbage lines, not sure what to do with them. + pass + elif line.strip(): new_msg.append(line) if additional_frames: diff --git a/tests/integrations/test_gnu_backtrace.py b/tests/integrations/test_gnu_backtrace.py index e41b6a05ea..28614fb343 100644 --- a/tests/integrations/test_gnu_backtrace.py +++ b/tests/integrations/test_gnu_backtrace.py @@ -1,196 +1,102 @@ +import pytest + from sentry_sdk import capture_exception from sentry_sdk.integrations.gnu_backtrace import GnuBacktraceIntegration -EXC_VALUE = r""" -DB::Exception: Cannot parse datetime. Stack trace: - +LINES = r""" 0. clickhouse-server(StackTrace::StackTrace()+0x16) [0x99d31a6] -1. clickhouse-server(DB::Exception::Exception(std::__cxx11::basic_string, std::allocator > const&, int)+0x22) [0x3089bb2] -2. clickhouse-server(void DB::readDateTimeTextFallback(long&, DB::ReadBuffer&, DateLUTImpl const&)+0x318) [0x99ffed8] -3. clickhouse-server(DB::FunctionComparison::executeDateOrDateTimeOrEnumOrUUIDWithConstString(DB::Block&, unsigned long, DB::IColumn const*, DB::IColumn const*, std::shared_ptr const&, std::shared_ptr const&, bool, unsigned long)+0xbb3) [0x411dee3] -4. clickhouse-server(DB::FunctionComparison::executeImpl(DB::Block&, std::vector > const&, unsigned long, unsigned long)+0x576) [0x41ab006] -5. clickhouse-server(DB::PreparedFunctionImpl::execute(DB::Block&, std::vector > const&, unsigned long, unsigned long)+0x3e2) [0x7933492] -6. clickhouse-server(DB::ExpressionAction::execute(DB::Block&, std::unordered_map, std::allocator >, unsigned long, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, unsigned long> > >&) const+0x61a) [0x7ae093a] -7. clickhouse-server(DB::ExpressionActions::execute(DB::Block&) const+0xe6) [0x7ae1e06] -8. clickhouse-server(DB::FilterBlockInputStream::FilterBlockInputStream(std::shared_ptr const&, std::shared_ptr const&, std::__cxx11::basic_string, std::allocator > const&, bool)+0x711) [0x79970d1] -9. clickhouse-server() [0x75bd5a3] +1. clickhouse-server(DB::Exception::Exception(std::__cxx11::basic_string, std::allocator > const&, int)+0x22) [0x372c822] +10. clickhouse-server(DB::ActionsVisitor::visit(std::shared_ptr const&)+0x1a12) [0x6ae45d2] 10. clickhouse-server(DB::InterpreterSelectQuery::executeImpl(DB::InterpreterSelectQuery::Pipeline&, std::shared_ptr const&, bool)+0x11af) [0x75c68ff] +10. clickhouse-server(ThreadPoolImpl::worker(std::_List_iterator)+0x1ab) [0x6f90c1b] +11. clickhouse-server() [0xae06ddf] +11. clickhouse-server(DB::ExpressionAnalyzer::getRootActions(std::shared_ptr const&, bool, std::shared_ptr&, bool)+0xdb) [0x6a0a63b] 11. clickhouse-server(DB::InterpreterSelectQuery::InterpreterSelectQuery(std::shared_ptr const&, DB::Context const&, std::shared_ptr const&, std::shared_ptr const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, DB::QueryProcessingStage::Enum, unsigned long, bool)+0x5e6) [0x75c7516] +12. /lib/x86_64-linux-gnu/libpthread.so.0(+0x8184) [0x7f3bbc568184] +12. clickhouse-server(DB::ExpressionAnalyzer::getConstActions()+0xc9) [0x6a0b059] 12. clickhouse-server(DB::InterpreterSelectQuery::InterpreterSelectQuery(std::shared_ptr const&, DB::Context const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, DB::QueryProcessingStage::Enum, unsigned long, bool)+0x56) [0x75c8276] +13. /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f3bbbb8303d] 13. clickhouse-server(DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::shared_ptr const&, DB::Context const&, std::vector, std::allocator >, std::allocator, std::allocator > > > const&, DB::QueryProcessingStage::Enum, unsigned long, bool)+0x7e7) [0x75d4067] +13. clickhouse-server(DB::evaluateConstantExpression(std::shared_ptr const&, DB::Context const&)+0x3ed) [0x656bfdd] 14. clickhouse-server(DB::InterpreterFactory::get(std::shared_ptr&, DB::Context&, DB::QueryProcessingStage::Enum)+0x3a8) [0x75b0298] +14. clickhouse-server(DB::makeExplicitSet(DB::ASTFunction const*, DB::Block const&, bool, DB::Context const&, DB::SizeLimits const&, std::unordered_map, DB::PreparedSetKey::Hash, std::equal_to, std::allocator > > >&)+0x382) [0x6adf692] 15. clickhouse-server() [0x7664c79] +15. clickhouse-server(DB::ActionsVisitor::makeSet(DB::ASTFunction const*, DB::Block const&)+0x2a7) [0x6ae2227] +16. clickhouse-server(DB::ActionsVisitor::visit(std::shared_ptr const&)+0x1973) [0x6ae4533] 16. clickhouse-server(DB::executeQuery(std::__cxx11::basic_string, std::allocator > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum)+0x8a) [0x76669fa] +17. clickhouse-server(DB::ActionsVisitor::visit(std::shared_ptr const&)+0x1324) [0x6ae3ee4] 17. clickhouse-server(DB::TCPHandler::runImpl()+0x4b9) [0x30973c9] +18. clickhouse-server(DB::ExpressionAnalyzer::getRootActions(std::shared_ptr const&, bool, std::shared_ptr&, bool)+0xdb) [0x6a0a63b] 18. clickhouse-server(DB::TCPHandler::run()+0x2b) [0x30985ab] +19. clickhouse-server(DB::ExpressionAnalyzer::appendGroupBy(DB::ExpressionActionsChain&, bool)+0x100) [0x6a0b4f0] 19. clickhouse-server(Poco::Net::TCPServerConnection::start()+0xf) [0x9b53e4f] +2. clickhouse-server(DB::FunctionTuple::getReturnTypeImpl(std::vector, std::allocator > > const&) const+0x122) [0x3a2a0f2] +2. clickhouse-server(DB::readException(DB::Exception&, DB::ReadBuffer&, std::__cxx11::basic_string, std::allocator > const&)+0x21f) [0x6fb253f] +2. clickhouse-server(void DB::readDateTimeTextFallback(long&, DB::ReadBuffer&, DateLUTImpl const&)+0x318) [0x99ffed8] +20. clickhouse-server(DB::InterpreterSelectQuery::analyzeExpressions(DB::QueryProcessingStage::Enum, bool)+0x364) [0x6437fa4] 20. clickhouse-server(Poco::Net::TCPServerDispatcher::run()+0x16a) [0x9b5422a] +21. clickhouse-server(DB::InterpreterSelectQuery::executeImpl(DB::InterpreterSelectQuery::Pipeline&, std::shared_ptr const&, bool)+0x36d) [0x643c28d] 21. clickhouse-server(Poco::PooledThread::run()+0x77) [0x9c70f37] +22. clickhouse-server(DB::InterpreterSelectQuery::executeWithMultipleStreams()+0x50) [0x643ecd0] 22. clickhouse-server(Poco::ThreadImpl::runnableEntry(void*)+0x38) [0x9c6caa8] 23. clickhouse-server() [0xa3c68cf] +23. clickhouse-server(DB::InterpreterSelectWithUnionQuery::executeWithMultipleStreams()+0x6c) [0x644805c] 24. /lib/x86_64-linux-gnu/libpthread.so.0(+0x8184) [0x7fe839d2d184] +24. clickhouse-server(DB::InterpreterSelectWithUnionQuery::execute()+0x38) [0x6448658] 25. /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7fe83934803d] +25. clickhouse-server() [0x65744ef] +26. clickhouse-server(DB::executeQuery(std::__cxx11::basic_string, std::allocator > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool)+0x81) [0x6576141] +27. clickhouse-server(DB::TCPHandler::runImpl()+0x752) [0x3739f82] +28. clickhouse-server(DB::TCPHandler::run()+0x2b) [0x373a5cb] +29. clickhouse-server(Poco::Net::TCPServerConnection::start()+0xf) [0x708e63f] +3. clickhouse-server(DB::Connection::receiveException()+0x81) [0x67d3ad1] +3. clickhouse-server(DB::DefaultFunctionBuilder::getReturnTypeImpl(std::vector > const&) const+0x223) [0x38ac3b3] +3. clickhouse-server(DB::FunctionComparison::executeDateOrDateTimeOrEnumOrUUIDWithConstString(DB::Block&, unsigned long, DB::IColumn const*, DB::IColumn const*, std::shared_ptr const&, std::shared_ptr const&, bool, unsigned long)+0xbb3) [0x411dee3] +30. clickhouse-server(Poco::Net::TCPServerDispatcher::run()+0xe9) [0x708ed79] +31. clickhouse-server(Poco::PooledThread::run()+0x81) [0x7142011] +4. clickhouse-server(DB::Connection::receivePacket()+0x767) [0x67d9cd7] +4. clickhouse-server(DB::FunctionBuilderImpl::getReturnTypeWithoutLowCardinality(std::vector > const&) const+0x75) [0x6869635] +4. clickhouse-server(DB::FunctionComparison::executeImpl(DB::Block&, std::vector > const&, unsigned long, unsigned long)+0x576) [0x41ab006] +5. clickhouse-server(DB::FunctionBuilderImpl::getReturnType(std::vector > const&) const+0x350) [0x6869f10] +5. clickhouse-server(DB::MultiplexedConnections::receivePacket()+0x7e) [0x67e7ede] +5. clickhouse-server(DB::PreparedFunctionImpl::execute(DB::Block&, std::vector > const&, unsigned long, unsigned long)+0x3e2) [0x7933492] +6. clickhouse-server(DB::ExpressionAction::execute(DB::Block&, std::unordered_map, std::allocator >, unsigned long, std::hash, std::allocator > >, std::equal_to, std::allocator > >, std::allocator, std::allocator > const, unsigned long> > >&) const+0x61a) [0x7ae093a] +6. clickhouse-server(DB::FunctionBuilderImpl::build(std::vector > const&) const+0x3c) [0x38accfc] +6. clickhouse-server(DB::RemoteBlockInputStream::readImpl()+0x87) [0x631da97] +7. clickhouse-server(DB::ExpressionActions::addImpl(DB::ExpressionAction, std::vector, std::allocator >, std::allocator, std::allocator > > >&)+0x552) [0x6a00052] +7. clickhouse-server(DB::ExpressionActions::execute(DB::Block&) const+0xe6) [0x7ae1e06] +7. clickhouse-server(DB::IBlockInputStream::read()+0x178) [0x63075e8] +8. clickhouse-server(DB::ExpressionActions::add(DB::ExpressionAction const&, std::vector, std::allocator >, std::allocator, std::allocator > > >&)+0x42) [0x6a00422] +8. clickhouse-server(DB::FilterBlockInputStream::FilterBlockInputStream(std::shared_ptr const&, std::shared_ptr const&, std::__cxx11::basic_string, std::allocator > const&, bool)+0x711) [0x79970d1] +8. clickhouse-server(DB::ParallelInputsProcessor::thread(std::shared_ptr, unsigned long)+0x2f1) [0x64467c1] +9. clickhouse-server() [0x75bd5a3] +9. clickhouse-server(DB::ScopeStack::addAction(DB::ExpressionAction const&)+0xd2) [0x6ae04d2] +9. clickhouse-server(ThreadFromGlobalPool::ThreadFromGlobalPool::process()::{lambda()#1}>(DB::ParallelInputsProcessor::process()::{lambda()#1}&&)::{lambda()#1}::operator()() const+0x6d) [0x644722d] """ -def test_basic(sentry_init, capture_events): +@pytest.mark.parametrize("input", LINES.strip().splitlines()) +def test_basic(sentry_init, capture_events, input): sentry_init(integrations=[GnuBacktraceIntegration()]) events = capture_events() try: - raise ValueError(EXC_VALUE) + raise ValueError(input) except ValueError: capture_exception() event, = events exception, = event["exception"]["values"] - assert exception["value"] == ( - "\n" - "DB::Exception: Cannot parse datetime. Stack trace:\n" - "\n" - "" + assert ( + exception["value"] + == "" ) + frame, = exception["stacktrace"]["frames"][1:] - assert exception["stacktrace"]["frames"][1:] == [ - { - "function": "clone", - "in_app": True, - "package": "/lib/x86_64-linux-gnu/libc.so.6", - "platform": "native", - }, - { - "in_app": True, - "package": "/lib/x86_64-linux-gnu/libpthread.so.0", - "platform": "native", - }, - {"in_app": True, "package": "clickhouse-server", "platform": "native"}, - { - "function": "Poco::ThreadImpl::runnableEntry", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "Poco::PooledThread::run", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "Poco::Net::TCPServerDispatcher::run", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "Poco::Net::TCPServerConnection::start", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::TCPHandler::run", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::TCPHandler::runImpl", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::executeQuery", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - {"in_app": True, "package": "clickhouse-server", "platform": "native"}, - { - "function": "DB::InterpreterFactory::get", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::InterpreterSelectQuery::InterpreterSelectQuery", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::InterpreterSelectQuery::InterpreterSelectQuery", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::InterpreterSelectQuery::executeImpl", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - {"in_app": True, "package": "clickhouse-server", "platform": "native"}, - { - "function": "DB::FilterBlockInputStream::FilterBlockInputStream", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::ExpressionActions::execute", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::ExpressionAction::execute", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::PreparedFunctionImpl::execute", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::NameNotEquals>::executeImpl", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::NameNotEquals>::executeDateOrDateTimeOrEnumOrUUIDWithConstString", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::readDateTimeTextFallback", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "DB::Exception::Exception", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - { - "function": "StackTrace::StackTrace", - "in_app": True, - "package": "clickhouse-server", - "platform": "native", - }, - ] + if "function" not in frame: + assert "clickhouse-server()" in input or "pthread" in input + else: + assert frame["function"] + assert ")" not in frame["function"] and "(" not in frame["function"] + assert frame["function"] in input From 9df5ceb372c9af315eea9bed7d442d278af7e83a Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 20 Jun 2019 01:01:37 +0200 Subject: [PATCH 2/2] ref: Preserve all lines --- sentry_sdk/integrations/gnu_backtrace.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/integrations/gnu_backtrace.py b/sentry_sdk/integrations/gnu_backtrace.py index b32bb16e0b..7178693233 100644 --- a/sentry_sdk/integrations/gnu_backtrace.py +++ b/sentry_sdk/integrations/gnu_backtrace.py @@ -89,10 +89,8 @@ def _process_gnu_backtrace(event, hint): }, ) ) - elif additional_frames: - # Skip garbage lines, not sure what to do with them. - pass - elif line.strip(): + else: + # Put garbage lines back into message, not sure what to do with them. new_msg.append(line) if additional_frames: