示例#1
0
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()
示例#2
0
文件: s3.py 项目: scorp249/ipapp
 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))
示例#3
0
 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))
示例#4
0
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
示例#5
0
 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))
示例#6
0
文件: fastapi.py 项目: draihal/ipapp
    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))
示例#7
0
    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))
示例#8
0
 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))
示例#9
0
 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))
示例#10
0
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
示例#11
0
 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))
示例#12
0
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)
    ]