Esempio n. 1
0
async def test_middleware_with_default_transport(zipkin_tracer: Tracer):
    app = web.Application()
    az.setup(app, zipkin_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(zipkin_tracer.transport.records) == 1

    rec = zipkin_tracer.transport.records[0]
    assert rec.asdict()["tags"][az.HTTP_ROUTE] == "/{pid}"

    # noop span does not produce records
    headers = {"b3": "1-2-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(zipkin_tracer.transport.records) == 1
Esempio n. 2
0
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"")
Esempio n. 3
0
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)
Esempio n. 4
0
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")
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 = """
    <html lang="en">
    <head>
        <title>aiohttp simple example</title>
    </head>
    <body>
        <h3>This page was traced by aiojaeger</h3>
        <p><a href="http://127.0.0.1:9001/status">Go to not traced page</a></p>
    </body>
    </html>
    """
    return web.Response(text=text, content_type="text/html")