How to use aiozipkin - 10 common examples

To help you get started, we’ve selected a few aiozipkin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiozipkin / tests / test_jaeger.py View on Github external
async def test_basic(jaeger_url, jaeger_api_url, client, loop):
    endpoint = az.create_endpoint('simple_service', ipv4='127.0.0.1', port=80)
    interval = 50
    tracer = await az.create(jaeger_url, endpoint, sample_rate=1.0,
                             send_interval=interval, loop=loop)

    with tracer.new_trace(sampled=True) as span:
        span.name('jaeger_span')
        span.tag('span_type', 'root')
        span.kind(az.CLIENT)
        span.annotate('SELECT * FROM')
        await asyncio.sleep(0.1)
        span.annotate('start end sql')

    # close forced sending data to server regardless of send interval
    await tracer.close()
    trace_id = span.context.trace_id[-16:]
    url = URL(jaeger_api_url) / 'api' / 'traces' / trace_id
github aio-libs / aiozipkin / tests / test_zipkin.py View on Github external
async def test_basic(zipkin_url, client, loop):
    endpoint = az.create_endpoint('simple_service', ipv4='127.0.0.1', port=80)
    interval = 50
    tracer = await az.create(zipkin_url, endpoint, sample_rate=1.0,
                             send_interval=interval, loop=loop)

    with tracer.new_trace(sampled=True) as span:
        span.name('root_span')
        span.tag('span_type', 'root')
        span.kind(az.CLIENT)
        span.annotate('SELECT * FROM')
        await asyncio.sleep(0.1)
        span.annotate('start end sql')

    # close forced sending data to server regardless of send interval
    await tracer.close()

    trace_id = span.context.trace_id
github aio-libs / aiozipkin / tests / test_aiohttp_helpers.py View on Github external
async def test_middleware_cleanup_app(tracer):
    fut = asyncio.Future()
    fut.set_result(None)
    with patch.object(tracer, 'close', return_value=fut) as mocked_close:
        app = web.Application()
        az.setup(app, tracer)
        app.freeze()
        await app.cleanup()
        assert mocked_close.call_count == 1
github aio-libs / aiozipkin / tests / test_aiohttp_helpers.py View on Github external
async def test_middleware_with_invalid_ip(tracer, version, address):
    app = web.Application()
    az.setup(app, tracer)

    # Fake transport
    transp = Mock()
    transp.get_extra_info.return_value = (address, '0')

    async def handler(request):
        return web.Response(body=b'data')

    req = make_mocked_request('GET', '/',
                              headers={'token': 'x'},
                              transport=transp, app=app)

    middleware = middleware_maker()
    with patch('aiozipkin.span.Span.remote_endpoint') as mocked_remote_ep:
        await middleware(req, handler)
        assert mocked_remote_ep.call_count == 0
github aio-libs / aiozipkin / tests / test_aiohttp_helpers.py View on Github external
def test_basic_setup(tracer):
    app = web.Application()
    az.setup(app, tracer)

    fetched_tracer = az.get_tracer(app)
    assert len(app.middlewares) == 1
    assert tracer is fetched_tracer
github aio-libs / aiozipkin / tests / test_helpers.py View on Github external
def other_trace_context():
    context = TraceContext(
        trace_id='6f9a20b5092fa5e144fd15cc31141cd4',
        parent_id='05e3ac9a4f6e3b90',
        span_id='41baf1be2fb9bfc5',
        sampled=None,
        debug=False,
        shared=False)
    return context
github aio-libs / aiozipkin / tests / test_record.py View on Github external
def test_basic_ctr():
    context = TraceContext('string', 'string', 'string', True, True, True)
    local_endpoint = Endpoint('string', 'string', 'string', 0)
    remote_endpoint = Endpoint('string', 'string', 'string', 0)
    record = (Record(context, local_endpoint)
              .start(0)
              .name('string')
              .set_tag('additionalProp1', 'string')
              .set_tag('additionalProp2', 'string')
              .set_tag('additionalProp3', 'string')
              .kind('CLIENT')
              .annotate('string', 0)
              .remote_endpoint(remote_endpoint)
              .finish(0)
              )
    dict_record = record.asdict()
    expected = {
        'traceId': 'string',
github aio-libs / aiozipkin / tests / test_tracer.py View on Github external
def test_noop_span_methods(tracer):
    context = TraceContext(
        trace_id='6f9a20b5092fa5e144fd15cc31141cd4',
        parent_id=None,
        span_id='41baf1be2fb9bfc5',
        sampled=False,
        debug=False,
        shared=True)

    with tracer.new_child(context) as span:
        span.name('root_span')
        span.tag('span_type', 'root')
        span.kind('CLIENT')
        span.annotate('start:sql', ts=1506970524)
        span.annotate('end:sql', ts=1506970524)
        span.remote_endpoint('service_a', ipv4='127.0.0.1', port=8080)

        with span.new_child() as child_span:
github aio-libs / aiozipkin / tests / test_aiohttp_helpers.py View on Github external
req.match_info.route.resource.canonical = '/{pid}'

    middleware = middleware_maker()
    await middleware(req, handler)
    span = az.request_span(req)
    assert span
    assert len(fake_transport.records) == 1

    rec = fake_transport.records[0]
    assert rec.asdict()['tags'][az.HTTP_ROUTE] == '/{pid}'

    # noop span does not produce records
    headers = {'X-B3-Sampled': '0'}
    req_noop = make_mocked_request('GET', '/', headers=headers, app=app)
    await middleware(req_noop, handler)
    span = az.request_span(req_noop)
    assert span
    assert len(fake_transport.records) == 1
github aio-libs / aiozipkin / tests / test_aiohttp_ingegration.py View on Github external
async def handler(request):
    span = az.request_span(request)
    session = request.app['session']

    url = 'https://httpbin.org/get'
    ctx = {'span_context': span.context}
    resp = await session.get(url, trace_request_ctx=ctx)
    data = await resp.text()
    return web.Response(body=data)