How to use the aiozipkin.CLIENT function in aiozipkin

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_zipkin.py View on Github external
async def test_zipkin_error(client, loop, caplog):
    endpoint = az.create_endpoint('error_service', ipv4='127.0.0.1', port=80)
    interval = 50
    zipkin_url = 'https://httpbin.org/status/404'
    async with az.create(zipkin_url, endpoint, sample_rate=1.0,
                         send_interval=interval, loop=loop) as tracer:
        with tracer.new_trace(sampled=True) as span:
            span.kind(az.CLIENT)
            await asyncio.sleep(0.0)

    assert len(caplog.records) == 1
    msg = 'zipkin responded with code: '
    assert msg in str(caplog.records[0].exc_info)

    t = ('aiozipkin', logging.ERROR, 'Can not send spans to zipkin')
    assert caplog.record_tuples == [t]
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
    url = URL(zipkin_url).with_path('/zipkin/api/v2/traces')
    data = await _retry_zipkin_client(url, client)
    assert any(s['traceId'] == trace_id for trace in data for s in trace), data
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
    resp = await client.get(url, headers={'Content-Type': 'application/json'})
    assert resp.status == 200
    data = await resp.json()
    assert data['data'][0]['traceID'] in trace_id
github aio-libs / aiozipkin / examples / simple.py View on Github external
async def run():
    # setup zipkin client
    zipkin_address = 'http://127.0.0.1:9411/api/v2/spans'
    endpoint = az.create_endpoint(
        'simple_service', ipv4='127.0.0.1', port=8080
    )

    # creates tracer object that traces all calls, if you want sample
    # only 50% just set sample_rate=0.5
    tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)

    # create and setup new trace
    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')
        # imitate long SQL query
        await asyncio.sleep(0.1)
        span.annotate('start end sql')

        # create child span
        with tracer.new_child(span.context) as nested_span:
            nested_span.name('nested_span_1')
            nested_span.kind(az.CLIENT)
            nested_span.tag('span_type', 'inner1')
            nested_span.remote_endpoint('remote_service_1')
            await asyncio.sleep(0.01)

        # create other child span
        with tracer.new_child(span.context) as nested_span:
            nested_span.name('nested_span_2')
github aio-libs / aiozipkin / examples / simple.py View on Github external
tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)

    # create and setup new trace
    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')
        # imitate long SQL query
        await asyncio.sleep(0.1)
        span.annotate('start end sql')

        # create child span
        with tracer.new_child(span.context) as nested_span:
            nested_span.name('nested_span_1')
            nested_span.kind(az.CLIENT)
            nested_span.tag('span_type', 'inner1')
            nested_span.remote_endpoint('remote_service_1')
            await asyncio.sleep(0.01)

        # create other child span
        with tracer.new_child(span.context) as nested_span:
            nested_span.name('nested_span_2')
            nested_span.kind(az.CLIENT)
            nested_span.remote_endpoint('remote_service_2')
            nested_span.tag('span_type', 'inner2')
            await asyncio.sleep(0.01)

    await tracer.close()
    print('-' * 100)
    print('Check zipkin UI for produced traces: http://localhost:9411/zipkin')