Difficulty: Beginner
Estimated Time: 10 minutes

OpenTracing is a vendor neutral specification for instrumentation APIs.

It offers consistent, expressive, vendor-neutral APIs for popular platforms, making it easy for developers to add (or switch) tracing implementations with an O(1) configuration change. OpenTracing also offers a lingua franca for OSS instrumentation and platform-specific tracing helper libraries.

This tutorial is based on Yuri Shkuro's OpenTracing tutorials

This scenario is based on the OpenTracing tutorial located at https://github.com/yurishkuro/opentracing-tutorial

The complete program can be found in the solution package. We moved the initTracer helper function into its own package lib so that we can reuse it in the other lessons as Tracing.init().

Don’t stop now! The next scenario will only take about 10 minutes to complete.

OpenTracing Tutorial - Lesson 1

Step 1 of 4

A simple Hello-World program

First, let's switch to the Java version of the tutorial: cd opentracing-tutorial/java.

Then, let's create a simple Java program lesson01/exercise/Hello.java that takes an argument and prints Hello, {arg}!.

package lesson01.exercise;

public class Hello {

    private void sayHello(String helloTo) {
        String helloStr = String.format("Hello, %s!", helloTo);
        System.out.println(helloStr);
    }

    public static void main(String[] args) {
        if (args.length != 1) {
            throw new IllegalArgumentException("Expecting one argument");
        }
        String helloTo = args[0];
        new Hello().sayHello(helloTo);
    }
}

And now run it with ./run.sh lesson01.exercise.Hello Bryan. Here we're using a simple helper script run.sh that executes a class via Maven, as well as strips out some of it diagnostic logging, so, it might take a while for the first run to complete.

Hello.java