def test_get_function_and_class_name(self):
     with ContextHelper():
         client = MockClient()
         assert common.get_function_and_class_name(
             client.get_foo, client) == "MockClient.get_foo"
         assert common.get_function_and_class_name(
             random_function) == "random_function"
示例#2
0
 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
示例#3
0
    def wrapper_use_tracer(*args, **kwargs):
        # type: (Any, Any) -> Any
        merge_span = kwargs.pop('merge_span', False)
        passed_in_parent = kwargs.pop("parent_span", None)

        span_impl_type = settings.tracing_implementation()
        if span_impl_type is None:
            return func(*args, **kwargs)  # type: ignore

        # Merge span is parameter is set, but only if no explicit parent are passed
        if merge_span and not passed_in_parent:
            return func(*args, **kwargs)  # type: ignore

        with common.change_context(passed_in_parent):
            name = name_of_span or common.get_function_and_class_name(
                func, *args)  # type: ignore
            with span_impl_type(name=name):
                return func(*args, **kwargs)  # type: ignore
示例#4
0
def test_get_function_and_class_name(http_request):
    client = MockClient(http_request)
    assert common.get_function_and_class_name(client.get_foo,
                                              client) == "MockClient.get_foo"
    assert common.get_function_and_class_name(
        random_function) == "random_function"