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

add trace_future

parent 10fa3336
No related branches found
No related tags found
No related merge requests found
# v2.9.15
* add `trace_future`
......@@ -30,6 +30,7 @@ Visit the project's page at GitHub_!
exceptions
processes
cassandra
opentracing
Indices and tables
......
**This module is available only if you have opentracing installed**
OpenTracing
===========
trace_future
------------
.. autofunction:: satella.opentracing.trace_future
__version__ = '2.9.15_a1'
__version__ = '2.9.15_a2'
from .trace import trace_future
__all__ = ['trace_future']
import typing as tp
from concurrent.futures import Future
try:
from opentracing import Span
except ImportError:
class Span:
pass
try:
from cassandra.cluster import ResponseFuture
except ImportError:
class ResponseFuture:
pass
def trace_future(future: tp.Union[ResponseFuture, Future], span: Span):
"""
Install a handler that will close a span upon a future completing, attaching the exception
contents if the future ends with an exception.
:param future: can be either a normal Future or a Cassandra's ResponseFuture
:param span: span to close
"""
if isinstance(future, ResponseFuture):
def close_exception(exc):
Span._on_error(span, type(exc), exc, '<unavailable>')
span.finish()
future.add_callback(span.finish)
future.add_errback(close_exception)
else:
def close_future(fut):
exc = fut.exception()
if exc is not None:
Span._on_error(span, type(exc), exc, '<unavailable>')
span.finish()
future.add_done_callback(close_future)
......@@ -15,6 +15,7 @@ setup(keywords=['ha', 'high availability', 'scalable', 'scalability', 'server',
'YAMLSource': ['pyyaml'],
'TOMLSource': ['toml'],
'FasterJSONSource': ['ujson'],
'cassandra': ['cassandra-driver']
'cassandra': ['cassandra-driver'],
'opentracing': ['opentracing']
}
)
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