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
async def handler(request): message = await request.json() tracer = az.get_tracer(request.app) for _ in range(5): asyncio.ensure_future( aiojobs.aiohttp.spawn(request, consume_message(message, tracer))) return web.Response(text='ok')
async def handler(request): message = await request.json() tracer = az.get_tracer(request.app) for _ in range(5): asyncio.ensure_future( aiojobs.aiohttp.spawn(request, consume_message(message, tracer)) ) return web.Response(text='ok')
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') await asyncio.sleep(0.01) text = 'Hello' return web.Response(text=text)
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 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 city(request): """Returns the information about the city >>>curl -H "Content-Type: application/json" 'http://localhost:8080/city/sydney' | jq [ { "geonameid": 6160752, "name": "Sydney", "latitude": 46.15014, "longitude": -60.18175, "country_code": "CA", "admin1": "07", "admin2": "", "geom": "0101000020E61000002506819543174EC025E99AC937134740" }, { "geonameid": 6354908, "name": "Sydney", "latitude": 46.1351, "longitude": -60.1831, "country_code": "CA", "admin1": "07", "admin2": "Cape Breton County (undefined)", "geom": "0101000020E6100000E5F21FD26F174EC045D8F0F44A114740" }, ... """ tracer = az.get_tracer(request.app) span = az.request_span(request) with tracer.new_child(span.context) as child_span: child_span.name('postgres:select:get_city') # call to external service like https://python.org # or database query city_name = request.match_info['city_name'] try: results = await db.get_city(request.app['db'], city_name.title()) except db.RecordNotFound as e: raise web.HTTPNotFound(text=str(e)) return web.json_response([dict(ob) for ob in results])
async def handler(request): span = az.request_span(request) tracer = az.get_tracer(request.app) await asyncio.sleep(0.01) session = request.app['session'] with tracer.new_child(span.context) as span_b: headers = span_b.context.make_headers() resp = await session.get(service_b_api, headers=headers) data_b = await resp.text() with tracer.new_child(span.context) as span_e: headers = span_e.context.make_headers() resp = await session.get(service_e_api, headers=headers) data_e = await resp.text() body = 'service_a ' + data_b + ' ' + data_e return web.Response(text=body)
async def neighbors(request): """Return the k nearest neighbors. >>> curl 'http://localhost:8080/neighbors?longitude=-73.98569&latitude=40.74844&number=10' "[{\"id\": 5142464, \"name\": \"WBAI-FM (New York)\", \"geom\": \"0101000020E6100000A27F828B157F52C05682C5E1CC5F4440\", \"latitude\": -73.98569, \"longitude\": 40.74844, \"country_code\": \"US\", \"admin1\": \"NY\", \"admin2\": \"061\"}, {\"id\": 5142503, \"name\": \"WCBS-FM (New York)\", \"geom\": \"0101000020E6100000A27F828B157F52C05682C5E1CC5F4440\", \"latitude\": -73.98569, \"longitude\": 40.74844, \"country_code\": \"US\", \"admin1\": \"NY\", \"admin2\": \"061\"}, {\"id\": 5142481, \"name\": \"WBLS-FM (New York)\", \"geom\": \"0101000020E6100000A27F828B157F52C05682C5E1CC5F4440\", \"latitude\": -73.98569, \"longitude\": 40.74844, \"country_code\": \"US\", \"admin1\": \"NY\", \"admin2\": \"061\"}, ...] """ tracer = az.get_tracer(request.app) span = az.request_span(request) with tracer.new_child(span.context) as child_span: child_span.name('postgres:select:get_neighbors') longitude = float(request.query["longitude"]) latitude = float(request.query["latitude"]) number = int(request.query["number"]) results = await db.get_neighbors(request.app['db'], longitude, latitude, number) return web.json_response([dict(ob) for ob in results])
async def handle(request: web.Request) -> web.StreamResponse: 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 aiozipkin</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")
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 aiozipkin</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')