Package: aiozipkin
aiozipkinaiozipkinis Python 3.6+ module that adds distributed tracing capabilities
fromasyncioapplications with zipkin (http://zipkin.io) server instrumentation.zipkinis 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 withaiozipkinreport timing data tozipkin.
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.FeaturesDistributed tracing capabilities toasyncioapplications.Supportzipkinv2protocol.Easy to use API.Explicit context handling, no thread local variables.Can work withjaegerandstackdriverthrough zipkin compatible API.zipkin vocabularyBefore code lets learn importantzipkinvocabulary, for more detailed
information please visithttps://zipkin.io/pages/instrumentingSpanrepresents one specific method (RPC) callAnnotationstring data associated with a particular timestamp in spanTag- key and value associated with given spanTrace- collection of spans, related to serving particular requestSimple exampleimportasyncioimportaiozipkinasazasyncdefrun():# setup zipkin clientzipkin_address='http://127.0.0.1:9411/api/v2/spans'endpoint=az.create_endpoint("simple_service",ipv4="127.0.0.1",port=8080)tracer=awaitaz.create(zipkin_address,endpoint,sample_rate=1.0)# create and setup new tracewithtracer.new_trace(sampled=True)asspan:# give a name for the spanspan.name("Slow SQL")# tag with relevant informationspan.tag("span_type","root")# indicate that this is client spanspan.kind(az.CLIENT)# make timestamp and name it with START SQL queryspan.annotate("START SQL SELECT * FROM")# imitate long SQL queryawaitasyncio.sleep(0.1)# make other timestamp and name it "END SQL"span.annotate("END SQL")awaittracer.close()if__name__=="__main__":loop=asyncio.get_event_loop()loop.run_until_complete(run())aiohttp exampleaiozipkinincludesaiohttpserver instrumentation, for this createweb.Application()as usual and install aiozipkin plugin:importaiozipkinasazdefinit_app():host,port="127.0.0.1",8080app=web.Application()endpoint=az.create_endpoint("AIOHTTP_SERVER",ipv4=host,port=port)tracer=awaitaz.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.importaiozipkinasazendpoint=az.create_endpoint("AIOHTTP_CLIENT")tracer=awaitaz.create(zipkin_address,endpoint)withtracer.new_trace()asspan:span.kind(az.CLIENT)headers=span.context.make_headers()host="http://127.0.0.1:8080/api/v1/posts/{}".format(i)resp=awaitsession.get(host,headers=headers)awaitresp.text()Documentationhttp://aiozipkin.readthedocs.io/InstallationInstallation process is simple, just:$ pip install aiozipkinSupport of other collectorsaiozipkincan work with any otherzipkincompatible service, currently we
tested it withjaegerandstackdriver.Jaeger supportjaegersupportszipkinspan format as result it is possible to useaiozipkinwithjaegerserver. You just need to specifyjaegerserver address and it
should work out of the box. Not need to run local zipkin server.
For more informations see tests andjaegerdocumentation.Stackdriver supportGooglestackdriversupportszipkinspan format as result it is possible to
useaiozipkinwith thisgoogleservice. In order to make this work you
need to setup zipkin service locally, that will send trace to the cloud. Seegooglecloud documentation how to setup make zipkin collector:RequirementsPython3.6+aiohttpCHANGES1.1.1 (2021-10-23)BugfixesFix unhandled AssertionError in aiohttp integration when unknown resource requested by the user.#400FixNoneTypeerror when usingSystemRoute.#4101.1.0 (2021-05-17)BugfixesExpect trace request context to be of SimpleNamespace type.#3851.0.0 (2020-11-06)BugfixesSupport Python 3.8 and Python 3.9#2590.7.1 (2020-09-20)BugfixesFixManifest.infile; addCHANGES.rstto the Source Tarball.0.7.0 (2020-07-17)FeaturesAdd support of AWS X-Ray trace id format.#2730.6.0 (2019-10-12)Add context var support for python3.7 aiohttp instrumentation #187Single header tracing support #189Add retries and batches to transport (thanks @konstantin-stepanov)Drop python3.5 support #238Use new typing syntax in codebase #2370.5.0 (2018-12-25)More strict typing configuration is used #147Fixed bunch of typos in code and docs #151 #153 (thanks @deejay1)Added interface for Transport #155 (thanks @deejay1)Added create_custom helper for easer tracer configuration #160 (thanks @deejay1)Added interface for Sampler #160 (thanks @deejay1)Added py.typed marker0.4.0 (2018-07-11)Add more coverage with typing #147Breaking change: typo send_inteval => send_interval #144 (thanks @gugu)Breaking change: do not append api/v2/spans to the zipkin dress #1500.3.0 (2018-06-13)Add support http.route tag for aiohttp #138Make zipkin address builder more permissive #141 (thanks @dsantosfff)0.2.0 (2018-03-03)Breaking change: az.create is coroutine now #114Added context manger for tracer object #114Added more mypy types #1170.1.1 (2018-01-26)Added new_child helper method #830.1.0 (2018-01-21)After few months of work and beta releases here are basic features:Initial release.Implemented zipkin v2 protocol with HTTP transportAdded jaeger supportAdded stackdriver supportAdded aiohttp server supportAdded aiohttp 3.0.0 client tracing supportAdded examples and demos