How to use the aiozipkin.request_span 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_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)
github aio-libs / aiozipkin / tests / test_aiohttp_ingegration.py View on Github external
async def error_handler(request):
    span = az.request_span(request)
    session = request.app['session']

    url = 'http://4c2a7f53-9468-43a5-9c7d-466591eda953'
    ctx = {'span_context': span.context}
    await session.get(url, trace_request_ctx=ctx)
    return web.Response(body=b'')
github aio-libs / aiozipkin / tests / test_aiohttp_helpers.py View on Github external
async def test_middleware_with_default_transport(tracer, fake_transport):
    app = web.Application()
    az.setup(app, tracer)

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

    req = make_mocked_request('GET', '/aa', headers={'token': 'x'}, app=app)
    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 / examples / aiohttp_example.py View on Github external
async def handle(request):
    tracer = az.get_tracer(request.app)
    span = az.request_span(request)

    with tracer.new_child(span.context) as child_span:
        child_span.name('mysql:select')
        # call to external service like https://python.org
        # or database query
        await asyncio.sleep(0.01)

    text = """
    
    
        <title>aiohttp simple example</title>
    
    
        <h3>This page was traced by aiozipkin</h3>
        <p><a href="http://127.0.0.1:9001/status">Go to not traced page</a></p>
github aio-libs / aiozipkin / examples / queue / frontend.py View on Github external
async def index(request):
    span = az.request_span(request)
    tracer = az.get_tracer(request.app)
    session = request.app['session']

    with tracer.new_child(span.context) as span_producer:
        span_producer.kind(az.PRODUCER)
        span_producer.name('produce event click')
        span_producer.remote_endpoint('broker', ipv4='127.0.0.1', port=9011)

        headers = span_producer.context.make_headers()
        message = {'payload': 'click', 'headers': headers}
        resp = await session.post(backend_service, json=message)
        resp = await resp.text()
        assert resp == 'ok'

    await asyncio.sleep(0.01)
    return web.Response(text=page, content_type='text/html')