Skip to main content

Version ReadTheDocs CI Coverage CodeClimate

Helper classes for observing your Tornado-based HTTP code.

Source Code

https://github.com/dave-shawley/divak-tornado

Download

https://pypi.org/project/divak-tornado

Documentation

https://divak-tornado.readthedocs.io

Issue Tracker

https://github.com/dave-shawley/divak-tornado

Divák implements patterns for observing inter-service communication in distributed systems from both a client and a server perspective. The primary goal is to provide a nice framework for all aspects of observability:

  • measuring time spent during execution

  • counting interesting events

  • propagating tokens across inter-service communication that allow for tracing of messages

  • injecting tracing tokens into log messages

In the past I have approached the problem of observing data flows from the perspective of the individual aspects of logging, metrics recording, and error reporting. Divák takes a different approach. It provides the tools to include measurements in your code and the ability to propagate tokens that correlate all parts of a data flow across multiple services.

This particular library implements observation as an application level observer, a mix-in class that reads tokens from incoming HTTP requests, a wrapper that propagates tokens to other services when you make HTTP requests, and other similar helpers. The goal is to make it possible to easily instrument your application code in such a way that operational metrics are recorded, correlation identifiers are created and propagated between services, and the same identifiers are included in log messages. All of this using a single context-manager based instrumentation mechanism.

Here’s an example of the API that I am aiming for, The request handler uses two new mix-in classes: divak.api.RequestTracker and divak.api.Logger. The request tracker adds methods that implement operation tracing and the logger is essentially a logging.LoggingAdapter that injects the correlation identifiers into LogRecord instances. I also used the divak.api.HttpClientMixin which adds a method to send HTTP requests to other services that propagates the active span information.

The application also uses two mix-in classes: divak.api.Recorder and divak.api.ProbabilisticSampler. The record is responsible for submitting trace data out-of-band to whatever aggregators you add and the sampler is what determines how frequently to sample requests.

from tornado import gen, web
import divak.api

class MyHandler(divak.api.RequestTracker, divak.api.Logger,
                divak.api.HttpClientMixin, web.RequestHandler):
   def initialize(self):
      super(self, MyHandler).initialize()
      self.set_divak_name('foo')

   @gen.coroutine
   def get(self):
      with self.record_operation('query-db'):
         rows = yield self.query('...')
         self.add_divak_tag('query-db.rowcount', len(rows))

      output = []
      for row in rows:
         self.logger.debug('requesting %r', row['id'])
         response = yield self.send_request(
            'http://.../?id={}'.format(row['id']),
            method='GET')
         output.append(response.body)
      self.set_status(200)
      self.send_response(output)

class Application(divak.api.Recorder, divak.api.ProbabilisticSampler,
                  web.Application):

   def __init__(self, *args, **kwargs):
      handlers = [web.url(r'/', MyHandler)]

      super(Application, self).__init__(handlers, *args, **kwargs)
      self.set_divak_service('my-service')
      self.set_divak_sample_probability(1.0 / 1000.0)
      self.add_divak_reporter(
         divak.api.ZipkinReporter('http://127.0.0.1:9411/api/v2'))
      self.add_divak_propagator(divak.api.ZipkinPropagation())

This example will result in zipkin tracing for GET / requests which record spans for the database query and each HTTP API call.

Metadata

Release files for divak-tornado 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for divak-tornado 0.0.3
File Size Uploaded
divak-tornado-0.0.3.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for divak-tornado 0.0.3
File Interpreter ABI Platform
divak_tornado-0.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 29.5 kB

Release files / divak-tornado-0.0.3.tar.gz

Download URL divak-tornado-0.0.3.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
337cb37d236169124dc4e1659df4ce1e00fa465445b02a0bc2925585bbbca93c
BLAKE2b-256 checksum
How to use checksums
cd57fe575414fd07b78e602333f2603a2a7b7c9059222e40ba2e078189ba9d8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / divak_tornado-0.0.3-py2.py3-none-any.whl

Download URL divak_tornado-0.0.3-py2.py3-none-any.whl
Size 11.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b2de49c2a16581ad7a664e6304e5fb3c44dd25efc5b88f04d292e2e5cc35a247
BLAKE2b-256 checksum
How to use checksums
0c2f167ac8663bc21976e6cde073947743765f236723f0eb5e20c874d62b74ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page