Welcome to my GitHub

https://github.com/zq2599/blog_demos

Content: Classification and summary of all original articles and supporting source code, involving Java, Docker, Kubernetes, DevOPS, etc.;

The full text of the "Jaeger Actual Combat (Java Edition)" series

  1. "Jaeger, a distributed call chain tracking tool? Two-minute speed experience"
  2. "Introduction to Jaeger Development (Java Version)"
  3. "How Java Application Logs are Related to Jaeger's Trace"
  4. "Jaeger's Client Sampling Configuration"
  5. "Minimalist! One annotation can create Jaeger's Span"
  6. "Supplement to Jaeger Knowledge Points"

Overview of this article

  • This article is the final chapter of the "Jaeger Actual Combat (Java Edition)" series. It is a pleasant time to learn and fight together. Now it's finally time to say goodbye. Finally, I will provide three useful knowledge points accumulated in ordinary times as the end. , And hope to help your development:
  • Modify service name
  • Close the log reported by span
  • Persistent storage of all-in-one images

    Modify service name

  • The service name seen on Jaeger’s web page is the value configured by spring.application.name by default. If you are not satisfied, you can customize it yourself. The configuration item is <font color="blue">opentracing.jaeger.service -name</font>, as shown in the red box in the figure below, I changed it to Chinese name here:

在这里插入图片描述

  • After running, the red box in the following picture is displayed on Jaeger's web page:

在这里插入图片描述

Close the log reported by span

  • The following is a log, only the first two lines are printed out by the <font color="blue">log.info</font> method when we write the code, and the remaining four lines are all output by the Jaeger SDK
00:18:12 [http-nio-8080-exec-1] INFO  c.b.j.p.c.HelloController [traceId=49476da841cd354b spanId=b595271a496cb0cb sampled=true] start hello from [1632269892342]
00:18:12 [http-nio-8080-exec-1] INFO  c.b.j.p.c.HelloController [traceId=49476da841cd354b spanId=b595271a496cb0cb sampled=true] hello
00:18:12 [http-nio-8080-exec-1] INFO  i.j.i.r.LoggingReporter [traceId=49476da841cd354b spanId=b595271a496cb0cb sampled=true] Span reported: 49476da841cd354b:991b82965543f8da:e6333b3a1c14f544:1 - mockBizChild
00:18:12 [http-nio-8080-exec-1] INFO  i.j.i.r.LoggingReporter [traceId=49476da841cd354b spanId=b595271a496cb0cb sampled=true] Span reported: 49476da841cd354b:e6333b3a1c14f544:b595271a496cb0cb:1 - mockBiz
00:18:13 [http-nio-8080-exec-1] INFO  i.j.i.r.LoggingReporter [traceId=49476da841cd354b spanId=b595271a496cb0cb sampled=true] Span reported: 49476da841cd354b:45e256ba3deed679:b595271a496cb0cb:1 - SET
00:18:13 [http-nio-8080-exec-1] INFO  i.j.i.r.LoggingReporter [traceId= spanId= sampled=] Span reported: 49476da841cd354b:b595271a496cb0cb:6322077c0edb62cc:1 - hello
  • In the above log, the content output by the Jaeger SDK is not very useful in general, and can be closed with the following configuration in the red box:

在这里插入图片描述

  • Run again, the log is as follows, cleaned up:
00:12:42 [http-nio-8080-exec-10] INFO  c.b.j.p.c.HelloController [traceId=6430f498d5623103 spanId=9e4a4c8bb326352b sampled=true] start hello from [1632269562868]
00:12:42 [http-nio-8080-exec-10] INFO  c.b.j.p.c.HelloController [traceId=6430f498d5623103 spanId=9e4a4c8bb326352b sampled=true] hello

Persistent storage of all-in-one images

  • Deploying the Jaeger server with all-in-one image is simple and fast, suitable for use in the development and debugging stages. The deployment can be completed by the following command:
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 14269:14269 \
-p 9411:9411 jaegertracing/all-in-one:1.26
  • Although the above command can make the Jaeger backend work normally, it has a flaw: the data is stored in the memory, and the data cannot be restored after the container is restarted. To solve this problem, you can enable the badger (a kind of Embedded storage), and store the badger data on the host. The complete command is as follows, where <font color="blue">/Users/will/temp/202109/28/data</font> is me Please modify the disk directory of your computer according to your actual situation:
docker run -d \
--name jaeger \
-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
-e SPAN_STORAGE_TYPE=badger \
-e BADGER_EPHEMERAL=false \
-e BADGER_DIRECTORY_VALUE=/badger/data \
-e BADGER_DIRECTORY_KEY=/badger/key \
-v /Users/will/temp/202109/28/data:/badger \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 14268:14268 \
-p 14269:14269 \
-p 9411:9411 jaegertracing/all-in-one:1.26
  • Restart or rebuild the Jaeger container at this time, and the historical data will be fully preserved
  • If you are configuring the all-in-one image in docker-compose.yml, you should note that you cannot enter boolean attribute values in the yml file, and you need to refer to the following methods:
  • First, create a file <font color="blue">.env</font> in the directory where docker-compose.yml is located, with the content as follows:
BADGER_FLAG=true
  • Finally, in docker-compose.yml, the configuration of the Jaeger container is as follows, using the configuration items in the <font color="blue">.env</font> file. In addition, my local storage here uses newly created volumes , You can change to the previous local disk mapping according to your needs:
version: '3.0'

networks:
  jaeger-tutorials-net:
    driver: bridge
    ipam:
      config:
        - subnet: 192.168.1.0/24
          gateway: 192.168.1.1

volumes:
  # 用于存储badger的数据
  badger-data:

services:
  jaeger:
    image: jaegertracing/all-in-one:1.26
    container_name: jaeger
    # 处理时钟漂移带来的计算出负数的问题
    command: ["--query.max-clock-skew-adjustment=100ms"]
    # 选择网络
    networks:
      - jaeger-tutorials-net
    # 持久化,请选择适合自己的目录
    environment:
      SPAN_STORAGE_TYPE: badger
      BADGER_EPHEMERAL: ${BADGER_FLAG}
      BADGER_DIRECTORY_VALUE: /badger/data
      BADGER_DIRECTORY_KEY: /badger/key
    # badger存储在本地卷(或者映射到本地某个目录)
    volumes:
      - badger-data:/badger
    #选择端口
    ports:
      - 16686:16686/tcp
    restart: always
  • At this point, the "Jaeger Actual Combat (Java Edition)" series is finally time to say goodbye, hope to provide a useful reference for your system construction, let's continue to meet in the next Xinchen original series.

You are not lonely, Xinchen is with you all the way

  1. Java series
  2. Spring series
  3. Docker series
  4. kubernetes series
  5. Database + Middleware Series
  6. DevOps series

Welcome to pay attention to the public account: programmer Xin Chen

Search "Programmer Xin Chen" on WeChat, I am Xin Chen, and I look forward to traveling the Java world with you...
https://github.com/zq2599/blog_demos

程序员欣宸
147 声望24 粉丝

热爱Java和Docker