By clicking "Accept all cookies" you agree to have cookies stored on your device to improve site navigation, analyze site usage, and assist with our marketing efforts. See our privacy policy for more information.
OpenTracing is an open distributed tracing standard for applications and OSS packages. Many tracing backend services support OpenTracing APIs, such as Jaeger, Zipkin and SkyWalking.
This blog guides you through every step of how to trace Pulsar messages by Jaeger through OpenTracing API.
Prerequisite
Before getting started, make sure you have installed JDK 8, Maven 3, and Pulsar (cluster or standalone). If you do not have an available Pulsar, follow the instructions to install one.
Step 1: start a Jaeger backend
Start a Jaeger backend in Docker.
docker run -d -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one:latest
If you have successfully started Jaeger, you can open the Jaeger UI website successfully.
Visit http://localhost:16686 to open the Jaeger UI website without a username or password.
Step 2: add maven dependencies
This step uses OpenTracing Pulsar Client, which is integrated with the Pulsar Client and OpenTracing APIs based on Pulsar Client Interceptors, to trace Pulsar messages. Developed by StreamNative, the OpenTracing Pulsar Client acts as a monitoring tool in the StreamNatvie Hub.
Add Jaeger client dependency to connect to Jaeger backend.
For easier understanding, this blog takes a usage scenario as an example. Suppose that you have three jobs and two topics. Job-1 publishes messages to the topic-A and Job-2 consumes messages from the topic-A. When Job-2 receives a message from topic-A, Job-2 sends a message to the topic-B, and then Job-3 consumes messages from topic-B. So there are two topics, two producers and two consumers in this scenario.
According to the scenario described previously, you need to start three applications to finish this job.
Job-1: publish messages to topic-A
Job-2: consume messages from topic-A and publish messages to topic-B
Job-3: consume messages from topic-B
Job-1
This example shows how to publish messages to topic-A in Java.
Now, you can run Job-3, Job-2 and Job-1 one by one. You can see the Job-3 receives logs in the console as below:
[0] Hello Pulsar and OpenTracing!
[1] Hello Pulsar and OpenTracing!
...
[9] Hello Pulsar and OpenTracing!
Congratulations, your jobs work well. Now you can open the Jaeger UI again and there are ten traces in the Jaeger.
You can click a job name to view the details of a trace.
The span name is formatted as To__<topic-name> and From__<topic-name>__<subscription_name>, which makes it easy to tell whether it is a producer or a consumer.
Summary
As you can see, OpenTracing Pulsar Client integrates Pulsar client and OpenTracing to trace Pulsar messages easily. If you are using Pulsar and OpenTracing in your application, do not hesitate to try it out!
Additionally, I also wrote a tech blog for How to Use Apache SkyWalking to Trace Apache Pulsar Messages. For the complete content, see here.
Penghui Li
Penghui Li is passionate about helping organizations to architect and implement messaging services. Prior to StreamNative, Penghui was a Software Engineer at Zhaopin.com, where he was the leading Pulsar advocate and helped the company adopt and implement the technology. He is an Apache Pulsar Committer and PMC member. Penghui lives in Beijing, China.