async def test_errors(loop, ): app = BaseApplication(BaseConfig()) lgr = app.logger cfg = ZipkinConfig(name='123') adapter = ZipkinAdapter(cfg) with pytest.raises(AdapterConfigurationError): adapter.handle(lgr.span_new()) with pytest.raises(AdapterConfigurationError): await adapter.stop()
def __init__(self, cfg: Config) -> None: super().__init__(cfg) self.s3 = S3(cfg.s3) self.add('s3', self.s3) self.add('srv', Server(cfg.srv, Handler())) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin))
def __init__(self, cfg: Config) -> None: super().__init__(cfg) self.add('tm', TaskManager(reg, cfg.tm)) if cfg.log_requests.enabled: self.logger.add(RequestsAdapter(cfg.log_requests)) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin))
async def test_zipkin_trace_id_size_settings( loop, use_64bit_trace_id: bool, trace_id_string_length: int ): app = BaseApplication(BaseConfig()) lgr = app.logger cfg = ZipkinConfig(name='123', use_64bit_trace_id=use_64bit_trace_id) lgr.add(ZipkinAdapter(cfg)) with lgr.span_new(name='test_span') as span: assert len(span.trace_id) == trace_id_string_length
def __init__(self, cfg: Config) -> None: super().__init__(cfg) self.add("srv", Server(cfg.rpc, RestRpcHttpHandler(api, cfg.rpc_handler))) if cfg.log_prometheus.enabled: self.logger.add(PrometheusAdapter(cfg.log_prometheus)) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin)) if cfg.log_sentry.enabled: self.logger.add(SentryAdapter(cfg.log_sentry)) if cfg.log_requests.enabled: self.logger.add(RequestsAdapter(cfg.log_requests))
def __init__(self, cfg: Config) -> None: super().__init__(cfg) if cfg.log_prometheus.enabled: self.logger.add(PrometheusAdapter(cfg.log_prometheus)) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin)) if cfg.log_sentry.enabled: self.logger.add(SentryAdapter(cfg.log_sentry)) if cfg.log_requests.enabled: self.logger.add(RequestsAdapter(cfg.log_requests)) self.add('srv', Uvicorn(cfg.asgi, fapp))
def __init__(self, cfg: Config) -> None: super().__init__(cfg) if cfg.log_prometheus.enabled: self.logger.add(PrometheusAdapter(cfg.log_prometheus)) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin)) if cfg.log_sentry.enabled: self.logger.add(SentryAdapter(cfg.log_sentry)) if cfg.log_requests.enabled: self.logger.add(RequestsAdapter(cfg.log_requests)) self.add('db', Oracle(cfg.db))
def __init__(self, cfg: Config) -> None: super().__init__(cfg) self.add( 'amqp', Pika(cfg.amqp, [lambda: ConsumerChannel(cfg.consumer)]) ) if cfg.log_prometheus.enabled: self.logger.add(PrometheusAdapter(cfg.log_prometheus)) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin)) if cfg.log_sentry.enabled: self.logger.add(SentryAdapter(cfg.log_sentry)) if cfg.log_requests.enabled: self.logger.add(RequestsAdapter(cfg.log_requests))
def __init__(self, cfg: Config) -> None: super().__init__(cfg) self.add( 'clt', RestRpcHttpClient(cfg.rpc), ) if cfg.log_prometheus.enabled: self.logger.add(PrometheusAdapter(cfg.log_prometheus)) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin)) if cfg.log_sentry.enabled: self.logger.add(SentryAdapter(cfg.log_sentry)) if cfg.log_requests.enabled: self.logger.add(RequestsAdapter(cfg.log_requests))
async def test_success(loop, ): async with ZipkinServer() as zs: cfg = ZipkinConfig(name='123', addr=zs.addr) adapter = ZipkinAdapter(cfg) app = BaseApplication(BaseConfig()) app.logger.add(adapter) lgr = app.logger await lgr.start() with lgr.span_new(name='t1', kind=Span.KIND_SERVER) as sp: sp.tag('tag', 'abc') sp.annotate('k1', 'val1', ts=123456) with pytest.raises(Exception): with sp.new_child('t2', Span.KIND_CLIENT): raise Exception() await lgr.stop() assert len(zs.spans) == 2 span: SpanModel = zs.spans[1] span2: SpanModel = zs.spans[0] assert span.name == 't1' assert span.tags == {'tag': 'abc'} assert span.annotations == [ Annotation(value='val1', timestamp=123456000000) ] assert span.duration > 0 assert span.timestamp > 0 assert not span.debug assert span.shared assert span2.name == 't2' assert span2.tags == { 'error': 'true', 'error.class': 'Exception', 'error.message': '', } assert 'raise Exception()' in span2.annotations[0].value
def __init__(self, cfg: Config) -> None: super().__init__(cfg) self.add('srv', Server(cfg.http, HttpHandler())) self.add('lock', Lock(cfg.lock)) if cfg.log_zipkin.enabled: self.logger.add(ZipkinAdapter(cfg.log_zipkin))
async def test_success( loop, ): async with ZipkinServer() as zs: cfg = ZipkinConfig(name='123', addr=zs.addr) adapter = ZipkinAdapter(cfg) app = BaseApplication(BaseConfig()) app.logger.add(adapter) lgr = app.logger await lgr.start() with lgr.span_new(name='t1', kind=Span.KIND_SERVER) as sp: sp.tag('tag', 'abc') sp.annotate('k1', 'val1', ts=123456) with pytest.raises(Exception): with sp.new_child('t2', Span.KIND_CLIENT): raise Exception() with lgr.span_new(kind=Span.KIND_SERVER) as sp3: sp3.set_name4adapter(lgr.ADAPTER_ZIPKIN, '111') sp3.annotate4adapter( lgr.ADAPTER_ZIPKIN, PgSpan.ANN_RESULT, json_encode({'result': '123'}), ts=122211000000, ) sp3.set_tag4adapter( lgr.ADAPTER_ZIPKIN, PgSpan.TAG_QUERY_NAME, 'get_paym', ) await lgr.stop() assert len(zs.spans) == 3 span: SpanModel = zs.spans[1] span2: SpanModel = zs.spans[0] span3: SpanModel = zs.spans[2] assert span.name == 't1' assert span.tags == {'tag': 'abc'} assert span.annotations == [ Annotation(value='val1', timestamp=123456000000) ] assert span.duration > 0 assert span.timestamp > 0 assert not span.debug assert span.shared assert span2.name == 't2' assert span2.tags == { 'error': 'true', 'error.class': 'Exception', 'error.message': '', } assert 'raise Exception()' in span2.annotations[0].value assert span3.name == '111' assert span3.tags == {PgSpan.TAG_QUERY_NAME: 'get_paym'} assert span3.annotations == [ Annotation(value='{"result": "123"}', timestamp=122211000000000000) ]