Need help with aiozipkin?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

170 Stars 28 Forks Apache License 2.0 566 Commits 9 Opened issues


Distributed tracing instrumentation for asyncio with zipkin

Services available


Need anything else?

Contributors list


.. image:: :target: .. image:: :target: .. image:: :target: :alt: Maintainability .. image:: :target: .. image:: :target: :alt: Documentation Status .. image:: :target: :alt: Chat on Gitter

aiozipkin is Python 3.6+ module that adds distributed tracing capabilities from asyncio_ applications with zipkin ( server instrumentation.

zipkin_ is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in microservice architectures. It manages both the collection and lookup of this data. Zipkin’s design is based on the Google Dapper paper.

Applications are instrumented with aiozipkin report timing data to zipkin_. The Zipkin UI also presents a Dependency diagram showing how many traced requests went through each application. If you are troubleshooting latency problems or errors, you can filter or sort all traces based on the application, length of trace, annotation, or timestamp.

.. image:: :alt: zipkin ui animation


  • Distributed tracing capabilities to asyncio applications.
  • Support zipkin_
  • Easy to use API.
  • Explicit context handling, no thread local variables.
  • Can work with jaeger_ and stackdriver_ through zipkin compatible API.

zipkin vocabulary

Before code lets learn important zipkin_ vocabulary, for more detailed information please visit

.. image:: :alt: zipkin ui glossary

  • Span represents one specific method (RPC) call
  • Annotation string data associated with a particular timestamp in span
  • Tag - key and value associated with given span
  • Trace - collection of spans, related to serving particular request

Simple example

.. code:: python

import asyncio
import aiozipkin as az

async def run(): # setup zipkin client zipkin_address = '' endpoint = az.create_endpoint( "simple_service", ipv4="", port=8080) tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0)

# create and setup new trace
with tracer.new_trace(sampled=True) as span:
    # give a name for the span"Slow SQL")
    # tag with relevant information
    span.tag("span_type", "root")
    # indicate that this is client span
    # 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")

await tracer.close()

if name == "main": loop = asyncio.get_event_loop() loop.run_until_complete(run())

aiohttp example

aiozipkin includes aiohttp server instrumentation, for this create

as usual and install aiozipkin plugin:

.. code:: python

import aiozipkin as az

def init_app(): host, port = "", 8080 app = web.Application() endpoint = az.create_endpoint("AIOHTTP_SERVER", ipv4=host, port=port) tracer = await az.create(zipkin_address, endpoint, sample_rate=1.0) az.setup(app, tracer)

That is it, plugin adds middleware that tries to fetch context from headers, and create/join new trace. Optionally on client side you can add propagation headers in order to force tracing and to see network latency between client and server.

.. code:: python

import aiozipkin as az

endpoint = az.create_endpoint("AIOHTTP_CLIENT") tracer = await az.create(zipkin_address, endpoint)

with tracer.new_trace() as span: span.kind(az.CLIENT) headers = span.context.make_headers() host = "{}".format(i) resp = await session.get(host, headers=headers) await resp.text()



Installation process is simple, just::

$ pip install aiozipkin

Support of other collectors

aiozipkin can work with any other zipkin_ compatible service, currently we tested it with jaeger_ and stackdriver_.

Jaeger support

jaeger_ supports zipkin_ span format as result it is possible to use aiozipkin with jaeger_ server. You just need to specify jaeger server address and it should work out of the box. Not need to run local zipkin server. For more informations see tests and jaeger_ documentation.

.. image:: :alt: jaeger ui animation

Stackdriver support

Google stackdriver_ supports zipkin_ span format as result it is possible to use aiozipkin with this google_ service. In order to make this work you need to setup zipkin service locally, that will send trace to the cloud. See google_ cloud documentation how to setup make zipkin collector:

.. image:: :alt: jaeger ui animation


  • Python_ 3.6+
  • aiohttp_

.. _PEP492: .. _Python: .. _aiohttp: .. _asyncio: .. _uvloop: .. _zipkin: .. _jaeger: .. _stackdriver: .. _google:

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.