Zipkin works well locally but not in docker container. All the microservices are registered well in the Eureka and they can communicate well. But the only problem is Zipkin. I am getting the following error:
org.springframework.web.client.ResourceAccessException: I/O error on
POST request for "http://localhost:9411/api/v2/spans": Connect to
http://localhost:9411 [localhost/127.0.0.1] failed: Connection refused
my docker-compose.yaml is as follows:
version: '3.8'
services:
currency-exchange:
image: samankt/springboot-udemy-currency-exchange:0.0.1-SNAPSHOT
mem_limit: 512m
ports:
- '8000:8000'
networks:
- saman-network
environment:
EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka
EUREKA.INSTANCE.PREFERIPADDRESS: true
SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_ZIPKIN_SENDER_TYPE: rabbit
depends_on:
- naming-server
- rabbitmq
api-gateway:
image: samankt/springboot-udemy-currency-api-gateway:0.0.1-snapshot
mem_limit: 512m
ports:
- '8765:8765'
networks:
- saman-network
environment:
EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka
EUREKA.INSTANCE.PREFERIPADDRESS: true
SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_ZIPKIN_SENDER_TYPE: rabbit
depends_on:
- naming-server
- rabbitmq
currency-converter:
image: samankt/currency-conversion:0.0.1-SNAPSHOT
mem_limit: 700m
ports:
- '8100:8100'
networks:
- saman-network
environment:
EUREKA.CLIENT.SERVICE-URL.DEFAULTZONE: http://naming-server:8761/eureka
EUREKA.INSTANCE.PREFERIPADDRESS: true
SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/
SPRING.ZIPKIN.DISCOVERYCLIENTENABLED: true
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_ZIPKIN_SENDER_TYPE: rabbit
depends_on:
- naming-server
- rabbitmq
naming-server:
image: samankt/naming-server:0.0.1-SNAPSHOT
mem_limit: 512m
ports:
- '8761:8761'
environment:
SPRING.ZIPKIN.BASE-URL: http://zipkin-server:9411/
networks:
- saman-network
zipkin-server:
image: openzipkin/zipkin:latest
mem_limit: 400m
ports:
- '9411:9411'
networks:
- saman-network
environment:
RABBIT_URI: amqp://guest:guest@rabbitmq:5672
depends_on:
- rabbitmq
restart: always
rabbitmq:
image: rabbitmq:3.8.12-management
ports:
- '5672:5672'
- '15672:15672'
networks:
- saman-network
networks:
saman-network:
2
Answers
The problem is solved when I downgraded to Spring 2.x from 3.0.
It seems that Zipkin does not work well with Spring 3.0 currently. The problem is for docker, not local running. I could not find enough resources to support this idea. But in my experience, this is the case. I tried Zipkin with "latest" tag with Spring 3.0.0 but the problem persists. But it does work well with Spring 2.x
SOLUTION 1
The error is telling you that the connection on
http://localhost:9411/api/v2/spans
is refused. When you run your application inside a docker container you need to send the request not with localhost, but through the docker network (in your case saman-network). To access the docker container which runs zipkin you need to send the request tohttp://zipkin-server:9411/api/v2/spans
.From Spring Boot 3 Sleuth is deprecated and you will need to use micrometer.
To use tracing with zipkin you can add the following 4 dependencies to you
pom.xml
fileFinally to change the Zipkin endpoint to send the tracing information you need to add the following to your application.yaml file.
It is good practice to use Spring profiles, therefore you copy your
application.yaml
file and name itapplication-docker.yaml
. In this new file you can modify the Zipkin endpoint with the zipkin container namezipkin-server
.You can activate the Spring profiles passing
SPRING_PROFILES_ACTIVATE=docker
in the environment.SOLUTION 2
For you this solution is faster to implement but I didn’t test it. You pass the Zipkin url as an environment value
SPRING.ZIPKIN.BASE-URL
inside thedocker-compose.yml
.This property was used with the Sleuth package. With Spring Boot 3 and micrometer try to pass instead:
MANAGEMENT.ZIPKIN.TRACING.ENDPOINT: http://zipkin-server:9411/api/v2/spans