From 739c5f9cced56388f14034ca19a94f51de500f75 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Fri, 4 Jun 2021 20:56:57 +0200
Subject: [PATCH] v2.17

---
 CHANGELOG.md                        | 5 ++++-
 satella/__init__.py                 | 2 +-
 satella/coding/concurrent/thread.py | 5 +++--
 satella/opentracing/trace.py        | 8 ++++----
 tests/test_opentracing.py           | 9 +++++++--
 5 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a5de4f71..ec5257b5 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 19faf108..aa83dd80 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 35d1392d..6e2daffb 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 995f2162..73923a6b 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 a3f23f8c..d79e38cb 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
 
-- 
GitLab