diff --git a/CHANGELOG.md b/CHANGELOG.md index 924229572f4eba9cc0b25143b4308209f311997a..990850b5091afbcc094a8b5585263e868bf19918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,4 @@ # v2.17.1 + +* add backwards compatibility for tags_factory + diff --git a/satella/__init__.py b/satella/__init__.py index d41597e9e252c328ccd432bea24e8c295586cca7..d49a0d727f275f2b9117c8058112e519ae50ec9e 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.17.1a1' +__version__ = '2.17.1' diff --git a/satella/opentracing/trace.py b/satella/opentracing/trace.py index 73923a6b0813eb3a6d1871696764533bb6f0dc3f..6596c07aeb02f47340da7005daee24d319d4a572 100644 --- a/satella/opentracing/trace.py +++ b/satella/opentracing/trace.py @@ -52,7 +52,14 @@ 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, **kwargs) + try: + v = value(*args, **kwargs) + except TypeError: + warnings.warn('You are using the deprecated single-parameter version ' + 'of tags_factory. Please upgrade to the newer one.', + DeprecationWarning) + v = value(args) + my_tags[key] = v 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 d79e38cb907b2b9cbbd72e6dcf99496bae3302f2..acbcbc195e3ae53306f454b48b9190efdbed8473 100644 --- a/tests/test_opentracing.py +++ b/tests/test_opentracing.py @@ -14,7 +14,7 @@ class TestOpentracing(unittest.TestCase): self.start_active_span_called = True def start_active_span(self, *args, tags=None, **kwargs): - slf.assertEqual(tags, {'a': 'b', 'c': 'd'}) + slf.assertEqual(tags, {'a': 'b', 'c': 'd', 'e': 'f'}) class MockScope(mock.Mock): def __enter__(self): @@ -28,7 +28,9 @@ class TestOpentracing(unittest.TestCase): tracer = MockTracer() @trace_function(tracer, 'trace_me', - tags_factory= {('a', lambda: 'b'), ('c', lambda: 'd')}) + tags_factory= {'a': lambda: 'b', + 'c': lambda: 'd', + 'e': (lambda args: 'f')}) def trace_me(): pass