Service Tracing Analysis on Spring Cloud Applications Using Zipkin

Service tracing analysis

Spring Cloud Sleuth and Zipkin

Service REST calls

@RequestMapping("/")
public String callHome(){
LOG.log(Level.INFO, "calling trace demo backend");
return restTemplate.getForObject("http://backend:8090", String.class);
}

HTTP request calls using RestTemplate

@RequestMapping("/")
public String callHome(){
LOG.log(Level.INFO, "calling trace demo backend");
return restTemplate.getForObject("http://backend:8090", String.class);
}
@RequestMapping("/")
public String home(){
LOG.log(Level.INFO, "trace demo backend is being called");
return "Hello World.";
}

Introduce Sleuth and Zipkin dependent packages

dependencies {
compile('org.springframework.cloud:spring-cloud-starter-sleuth')
compile('org.springframework.cloud:spring-cloud-sleuth-zipkin')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
spring.zipkin.base-url=http://zipkin-server:9411

Build a Docker image

FROM java:8-jre-alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/' /etc/apk/repositories
VOLUME /tmp
ADD build/libs/*.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
cd tracedemo
./gradlew build
docker build -t zipkin-demo-frontend .
cd ../tracebackend
./gradlew build
docker build -t zipkin-demo-backend .
After the image is ready, upload the image to your image repository with the `docker push` command.

Zipkin Server

dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile('io.zipkin.java:zipkin-server')
runtime('io.zipkin.java:zipkin-autoconfigure-ui')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
@SpringBootApplication
@EnableZipkinServer
public class ZipkinApplication {
public static void main(String[] args) {
SpringApplication.run(ZipkinApplication.class, args);
}
}
server.port=9411

Build a Docker image

Deployment on Alibaba Cloud Docker

version: "2"
services:
zipkin-server:
image: registry.cn-hangzhou.aliyuncs.com/jingshanlb/zipkin-demo-server
labels:
aliyun.routing.port_9411: http://zipkin
restart: always
frontend:
image: registry.cn-hangzhou.aliyuncs.com/jingshanlb/zipkin-demo-frontend
labels:
aliyun.routing.port_8080: http://frontend
links:
- zipkin-server
- backend
restart: always
backend:
image: registry.cn-hangzhou.aliyuncs.com/jingshanlb/zipkin-demo-backend
links:
- zipkin-server
restart: always

create an application

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store