Exercise 2 – the first trace

Now that we are familiar with the sample application, let's add some very basic instrumentation to it to create a trace for each HTTP request that it handles. We will do it in three steps:

  1. Create a tracer instance
  2. Start a span in the HTTP handler function
  3. Annotate the span with additional details in a few places in the code

Step 1 – create a tracer instance

As mentioned, OpenTracing is just an API, so we need to instantiate a concrete implementation of the tracer. We will be using the Jaeger tracer as an example, but the function that creates the tracer will be the only place in the whole program that is Jaeger-specific. It can be easily replaced with any other OpenTracing-compatible tracer, such as Zipkin or tracers from ...

Get Mastering Distributed Tracing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.