Merge "In case of an error, always add message"

This commit is contained in:
Zuul 2018-12-22 03:34:15 +00:00 committed by Gerrit Code Review
commit 97564b644f
4 changed files with 8 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import collections
import datetime import datetime
import functools import functools
import inspect import inspect
import six
import socket import socket
import threading import threading
@ -158,7 +159,10 @@ def trace(name, info=None, hide_args=False, hide_result=True,
start(name, info=info_) start(name, info=info_)
result = f(*args, **kwargs) result = f(*args, **kwargs)
except Exception as ex: except Exception as ex:
stop_info = {"etype": reflection.get_class_name(ex)} stop_info = {
"etype": reflection.get_class_name(ex),
"message": six.text_type(ex)
}
raise raise
else: else:
if not hide_result: if not hide_result:

View File

@ -105,6 +105,7 @@ def handle_error(exception_context):
info = { info = {
"etype": exception_class_name, "etype": exception_class_name,
"message": original_exception,
"db": { "db": {
"original_exception": original_exception, "original_exception": original_exception,
"chained_exception": chained_exception "chained_exception": chained_exception

View File

@ -260,7 +260,7 @@ class TraceDecoratorTestCase(test.TestCase):
"name": "osprofiler.tests.unit.test_profiler.test_fn_exc" "name": "osprofiler.tests.unit.test_profiler.test_fn_exc"
} }
} }
expected_stop_info = {"etype": "ValueError"} expected_stop_info = {"etype": "ValueError", "message": ""}
mock_start.assert_called_once_with("foo", info=expected_info) mock_start.assert_called_once_with("foo", info=expected_info)
mock_stop.assert_called_once_with(info=expected_stop_info) mock_stop.assert_called_once_with(info=expected_stop_info)

View File

@ -62,6 +62,7 @@ class SqlalchemyTracingTestCase(test.TestCase):
sqlalchemy.handle_error(sqlalchemy_exception_ctx) sqlalchemy.handle_error(sqlalchemy_exception_ctx)
expected_info = { expected_info = {
"etype": "Exception", "etype": "Exception",
"message": "error",
"db": { "db": {
"original_exception": str(original_exception), "original_exception": str(original_exception),
"chained_exception": str(chained_exception), "chained_exception": str(chained_exception),