def __init__(self, environ=None, tracer_to_use=None):
     if environ is None:
         environ = {}
     self.orig_tracer = OpenCensusSpan.get_current_tracer()
     self.orig_current_span = OpenCensusSpan.get_current_span()
     self.os_env = mock.patch.dict(os.environ, environ)
     self.tracer_to_use = tracer_to_use
Exemplo n.º 2
0
 def test_span_with_opencensus_complicated(self, value):
     with ContextHelper(tracer_to_use=value) as ctx:
         exporter = MockExporter()
         trace = tracer_module.Tracer(sampler=AlwaysOnSampler(), exporter=exporter)
         with trace.start_span(name="OverAll") as parent:
             client = MockClient()
             client.make_request(2)
             with trace.span("child") as child:
                 time.sleep(0.001)
                 client.make_request(2, parent_span=parent)
                 assert OpenCensusSpan.get_current_span() == child
                 client.make_request(2)
         trace.finish()
         exporter.build_tree()
         parent = exporter.root
         assert len(parent.children) == 4
         assert parent.children[0].span_data.name == "MockClient.__init__"
         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 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
 def __init__(self, environ={}, tracer_to_use=None, should_only_propagate=None):
     self.orig_tracer = OpenCensusSpan.get_current_tracer()
     self.orig_current_span = OpenCensusSpan.get_current_span()
     self.orig_sdk_context_span = tracing_context.current_span.get()
     self.os_env = mock.patch.dict(os.environ, environ)
     self.tracer_to_use = tracer_to_use
     self.should_only_propagate = should_only_propagate
 def __enter__(self):
     self.orig_tracer = OpenCensusSpan.get_current_tracer()
     self.orig_current_span = OpenCensusSpan.get_current_span()
     execution_context.clear()
     if self.tracer_to_use is not None:
         settings.tracing_implementation.set_value(self.tracer_to_use)
     self.os_env.start()
     execution_context.clear()
     return self
Exemplo n.º 5
0
 def __enter__(self):
     self.orig_tracer = OpenCensusSpan.get_current_tracer()
     self.orig_current_span = OpenCensusSpan.get_current_span()
     self.orig_sdk_context_span = tracing_context.current_span.get()
     if self.tracer_to_use is not None:
         settings.tracing_implementation.set_value(self.tracer_to_use)
     if self.should_only_propagate is not None:
         settings.tracing_should_only_propagate.set_value(
             self.should_only_propagate)
     self.os_env.start()
     return self
Exemplo n.º 6
0
 def test_should_only_propagate(self):
     with ContextHelper(should_only_propagate=True):
         exporter = MockExporter()
         trace = tracer_module.Tracer(sampler=AlwaysOnSampler(),
                                      exporter=exporter)
         with trace.start_span(name="OverAll") as parent:
             client = MockClient()
             client.make_request(2)
             with trace.span("child") as child:
                 client.make_request(2, parent_span=parent)
                 assert OpenCensusSpan.get_current_span() == child
                 client.make_request(2)
         trace.finish()
         exporter.build_tree()
         parent = exporter.root
         assert len(parent.children) == 1
         assert parent.children[0].span_data.name == "child"
         assert not parent.children[0].children
 def get_span_from_thread(output):
     current_span = OpenCensusSpan.get_current_span()
     output.append(current_span)