async def setUp(self): self.recorder = InMemoryRecorder() self.dict_discovery = SimpleDictDiscovery({}) self.discovery = AIOCompositeDiscovery(self.get_local_discovery(), self.dict_discovery) self.discovery.tracer = BasicTracer(self.recorder) self.svc = DummyService() await self.ensure_future(self.svc.on_start())
def tracer(asyncio_scope_manager): t = BasicTracer( recorder=InMemoryRecorder(), scope_manager=asyncio_scope_manager, ) t.register_required_propagators() return t
def test_span_log_kv(): recorder = InMemoryRecorder() tracer = BasicTracer(recorder=recorder) span = tracer.start_span('x') span.log_kv({ 'foo': 'bar', 'baz': 42, }) span.finish() finished_spans = recorder.get_spans() assert len(finished_spans) == 1 assert len(finished_spans[0].logs) == 1 assert len(finished_spans[0].logs[0].key_values) == 2 assert finished_spans[0].logs[0].key_values['foo'] == 'bar' assert finished_spans[0].logs[0].key_values['baz'] == 42
def test_span_sampling_priority(): recorder = InMemoryRecorder() tracer = BasicTracer(recorder=recorder) span = tracer.start_span('x') assert span.context.sampled is True span.set_tag(tags.SAMPLING_PRIORITY, 0) assert span.context.sampled is False span.finish() assert len(recorder.get_spans()) == 1 def get_sampled_spans(): return [span for span in recorder.get_spans() if span.context.sampled] assert len(get_sampled_spans()) == 0
def tracer(): t = BasicTracer(recorder=InMemoryRecorder()) old_tracer = opentracing.tracer opentracing.tracer = t try: yield t except: opentracing.tracer = old_tracer
def tracer(): dummy_tracer = BasicTracer(recorder=InMemoryRecorder()) dummy_tracer.register_required_propagators() old_tracer = opentracing.tracer opentracing.tracer = dummy_tracer try: yield dummy_tracer finally: opentracing.tracer = old_tracer
def tracer(): t = BasicTracer(recorder=InMemoryRecorder()) t.register_required_propagators() old_tracer = opentracing.tracer opentracing.tracer = t try: yield t except: opentracing.tracer = old_tracer
def _get_tracers(scope_manager=None): from basictracer.recorder import InMemoryRecorder from basictracer.tracer import BasicTracer dummy_tracer = BasicTracer(recorder=InMemoryRecorder(), scope_manager=scope_manager) dummy_tracer.register_required_propagators() old_tracer = opentracing.tracer opentracing.tracer = dummy_tracer return old_tracer, dummy_tracer
def __init__(self, *args, **kwargs): super(FanTest, self).__init__(*args, **kwargs) self.recorder = InMemoryRecorder() discovery = LocalDiscovery() discovery.tracer = BasicTracer(self.recorder) for service in [DummyService, NestedService]: s = service() discovery.register(LocalEndpoint(s)) self.context = Context(discovery)
def tracer(): old_tracer = opentracing.tracer t = BasicTracer( recorder=InMemoryRecorder(), scope_manager=TornadoScopeManager(), ) t.register_required_propagators() opentracing.tracer = t try: yield t finally: opentracing.tracer = old_tracer
def tracer(): t = BasicTracer(recorder=InMemoryRecorder()) t.register_required_propagators() return t
def setUp(self): # initialize an in-memory tracer self.recorder = InMemoryRecorder() self.tracer = BasicTracer(recorder=self.recorder)
class AIOEndpointCase(AIOTestCase): endpoint_class = AIODummyEndpoint transport_class = AIODummyTransport endpoint_params = {'id': 'test', 'transport': 'aiotest'} def __init__(self, *args): super().__init__(*args) self.log = logging.getLogger(self.__class__.__name__) def get_local_discovery(self): ld = TestLocalDiscovery() TestLocalDiscovery.transports = { self.endpoint_params['transport']: self.transport_class } if not hasattr(self, 'ctx_local'): self.ctx_local = [] self.ctx_local.append(ld) return ld async def setUp(self): self.recorder = InMemoryRecorder() self.dict_discovery = SimpleDictDiscovery({}) self.discovery = AIOCompositeDiscovery(self.get_local_discovery(), self.dict_discovery) self.discovery.tracer = BasicTracer(self.recorder) self.svc = DummyService() await self.ensure_future(self.svc.on_start()) async def _test_remote_register(self): ep = self.endpoint_class(self.discovery, self.svc, self.endpoint_params) await asyncio.wait_for(ep.on_start(), TEST_TIMEOUT) self.discovery.register(ep) l = self.discovery.local r = self.discovery.remote assert l.cached_endpoints[('dummy', )] == ep assert r.data['dummy'] == self.endpoint_params @property def ctx(self): ld = TestLocalDiscovery() self.ctx_local.append(ld) discovery = AIOCompositeDiscovery(self.get_local_discovery(), self.dict_discovery) discovery.tracer = BasicTracer(self.recorder) return Context(discovery, self.svc) async def _test_remote_call(self): params = self.endpoint_params ep = self.endpoint_class(self.discovery, self.svc, params) await asyncio.wait_for(ep.on_start(), TEST_TIMEOUT) self.discovery.register(ep) with self.ctx as ctx: res = await asyncio.wait_for(ctx.rpc.dummy.ping(), TEST_TIMEOUT) self.assertEqual(res, 'pong') self.assertEquals(len(self.recorder.get_spans()), 2) spans = [(x.context.span_id, x.context.trace_id) for x in self.recorder.get_spans()] self.log.debug('SPANS: {}'.format(spans)) async def tearDown(self): for ld in self.ctx_local: for v in ld.cached_endpoints.values(): await v.on_stop()