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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • AI Technology Is Drastically Disrupting the Background Screening Industry
  • Hyperion Essbase Technical Functionality
  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Implementing RBAC in Quarkus

Trending

  • AI Technology Is Drastically Disrupting the Background Screening Industry
  • Hyperion Essbase Technical Functionality
  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Implementing RBAC in Quarkus
  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.

Jitendra Bafna user avatar by
Jitendra Bafna
CORE ·
Jan. 11, 19 · Tutorial
Like (16)
Save
Tweet
Share
65.87K 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.

Trending

  • AI Technology Is Drastically Disrupting the Background Screening Industry
  • Hyperion Essbase Technical Functionality
  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Implementing RBAC in Quarkus

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: