Skip to content
Snippets Groups Projects
Commit 95c91ade authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

add trace_exception, v2.12

parent db6f9ce4
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,5 @@
* added `intify`
* added `satella.coding.typing`
* added `satella.opentracing.trace_exception`
......@@ -12,3 +12,9 @@ trace_function
--------------
.. autofunction:: satella.opentracing.trace_function
trace_exception
---------------
.. autofunction:: satella.opentracing.trace_exception
__version__ = '2.11.36_a5'
__version__ = '2.12'
from .trace import trace_future, trace_function
__all__ = ['trace_future', 'trace_function']
from .exceptions import trace_exception
__all__ = ['trace_future', 'trace_function', 'trace_exception']
import sys
import types
import typing as tp
from satella.coding.typing import ExceptionClassType
from satella.instrumentation import Traceback
from satella.opentracing.trace import Span
def trace_exception(span: Span, exc_type: tp.Optional[ExceptionClassType] = None,
exc_val: tp.Optional[Exception] = None,
exc_tb: tp.Optional[types.TracebackType] = None) -> None:
"""
Log an exception's information to the chosen span, as logs and tags.
:param span: span to log into
:param exc_type: exception type. If None this will be taken from sys.exc_info.
:param exc_val: exception value. If None this will be taken from sys.exc_info.
:param exc_tb: exception traceback. If None this will be taken from sys.exc_info.
"""
if exc_type is None:
exc_type, exc_val, exc_tb = sys.exc_info()
if exc_type is None:
return
span.set_tag('error', True)
span.log_kv({'event': 'error',
'message': str(exc_val),
'error.object': exc_val,
'error.kind': exc_type,
'stack': Traceback(exc_tb.tb_frame).pretty_format()
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment