Nikolay Novik
KyivPy 22
aiomysql, aioobc
aiomonitor, aiohttp-debugtoolbar, aiobotocore,
aiohttp-mako, aiohttp-admin, aiorwlock, aiozipkin
Distributed Tracing - is a tool that helps gather timing data needed to troubleshoot latency problems in service oriented architectures. Provides an end-to-end view of requests as they travel through your application, and shows a map of your application’s underlying components.
{'X-B3-TraceId': '6f9a20b5092fa5e144fd15cc31141cd4'
'X-B3-ParentSpanId': None,
'X-B3-SpanId': '41baf1be2fb9bfc5',
'X-B3-Sampled': '1',}
Name | github | stars |
---|---|---|
py_zipkin | github.com/Yelp/py_zipkin | 61 ★ |
pyramid_zipkin | github.com/Yelp/pyramid_zipkin | 23 ★ |
flask-zipkin | github.com/qiajigou/flask-zipkin | 14 ★ |
django-zipkin | github.com/prezi/django-zipkin | 19 ★ |
aiozipkin | github.com/aio-libs/aiozipkin | 10 ★ |
import aiozipkin as az
async def run():
zipkin_address = "http://127.0.0.1:9411"
endpoint = az.create_endpoint("simple_service", ipv4="127.0.0.1", port=8080)
tracer = az.create(zipkin_address, endpoint)
# create and setup new trace
with tracer.new_trace(sampled=True) as span:
# give a name for the span
span.name("Slow SQL")
# tag with relevant information
span.tag("span_type", "root")
# indicate that this is client span
span.kind(az.CLIENT)
# make timestamp and name it with START SQL query
span.annotate("START SQL SELECT * FROM")
# imitate long SQL query
await asyncio.sleep(0.1)
# make other timestamp and name it "END SQL"
span.annotate("END SQL")
It is possible to attach bunch of metadata for each span.
with tracer.new_trace(sampled=True) as span:
span.name("Slow SQL")
span.annotate("START SQL SELECT * FROM")
await asyncio.sleep(0.1)
span.annotate("END SQL")
await asyncio.sleep(0.1)
Span duration can be annotated manually
# create and setup new trace
with tracer.new_trace(sampled=True) as span:
span.name('root_span')
await asyncio.sleep(0.1)
# create child span
with tracer.new_child(span.context) as nested_span:
nested_span.name('nested_span_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')
await asyncio.sleep(0.01)
Spans can be nested, just pass contest from parent
with tracer.new_trace(sampled=True) as span:
span.kind(az.CLIENT)
headers = span.context.make_headers()
resp = await session.get(host, headers=headers)
await resp.text()
Server side will work automatically if aiozipkin installed as
plugin
def make_app(host, port, loop):
app = web.Application()
endpoint = az.create_endpoint(
'aiohttp_server', ipv4=host, port=port)
tracer = az.create(zipkin_address, endpoint, sample_rate=1.0)
az.setup(app, tracer)
Middleware attaches server span to client span.
aio-libs: https://github.com/aio-libs