After gaining a preliminary understanding of the concept of OpenTelemetry, we will use Jaeger as an example to demonstrate how to implement tracing in a program.

Jaeger

Jaeger \ˈyā-gər\ is Uber’s open-source distributed tracing system and one of the systems that support OpenTelemetry. It is also a CNCF project. In this article, we will use Jaeger to demonstrate how to introduce distributed tracing into a system. Below is the architecture diagram for Opentracing+Jaeger, which also applies to using OpenTelemetry.

Tracing - Preparation - 图1

Preparation

Jaeger offers an all-in-one image, which allows us to quickly start testing:

  1. docker run --rm --name jaeger \
  2. -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \
  3. -p 6831:6831/udp \
  4. -p 6832:6832/udp \
  5. -p 5778:5778 \
  6. -p 16686:16686 \
  7. -p 4317:4317 \
  8. -p 4318:4318 \
  9. -p 14250:14250 \
  10. -p 14268:14268 \
  11. -p 14269:14269 \
  12. -p 9411:9411 \
  13. jaegertracing/all-in-one:1.55

If pulling the docker image is too slow, you can try modifying the image address of the docker pull site, such as: http://mirrors.ustc.edu.cn/help/dockerhub.html?highlight=docker

After the image starts, you can open the Jaeger UI via http://localhost:16686.

Tracing - Preparation - 图2

Sample Code Address

Our sample code is in the gf main repository, located at: https://github.com/gogf/gf/tree/master/example/trace

Encapsulated Jaeger Registration (to be removed in version 2.6.0)

For developers’ convenience, we have encapsulated the initialization logic for jaeger through a community module, code address: https://github.com/gogf/gf/tree/master/contrib/trace/jaeger

OTLP HTTP Encapsulation

For developers’ convenience, we have encapsulated the initialization logic for otelhttp through a community module, code address: https://github.com/gogf/gf/tree/master/contrib/trace/otlphttp

OTLP GRPC Encapsulation

For developers’ convenience, we have encapsulated the initialization logic for otelgrpc through a community module, code address: https://github.com/gogf/gf/tree/master/contrib/trace/otlpgrpc