def wrapper_use_tracer(self, *args, **kwargs):
     # type: (Any) -> Any
     passed_in_parent = kwargs.pop("parent_span", None)
     orig_wrapped_span = tracing_context.current_span.get()
     wrapper_class = settings.tracing_implementation()
     original_span_instance = None
     if wrapper_class is not None:
         original_span_instance = wrapper_class.get_current_span()
     parent_span = common.get_parent_span(passed_in_parent)
     ans = None
     if common.should_use_trace(parent_span):
         common.set_span_contexts(parent_span)
         name = name_of_span or self.__class__.__name__ + "." + func.__name__
         child = parent_span.span(name=name)
         child.start()
         common.set_span_contexts(child)
         ans = func(self, *args, **kwargs)
         child.finish()
         common.set_span_contexts(parent_span)
         if orig_wrapped_span is None and passed_in_parent is None and original_span_instance is None:
             parent_span.finish()
         common.set_span_contexts(orig_wrapped_span,
                                  span_instance=original_span_instance)
     else:
         ans = func(self, *args, **kwargs)
     return ans
 def wrapper_use_tracer(*args, **kwargs):
     # type: (Any, Any) -> Any
     passed_in_parent = kwargs.pop("parent_span", None)
     orig_wrapped_span = tracing_context.current_span.get()
     wrapper_class = settings.tracing_implementation()
     original_span_instance = None
     if wrapper_class is not None:
         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 and orig_wrapped_span is None:
         common.set_span_contexts(parent_span)
         name = name_of_span or common.get_function_and_class_name(func, *args)  # type: ignore
         child = parent_span.span(name=name)
         child.start()
         common.set_span_contexts(child)
         ans = func(*args, **kwargs) # type: ignore
         child.finish()
         common.set_span_contexts(parent_span)
         if orig_wrapped_span is None and passed_in_parent is None and original_span_instance is None:
             parent_span.finish()
         common.set_span_contexts(orig_wrapped_span, span_instance=original_span_instance)
     else:
         ans = func(*args, **kwargs) # type: ignore
     return ans
Beispiel #3
0
    def test_get_parent_span(self):
        with ContextHelper():
            opencensus = sys.modules["opencensus"]
            del sys.modules["opencensus"]

            parent = common.get_parent_span(None)
            assert parent is None

            sys.modules["opencensus"] = opencensus
            parent = common.get_parent_span(None)
            assert parent.span_instance.name == "azure-sdk-for-python-first_parent_span"

            tracer = tracer_module.Tracer(sampler=AlwaysOnSampler())
            parent = common.get_parent_span(None)
            assert parent.span_instance.name == "azure-sdk-for-python-first_parent_span"
            parent.finish()

            some_span = tracer.start_span(name="some_span")
            new_parent = common.get_parent_span(None)
            assert new_parent.span_instance.name == "some_span"
            some_span.finish()

            should_be_old_parent = common.get_parent_span(parent.span_instance)
            assert should_be_old_parent.span_instance == parent.span_instance