diff --git a/CHANGELOG.md b/CHANGELOG.md index a5de4f71bb153a2abe7cb2ec7c16e78f35dea763..ec5257b56ddf0dd77d1cef5072b166fa0f17a02e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -# v2.16.8 +# v2.17 * added extra attribute to `Future`s returned by call_in_separate_thread +* fixed a bug with `trace_function's` `tags_factory` + +WARNING!! Slight API change there. diff --git a/satella/__init__.py b/satella/__init__.py index 19faf1080da9eed5cc56d8eabe29a8ff9e2e9dba..aa83dd809f1708a184177879a42c7753284ff8d7 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.16.8a1' +__version__ = '2.17' diff --git a/satella/coding/concurrent/thread.py b/satella/coding/concurrent/thread.py index 35d1392d14d1686f06f8d9f99254bd17827bca6f..6e2daffb6768152aa2c9225c5b3b88cd0b5ef4ab 100644 --- a/satella/coding/concurrent/thread.py +++ b/satella/coding/concurrent/thread.py @@ -24,7 +24,8 @@ def call_in_separate_thread(*t_args, no_thread_attribute: bool = False, (or the exception) of the function. The returned Future will have an extra attribute, "thread" that is - thread that was spawned for it. + thread that was spawned for it. The returned thread will in turn + have an attribute "future" that links to this future. .. warning:: calling this will cause reference loops, so don't use it if you've disabled Python GC, or in that case enable @@ -33,7 +34,7 @@ def call_in_separate_thread(*t_args, no_thread_attribute: bool = False, The arguments given here will be passed to thread's constructor, so use like: :param no_thread_attribute: if set to True, future won't have a link returned to - it's thread + it's thread. The thread will have attribute of "future" anyways. :param delay: seconds to wait before launching function >>> @call_in_separate_thread(daemon=True) diff --git a/satella/opentracing/trace.py b/satella/opentracing/trace.py index 995f2162c1c26fa54dd9702103536d26364b044b..73923a6b0813eb3a6d1871696764533bb6f0dc3f 100644 --- a/satella/opentracing/trace.py +++ b/satella/opentracing/trace.py @@ -35,9 +35,9 @@ def trace_function(tracer, name: str, tags: tp.Optional[dict] = None, :param tracer: tracer to use :param name: Name of the trace :param tags: optional tags to use - :param tags_factory: a list of tuple (tag name, callable that is called with *args passed to - this function as a sole argument). Extra tags will be generated from this. - Can be also a dict. + :param tags_factory: a list of tuple (tag name, callable that is called with *args + and **kwargs passed to this function as a sole argument). Extra tags will be generated + from this. Can be also a dict. """ if isinstance(tags_factory, dict): tags_factory = list(tags_factory.items()) @@ -52,7 +52,7 @@ def trace_function(tracer, name: str, tags: tp.Optional[dict] = None, tags = {} my_tags = copy.copy(tags) for key, value in tags_factory: - my_tags[key] = value(args) + my_tags[key] = value(*args, **kwargs) with tracer.start_active_span(name, tags=my_tags): return fun(*args, **kwargs) diff --git a/tests/test_opentracing.py b/tests/test_opentracing.py index a3f23f8cd9fd5f3a731d2fb4003336b0b2036f5a..d79e38cb907b2b9cbbd72e6dcf99496bae3302f2 100644 --- a/tests/test_opentracing.py +++ b/tests/test_opentracing.py @@ -7,11 +7,15 @@ from unittest import mock class TestOpentracing(unittest.TestCase): def test_trace_function(self): + slf = self + class MockTracer: def __init__(self): self.start_active_span_called = True - def start_active_span(self, *args, **kwargs): + def start_active_span(self, *args, tags=None, **kwargs): + slf.assertEqual(tags, {'a': 'b', 'c': 'd'}) + class MockScope(mock.Mock): def __enter__(self): return self @@ -23,7 +27,8 @@ class TestOpentracing(unittest.TestCase): tracer = MockTracer() - @trace_function(tracer, 'trace_me') + @trace_function(tracer, 'trace_me', + tags_factory= {('a', lambda: 'b'), ('c', lambda: 'd')}) def trace_me(): pass