语言: Java
框架:春季靴
工具:积家
我已经完成以下配置,将整个跟踪记录到日志中。 但是在控制器级别的日志中未显示跟踪。何时执行休眠查询,而不是在日志(在服务和存储库级别的日志上)上放置跟踪之后
application.log
2019-11-08 05:14 INFO [iHub-service,] [http-nio-8080-exec-27] INFO c.s.controller.Controller ...............message.............
2019-11-08 05:14 DEBUG [iHub-service,294d434a24290786:294d434a24290786:0:1 - ] [http-nio-8080-exec-27] DEBUG org.hibernate.SQL logStatement - Hibernate query
Hibernate: hibernate query.........
2019-11-08 05:14 INFO [iHub-service,294d434a24290786:294d434a24290786:0:1 - ] [http-nio-8080-exec-27] INFO i.j.i.reporters.LoggingReporter report - Span reported: b9b799296f2b2dda:7aa285d9c044dce6:b9b799296f2b2dda:1 - Query
2019-11-08 05:14 DEBUG [iHub-service,b9b799296f2b2dda:7aa285d9c044dce6:b9b799296f2b2dda:1 - Query] [http-nio-8080-exec-27] DEBUG org.hibernate.SQL logStatement - hibernate query
Hibernate: hibernate query...........
记者类
public class MDCReporter implements Reporter {
public MDCReporter() {
// default constructor
}
@Override
public void report(JaegerSpan span) {
MDC.put("traceinfo", span);
}
Appender类
public class JaegerReportAppender implements ReporterAppender {
public JaegerReportAppender() {
// default constructor
}
@Override
public void append(Collection<Reporter> reporters) {
reporters.add(new MDCReporter());
}
}
主要的春季靴子类
@SpringBootApplication
public class Service1Application {
public static void main(String[] args) {
SpringApplication.run(Service1Application.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
JaegerReportAppender customLoggingReporter() {
return new JaegerReportAppender();
}
}
Application.properties
opentracing.jaeger.http-sender.url = http://localhost:14268/api/traces
logging.pattern.console=%d{yyyy-MM-dd HH:mm} %5p [${spring.application.name},%X{traceinfo:-}] [%thread] %-5level %logger{36} %M - %msg%
spring.sleuth.opentracing.enabled=false
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.solanki</groupId>
<artifactId>Service-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Service-2</name>
<description>service-1</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/io.opentracing.contrib/opentracing-spring-jaeger-cloud-starter -->
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:0)
不幸的是,报告器界面用于报告已完成的跨度,它在JaegerSpan.finish上被调用。我想这就是为什么它不出现在日志中的原因。