This repository serves to demonstrate how to trace calls between services in a microservice environment. This is particularly important to analyze traffic flow and to identify API bottlenecks and performance issues. Do note that tracing and logging are separated on purpose. Tools such as ELK stack should be preferred for distributed logging purpose.
Simply run start-docker.bat
;
Simply run start-compose.bat
- Make a call to
employee-service
by visitinghttp://localhost:9080/employees
- Check
zipkin
athttp://localhost:9411/zipkin
. ClickRun Query
and then select the first span to view detail. You should see this:
- It shows that call to
employee-service
'sGET /employees
took 366ms. - It shows that
employee-service
calledinventory-service
'sGET /inventories
REST resource. - It shows that
inventory-service
made a connection to database and executed some queries.
protip, if you click on the span
with jdbc
prefix then you can see these details:
spring-cloud-starter-zipkin
contains bothSleuth
(add tracing using MDC) andZipkin
(send trace tozipkin
server).p6spy-spring-boot-starter
will create proxies that allow JDBC calls to be intercepted and reported tozipkin
.
- It seems that there are no official alpine version of jdk8+ available and that causes image size to increase. Base
image that's currently used is not officially supported by
alpine
. - If we're running everything in this repo using
docker
only, a container can reach another container by connecting tohttp://host.docker.internal:port
instead ofhttp://localhost:post
. It seems thathost.docker.internal
is a special DNS name that resolves to the host machine (a.k.a, the host machine's localhost). - It's helpful to run a container with name supplied e.g.,
docker run -d --name coolName imageName
. One can then stop container using name instead of container id e.g.,docker top coolName
- In
docker-compose
, we don't need tohost.docker.internal
. Instead, we connect to a particular container using the container'sservice name
defined indocker-compose.yaml
. - When connecting from one container to another in
docker-compose
, remember to point to the container(service)'s container port instead of host port
version: "3.8"
services:
employee: # 'employee' is the 'service-name'
image: aurelius0523/employee-service
ports:
- 9080:8080
inventory: # 'inventory' is also 'service name'
image: aurelius0523/inventory-service
ports:
- 9081:8081 # if employee-service needs to call inventory-service, the url will be http://inventory/8081