DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • How to Create Microservices Using Spring
  • Component Tests for Spring Cloud Microservices
  • Migration of Microservice Applications From WebLogic to Openshift

Trending

  • LLM-Powered Deep Parsing for Industrial Inventory Search
  • Feature Flag Debt: Performance Impact in Enterprise Applications
  • Compliance Automated Standard Solution (COMPASS), Part 10: How OSCAL Mapping Paves the Way for Continuous Compliance Scalability
  • A System Cannot Protect What It Does Not Understand
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Cloud and Spring Boot, Part 2: Implementing Zipkin Server For Distributed Tracing

Spring Cloud and Spring Boot, Part 2: Implementing Zipkin Server For Distributed Tracing

This second tutorial takes a look at how Zipkin server works with Eureka for distributed tracing.

By 
Jitendra Bafna user avatar
Jitendra Bafna
·
Jan. 11, 19 · Tutorial
Likes (16)
Comment
Save
Tweet
Share
70.1K Views

Join the DZone community and get the full member experience.

Join For Free

In my last article you have learn how to implement Eureka Server for service discovery and registration. In this article, you will learn one more important feature of microservices, Distributed Tracing.

What is Distributed Tracing?

Distributed Tracing is crucial for troubleshooting and understanding microservices. It is very useful when we need to track the request passing through multiple microservices. Distributed Tracing can be used to measure the performance of the microservices. 

It is easy to identify which microservice is failed or having performance issues whenever there are multiple service calls within a single request.

In this article, you will see how to implement Zipkin Server for Distributed Tracing.

To achieve this, you need to create Zipkin Server application and add these two dependencies in POM.xml.

<dependency>
    <groupId>io.zipkin.java</groupId>
    <artifactId>zipkin-server</artifactId>
    <version>2.11.7</version>
</dependency>
<dependency>
    <groupId>io.zipkin.java</groupId>
    <artifactId>zipkin-autoconfigure-ui</artifactId>
    <version>2.11.7</version>
</dependency>

Implementing Zipkin Server 

Create Spring Boot Application

You need to create a Maven application and name the application (i.e. zipkin-server) or you can use https://start.spring.io to create a Spring project.

POM.xml

You need to add this list of dependencies in the POM.xml of your project.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example.zikin.server</groupId>
<artifactId>zipkin-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>zipkin-server</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
    <groupId>io.zipkin.java</groupId>
    <artifactId>zipkin-server</artifactId>
    <version>2.11.7</version>
</dependency>

<dependency>
    <groupId>io.zipkin.java</groupId>
    <artifactId>zipkin-autoconfigure-ui</artifactId>
    <version>2.11.7</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

Spring Boot Starter Application

Now you need to open the Spring Boot application ZipkinServerApplication.java and add the annotation  @EnableZipkinServer  on the top of the class as shown below.

package com.example.zikin.server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import zipkin.server.EnableZipkinServer;

@SpringBootApplication
@EnableZipkinServer
public class ZipkinServerApplication {

public static void main(String[] args) {
SpringApplication.run(ZipkinServerApplication.class, args);
}
}

Application Properties file

You need to add the below list of properties in application.properties located at src/main/resources of your application.

spring.application.name=zipkin-server
server.port=9411

Running Zipkin Server

Run the Zipkin server as a Java application and navigate to the url: http://localhost:9411/zipkin.

Image title

Currently, you will not see any traces as there is no client application registered with Zipkin Server.

Registering Client Application With Zipkin Server

Registering Eureka Server With Zipkin Server

In the last article, you have seen how to implement the Eureka Server. You can register Eureka Server to Zipkin server by adding one property in application.properties file located at src/main/resources.

spring.zipkin.base-url=http://localhost:9411/

spring.zipkin.base-url determines the address where Zipkin Server is running.

You need to add one dependency in POM.xml of Eureka Server application.

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

Once Eureka Server is up and running, you can find traces in Zipkin Server and even you can see eureka-server in Service Name of Zipkin Server UI.

Image title

Registering Spring Boot Client Application With Zipkin Server

For registering any Spring Boot-based client application, you simply need to add one property in application.properties file of your application located at src/main/resources.

spring.zipkin.base-url=http://localhost:9411/

You need to add one dependency in POM.xml of your client application.

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

Once your client application is up and running, you can see the traces in the Zipkin server.

Image title

Viewing Traces Details in Zipkin Server

You can view the traces details by clicking any of entry shown in above image.

Image title

Now you have learned how to implement Zipkin Server for Distributed Tracing.

Spring Framework Spring Boot application Spring Cloud microservice

Opinions expressed by DZone contributors are their own.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • How to Create Microservices Using Spring
  • Component Tests for Spring Cloud Microservices
  • Migration of Microservice Applications From WebLogic to Openshift

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook