def test_disabled_instrumentation(self): # it must not propagate if the module is disabled unpatch() def fn(): # an active context must be available ok_(self.tracer.context_provider.active() is not None) with self.tracer.trace('executor.thread'): return 42 with override_global_tracer(self.tracer): with self.tracer.trace('main.thread'): with concurrent.futures.ThreadPoolExecutor( max_workers=2) as executor: future = executor.submit(fn) result = future.result() # assert the right result eq_(result, 42) # we provide two different traces traces = self.tracer.writer.pop_traces() eq_(len(traces), 2) eq_(len(traces[0]), 1) eq_(len(traces[1]), 1) executor = traces[0][0] main = traces[1][0] eq_(main.name, 'main.thread') eq_(executor.name, 'executor.thread') ok_(main.parent_id is None) ok_(executor.parent_id is None)
def test_disabled_instrumentation(self): # it must not propagate if the module is disabled unpatch() def fn(): with self.tracer.trace("executor.thread"): return 42 with self.override_global_tracer(): with self.tracer.trace("main.thread"): with concurrent.futures.ThreadPoolExecutor( max_workers=2) as executor: future = executor.submit(fn) result = future.result() # assert the right result self.assertEqual(result, 42) # we provide two different traces self.assert_span_count(2) # Retrieve the root spans (no parents) # DEV: Results are sorted based on root span start time traces = self.get_root_spans() self.assertEqual(len(traces), 2) traces[0].assert_structure(dict(name="main.thread")) traces[1].assert_structure(dict(name="executor.thread"))
def test_disabled_instrumentation(self): # it must not propagate if the module is disabled unpatch() def fn(): # an active context must be available # DEV: With `ThreadLocalContext` `.active()` will never be `None` self.assertIsNotNone(self.tracer.context_provider.active()) with self.tracer.trace('executor.thread'): return 42 with self.override_global_tracer(): with self.tracer.trace('main.thread'): with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: future = executor.submit(fn) result = future.result() # assert the right result self.assertEqual(result, 42) # we provide two different traces self.assert_span_count(2) # Retrieve the root spans (no parents) # DEV: Results are sorted based on root span start time traces = self.get_root_spans() self.assertEqual(len(traces), 2) traces[0].assert_structure(dict(name='main.thread')) traces[1].assert_structure(dict(name='executor.thread'))
def test_disabled_instrumentation(self): # it must not propagate if the module is disabled unpatch() def fn(): # an active context must be available ok_(self.tracer.context_provider.active() is not None) with self.tracer.trace('executor.thread'): return 42 with override_global_tracer(self.tracer): with self.tracer.trace('main.thread'): with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: future = executor.submit(fn) result = future.result() # assert the right result eq_(result, 42) # we provide two different traces traces = self.tracer.writer.pop_traces() eq_(len(traces), 2) eq_(len(traces[0]), 1) eq_(len(traces[1]), 1) executor = traces[0][0] main = traces[1][0] eq_(main.name, 'main.thread') eq_(executor.name, 'executor.thread') ok_(main.parent_id is None) ok_(executor.parent_id is None)
def tearDown(self): # remove instrumentation unpatch() super(PropagationTestCase, self).tearDown()
def tearDown(self): # remove instrumentation unpatch()