Add the libraries and code to generate traces

We start by adding two libraries for the tracing to our project: jaeger-client and flask_opentracing. flask-opentracing adds tracing into Flask projects so that you can easily have all HTTP endpoints traced automatically. The OpenTracing project doesn't include any collectors, so we also need a library to collect and send the trace data somewhere, in this case, jaeger-client.

The example also adds the requests library, as in this example we will add an HTTP endpoint that makes a remote request, processes the responses, and returns the values—and add tracing to that sequence.

Importing the libraries and initializing the tracer is fairly straightforward:

import opentracingfrom jaeger_client import ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.