So you are into micro-services and you already found about OpenTracing and you want to use that fancy JaegerUI to see what is really going on between your micro-services. You already noticed that there are not many examples out there about jaeger and node.js. I hear you! This is why I created this repository, I want to help you understand how multi-micro-service tracing works with Jaeger.
You will learn how your tracers in your micro-services inject 💉 and extract 👀 headers.
- Node.js Active LTS recommended
- PM2 To start multiple node.js instances easily
- Jaeger All in One Docker Image To setup a jeager collector in your local environment
-
Install prerequisites
-
Make sure you have installed Node.js and Docker
-
Install PM2 globally
npm i -g pm2
-
Run Jaeger All in One Docker Image
docker run -d --name jaeger \ -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \ -p 5775:5775/udp \ -p 6831:6831/udp \ -p 6832:6832/udp \ -p 5778:5778 \ -p 16686:16686 \ -p 14268:14268 \ -p 9411:9411 \ jaegertracing/all-in-one:1.8
-
-
Run the example project
-
Clone this repository
git clone git@github.com:algun/jaeger-nodejs-example.git
-
Change your directory into the project
cd jaeger-nodejs-example
-
Install packages
npm i
-
Use PM2 to start up all your services
pm2 start
-
Use PM2 to watch project logs
pm2 logs
-
-
Visit your initial endpoint to create traces between all services
-
Visit your local JaegerUI to enjoy your micro-service trace visualizations
Here are some key points to understand how this project instruments these services with jaeger:
- Check
ecosystem.config.js
file to see how service names and ports are defined - Pay attentions to
tracer.inject()
andtracer.extract()
commands to understand how the spans flow into another service via http headers. - Notice that
init-service
has onlytracer.inject()
since it is the firelight of our multi-micro-service calls. - Notice that
andservice4
service5
have onlytracer.extract()
since they are the end of the line for our micro-service structure in this example. - Notice that
service4
still injects its headers withtracer.inject()
but it makes no sense since it will not create request any further within this project.
This is my humble attempt to help people out who is struggling to understand tracing concept between micro-services.