如何将整个日志发送到 Quarkus 中的 jeager span?

How to send entire logs to jeager span in Quarkus?

有没有办法把应用程序提供的标准日志和错误放到一个span中? 我想把 quarkus 中提供的 slf4j 日志放在 jeager-Ui

Quarkus log information

application.properties

quarkus.http.port=8200
quarkus.swagger-ui.always-include=true
quarkus.jaeger.service-name=myservice
quarkus.jaeger.reporter-log-spans=true
quarkus.jaeger.log-trace-context=true
quarkus.jaeger.propagation=jaeger
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n

quarkus.log.handler.gelf.enabled=true
quarkus.log.handler.gelf.host=localhost
quarkus.log.handler.gelf.port=12201

以下是我用来实现集中式日志管理(ELK)的依赖项。为此,我正在使用 quarkus quarkus-centralized-log-managemt guide

提供的指南

pom.xml

<dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-smallrye-opentracing</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-hibernate-validator</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-rest-client</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-smallrye-openapi</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jackson</artifactId>
    </dependency>
    <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-logging-gelf</artifactId>
    </dependency>
    <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-smallrye-metrics</artifactId>
    </dependency>
  </dependencies>
    

您可以@Inject Tracer 并在其中添加您自己的东西。

但我以为 Jaeger 会自动记录错误,但我可能错了。

配置您的日志以接受 Jaeger 属性后,例如 ex :

quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) [traceId=%X{traceId},spanId=%X{spanId},%X{sampled}] %s%e%n

然后您需要通过以下属性将 Jaeger 上下文传播到您的日志:

quarkus.jaeger.log-trace-context=true

quarkus.jaeger.propagation=jaeger

我在 application.properties.By 中添加了一个新的 gelf 配置 属性 这样我们就可以将带有 traceId 和 spanId 的日志发送到 ELK 堆栈。

application.properties

quarkus.http.port=8200
quarkus.swagger-ui.always-include=true
quarkus.jaeger.service-name=myservice
quarkus.jaeger.reporter-log-spans=true //This can be excluded
quarkus.jaeger.propagation=jaeger //This can be excluded
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.log.console.format=%d{HH:mm:ss} %-5p traceId=%X{traceId}, spanId=%X{spanId}, sampled=%X{sampled} [%c{2.}] (%t) %s%e%n

quarkus.log.handler.gelf.enabled=true
quarkus.log.handler.gelf.host=localhost
quarkus.log.handler.gelf.port=12201
quarkus.log.handler.gelf.include-full-mdc=true //newly added property