Oct 10, 2019
6 min read

Use Apache SkyWalking to Trace Apache Pulsar Messages

Penghui Li
Engineering Lead of Messaging Team, StreamNative

Overview

Apache Pulsar is a distributed messaging platform and a fast-growing alternative to Kafka. Apache SkyWalking is a popular application performance monitoring tool for distributed systems, specially designed for microservices, cloud-native, and container-based (Docker, K8s, and Mesos) architectures.

Message tracing is a very useful feature which helps engineers troubleshoot problems related to message publishing and receiving.

This tutorial shares how to track Pulsar messages by using SkyWalking.

Prerequisite

Before getting started, make sure you have installed Git, JDK 8, Maven 3, and Pulsar (cluster or standalone). If you do not have an available Pulsar, follow the instruction (http://pulsar.apache.org/docs/en/standalone/) to install.

Build Pulsar agent from SkyWalking source

The Apache Pulsar agent will be officially released in the SkyWalking 6.5.0, since it has not been released yet, you need to build a Pulsar agent from the source of SkyWalking.

1. Download the SkyWalking source and build the Pulsar agent plugin.

<script>
$ git clone https://github.com/apache/SkyWalking.git
    $ cd SkyWalking
    $ git submodule init
    $ git submodule update
    $ ./mvnw clean package -DskipTests
<script> 

2. Decompress the file apache-SkyWalking-apm-bin.tar.gz.

After the decompression, all packages are in the directory apm-dist/target.

<script>
$ tar -xf apache-SkyWalking-apm-bin.tar.gz
<script> 

You can find the Pulsar agent plugin is in the directory agent/plugins.

Congratulations, you have successfully built the Pulsar agent plugin.

Start a SkyWalking backend

If you already have an available SkyWalking backend, you can skip this step. If not, here is a quick start for running a SkyWalking backend locally.

Tip: if you run the SkyWalking backend and Pulsar broker on the same machine, you need to change the web service port of SkyWalking or Pulsar.

For how to change the web service port of SkyWalking UI, see here.

If you want to change the web service port of Pulsar broker, edit the file conf/broker.conf.

Download test project and set up

1. Download the SkyWalking integration test for Apache Pulsar.

<script>
$ git clone https://github.com/SkyAPMTest/agent-auto-integration-testcases.git
In this repo, you can find a project named pulsar-scenario.
<script> 

2. Import the project pulsar-scenario to your IDE.

Here takes Intelli IDEA as an example.

As shown in the image below, the project pulsar-scenario is a spring boot application and has a CaseController.

developper interface to show how to Import the project pulsar-scenario

3. Set up the Pulsar agent plugin.

Before starting the spring boot application, you need to set up the Pulsar agent plugin.

Tip:

  • For how to set up a Java agent and its properties, see here.
  • By default, the project pulsar-scenario uses the 8082 port.
  • Detail of VM options as shown in the image below:
<script>
```bash
     
        -javaagent:/apm-dist/target/apache-SkyWalking-apm-bin/agent/SkyWalking-agent.jar -DSW_AGENT_COLLECTOR_BACKEND_SERVICES=:11800 -DSW_AGENT_NAME=pulsar-demo -Dservice.url=pulsar://:6650
     
    ```
<script> 
image of pulsar agent plugin

Test and view in SkyWalking

After performing the steps stated previously, you have prepared all the environments. Next, you can simulate some requests and view them in SkyWalking UI. Download the pulsar-case.

<script>
$ curl http://localhost:8082/pulsar-scenario/case/pulsar-case
<script> 

By executing the HTTP request above, some traces are created in SkyWalking. Let’s go to the SkyWalking UI to check them.

Dashboard view

It shows there are 2 endpoints, 1 service, and 1 MQ.

skywalking interface with graph

Topology view

It shows that a user sends a request to the web service (that is, your test web application) and the web service sends to and receives messages from a Pulsar broker.

skywalking interface with workflow apach

Trace view

It shows the trace details of each request.

Currently, the Pulsar agent plugin has 3 types of spans as below:

  • Producer span, which records messages sent by producers.
  • Producer callback span, which records messages are already sent.
  • Consumer span, which records messages are received by consumers.
skywalking interface with pulsar demo

Summary

As you can see, SkyWalking UI is pretty cool! If you are still worried about how to track Pulsar messages, try this integration of Pulsar and SkyWalking.

Thanks for the SkyWalking community who gives me a lot of help for the integration of Pulsar and SkyWalking.

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.

Related articles

Apr 11, 2024
5 min read

The New CAP Theorem for Data Streaming: Understanding the Trade-offs Between Cost, Availability, and Performance

Mar 31, 2024
5 min read

Data Streaming Trends from Kafka Summit London 2024

Newsletter

Our strategies and tactics delivered right to your inbox

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Pulsar Tutorials