Merge "Add exception type to stop trace info"
This commit is contained in:
commit
9d410faa31
|
@ -314,7 +314,11 @@ class Trace(object):
|
|||
start(self._name, info=self._info)
|
||||
|
||||
def __exit__(self, etype, value, traceback):
|
||||
stop()
|
||||
if etype:
|
||||
info = {"etype": reflection.get_class_name(etype)}
|
||||
stop(info=info)
|
||||
else:
|
||||
stop()
|
||||
|
||||
|
||||
class _Profiler(object):
|
||||
|
|
|
@ -156,6 +156,18 @@ class WithTraceTestCase(test.TestCase):
|
|||
mock_stop.reset_mock()
|
||||
mock_stop.assert_called_once_with()
|
||||
|
||||
@mock.patch("osprofiler.profiler.stop")
|
||||
@mock.patch("osprofiler.profiler.start")
|
||||
def test_with_trace_etype(self, mock_start, mock_stop):
|
||||
|
||||
def foo():
|
||||
with profiler.Trace("foo"):
|
||||
raise ValueError("bar")
|
||||
|
||||
self.assertRaises(ValueError, foo)
|
||||
mock_start.assert_called_once_with("foo", info=None)
|
||||
mock_stop.assert_called_once_with(info={"etype": "ValueError"})
|
||||
|
||||
|
||||
@profiler.trace("function", info={"info": "some_info"})
|
||||
def tracede_func(i):
|
||||
|
|
Loading…
Reference in New Issue