diff --git a/sdk/core/azure-core/azure/core/tracing/decorator.py b/sdk/core/azure-core/azure/core/tracing/decorator.py index 7d5d7bfce407..3986dcaf31ed 100644 --- a/sdk/core/azure-core/azure/core/tracing/decorator.py +++ b/sdk/core/azure-core/azure/core/tracing/decorator.py @@ -48,7 +48,7 @@ def wrapper_use_tracer(self, *args, **kwargs): original_span_instance = wrapper_class.get_current_span() parent_span = common.get_parent_span(passed_in_parent) ans = None - if parent_span is not None: + if parent_span is not None and orig_wrapped_span is None: common.set_span_contexts(parent_span) name = name_of_span or self.__class__.__name__ + "." + func.__name__ child = parent_span.span(name=name) diff --git a/sdk/core/azure-core/azure/core/tracing/decorator_async.py b/sdk/core/azure-core/azure/core/tracing/decorator_async.py index 781e20a6bef2..4df65fee77ef 100644 --- a/sdk/core/azure-core/azure/core/tracing/decorator_async.py +++ b/sdk/core/azure-core/azure/core/tracing/decorator_async.py @@ -48,7 +48,7 @@ async def wrapper_use_tracer(self, *args, **kwargs): original_span_instance = wrapper_class.get_current_span() parent_span = common.get_parent_span(passed_in_parent) ans = None - if parent_span is not None: + if parent_span is not None and orig_wrapped_span is None: common.set_span_contexts(parent_span) name = name_of_span or self.__class__.__name__ + "." + func.__name__ child = parent_span.span(name=name) diff --git a/sdk/core/azure-core/tests/azure_core_asynctests/test_tracing_decorator_async.py b/sdk/core/azure-core/tests/azure_core_asynctests/test_tracing_decorator_async.py index 8b43ddf71a62..82b4f97dc92f 100644 --- a/sdk/core/azure-core/tests/azure_core_asynctests/test_tracing_decorator_async.py +++ b/sdk/core/azure-core/tests/azure_core_asynctests/test_tracing_decorator_async.py @@ -139,13 +139,10 @@ async def test_span_with_opencensus_complicated(value): parent = exporter.root assert len(parent.children) == 4 assert parent.children[0].span_data.name == "MockClient.__init__" + assert not parent.children[0].children assert parent.children[1].span_data.name == "MockClient.make_request" - assert parent.children[1].children[0].span_data.name == "MockClient.get_foo" - assert parent.children[1].children[1].span_data.name == "MockClient.make_request" + assert not parent.children[1].children assert parent.children[2].span_data.name == "child" assert parent.children[2].children[0].span_data.name == "MockClient.make_request" assert parent.children[3].span_data.name == "MockClient.make_request" - assert parent.children[3].children[0].span_data.name == "MockClient.get_foo" - assert parent.children[3].children[1].span_data.name == "MockClient.make_request" - children = parent.children[1].children - assert len(children) == 2 + assert not parent.children[3].children diff --git a/sdk/core/azure-core/tests/test_tracing_decorator.py b/sdk/core/azure-core/tests/test_tracing_decorator.py index 473060f6097a..764c09396255 100644 --- a/sdk/core/azure-core/tests/test_tracing_decorator.py +++ b/sdk/core/azure-core/tests/test_tracing_decorator.py @@ -171,13 +171,10 @@ def test_span_with_opencensus_complicated(self, value): parent = exporter.root assert len(parent.children) == 4 assert parent.children[0].span_data.name == "MockClient.__init__" + assert not parent.children[0].children assert parent.children[1].span_data.name == "MockClient.make_request" - assert parent.children[1].children[0].span_data.name == "MockClient.get_foo" - assert parent.children[1].children[1].span_data.name == "MockClient.make_request" + assert not parent.children[1].children assert parent.children[2].span_data.name == "child" assert parent.children[2].children[0].span_data.name == "MockClient.make_request" assert parent.children[3].span_data.name == "MockClient.make_request" - assert parent.children[3].children[0].span_data.name == "MockClient.get_foo" - assert parent.children[3].children[1].span_data.name == "MockClient.make_request" - children = parent.children[1].children - assert len(children) == 2 + assert not parent.children[3].children