API

Core API Reference

aiozipkin.CLIENT

Constant indicates that span has been created on client side.

aiozipkin.SERVER

Constant indicates that span has been created on server side.

aiozipkin.PRODUCER

Constant indicates that span has been created by messsage producer.

aiozipkin.CONSUMER

Constant indicates that span has been created by messsage consumer.

aiozipkin.make_context(headers: Dict[str, str])

Creates tracing context object from from headers mapping if possible, otherwise returns None.

Parameters:

headers (dict) – hostname to serve monitor telnet server

Returns:

TraceContext object or None

coroutine aiozipkin.create(zipkin_address, local_endpoint, sample_rate, send_interval, loop, ignored_exceptions)

Creates Tracer object

Parameters:
  • zipkin_address (Endpoint) – information related to service address and name, where current zipkin tracer is installed

  • local_endpoint (Endpoint) – hostname to serve monitor telnet server

  • sample_rate (float) – hostname to serve monitor telnet server

  • send_inteval (float) – hostname to serve monitor telnet server

  • loop (asyncio.EventLoop) – hostname to serve monitor telnet server

  • Optional[List[Type[Exception]]] – ignored_exceptions list of exceptions which will not be labeled as error

Returns:

Tracer

coroutine aiozipkin.create_custom(transport, sampler, local_endpoint, ignored_exceptions)

Creates Tracer object with a custom Transport and Sampler implementation.

Parameters:
  • transport (TransportABC) – custom transport implementation

  • sampler (SamplerABC) – custom sampler implementation

  • local_endpoint (Endpoint) – hostname to serve monitor telnet server

  • Optional[List[Type[Exception]]] – ignored_exceptions list of exceptions which will not be labeled as error

Returns:

Tracer

class aiozipkin.Endpoint(serviceName: str, ipv4=None, ipv6=None, port=None)

This this simple data only class, just holder for service related information:

serviceName
ipv4
ipv6
port
class aiozipkin.TraceContext(trace_id, parent_id, span_id, sampled, debug, shared)

Immutable class with trace related data that travels across process boundaries.:

Parameters:
  • trace_id (str) – hostname to serve monitor telnet server

  • parent_id (Optional[str]) – hostname to serve monitor telnet server

  • span_id (str) – hostname to serve monitor telnet server

  • sampled (str) – hostname to serve monitor telnet server

  • debug (str) – hostname to serve monitor telnet server

  • shared (float) – hostname to serve monitor telnet server

make_headers()
Rtype dict:

hostname to serve monitor telnet server

class aiozipkin.Sampler(trace_id, parent_id, span_id, sampled, debug, shared)

TODO: add

Parameters:
  • sample_rate (float) – XXX

  • seed (Optional[int]) – seed value for random number generator

is_sampled(trace_id)

XXX

Rtype bool:

hostname to serve monitor telnet server

Aiohttp integration API

API for integration with aiohttp.web, just calling setup is enough for zipkin to start tracking requests. On high level attached plugin registers middleware that starts span on beginning of request and closes it on finish, saving important metadata, like route, status code etc.

aiozipkin.APP_AIOZIPKIN_KEY

Key, for aiohttp application, where aiozipkin related data is saved. In case for some reason you want to use 2 aiozipkin instances or change default name, this parameter should not be used.

aiozipkin.REQUEST_AIOZIPKIN_KEY

Key, for aiohttp request, where aiozipkin span related to current request is located.

aiozipkin.setup(app, tracer, tracer_key=APP_AIOZIPKIN_KEY, request_key=APP_AIOZIPKIN_KEY)

Sets required parameters in aiohttp applications for aiozipkin.

Tracer added into application context and cleaned after application shutdown. You can provide custom tracer_key, if default name is not suitable.

Parameters:
  • app (aiottp.web.Application) – application for tracer to attach

  • tracer (Tracer) – aiozipkin tracer

  • skip_routes (List) – list of routes not to be traced

  • tracer_key (str) – key for aiozipkin state in aiohttp Application

  • request_key (str) – key for Span in request object

Returns:

aiottp.web.Application

aiozipkin.get_tracer(app, tracer_key=APP_AIOZIPKIN_KEY)

Sets required parameters in aiohttp applications for aiozipkin.

By default tracer has APP_AIOZIPKIN_KEY in aiohttp application context, you can provide own key, if for some reason default one is not suitable.

Parameters:
  • app (aiottp.web.Application) – application for tracer to attach

  • tracer_key (str) – key where tracerd stored in app

aiozipkin.request_span(request, request_key=REQUEST_AIOZIPKIN_KEY)

Return span created by middleware from request context, you can use it as parent on next child span.

Parameters:
  • app (aiottp.web.Request) – application for tracer to attach

  • request_key (str) – key where stpan stored in request

aiozipkin.make_trace_config(tracer)

Creates configuration compatible with aiohttp client. It attaches to reslevant hooks and annotates timing.

Parameters:

tracer (Tracer) – to install in aiohttp tracer config

Returns:

aiohttp.TraceConfig