spring - spring cloud sleuth 无法生成 spanID
问题描述
有必要为所有进入控制台日志的内容生成一个 span-id,但不幸的是,没有生成 span-id:
2019-03-13 12:35:27.116 INFO [core.data,,,] 13304 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1fd386c3: startup date [Wed Mar 13 12:35:27 MSK 2019]; root of context hierarchy
2019-03-13 12:35:27.268 INFO [core.data,,,] 13304 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-03-13 12:35:27.298 INFO [core.data,,,] 13304 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$66207a2f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-13 14:58:43,737+0300 p=INFO l=org.springframework.boot.web.servlet.FilterRegistrationBean trace-id= span-id= Mapping filter: 'characterEncodingFilter' to: [/*]
2019-03-13 14:58:43,737+0300 p=INFO l=org.springframework.boot.web.servlet.FilterRegistrationBean trace-id= span-id= Mapping filter: 'webMvcMetricsFilter' to: [/*]
2019-03-13 14:58:43,738+0300 p=INFO l=org.springframework.boot.web.servlet.FilterRegistrationBean trace-id= span-id= Mapping filter: 'unauthorizedLogbookFilter' to: [/*]
应用程序.yml
logging:
config: classpath:config/logging/logback.xml
pattern:
console: '%d{"yyyy-MM-dd HH:mm:ss,SSSZ"} %clr(p=%level) %clr(t=%t){yellow} %clr(l=%logger){magenta} %clr(trace-id=%X{X-B3-TraceId:-}){blue} %clr(span-id=%X{X-B3-SpanId:-}){cyan} %msg%n'
level:
org.hibernate: info
org.springframework: info
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--spring defaults-->
<include
resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-
appender.xml"/>
<!--custom configurations-->
<include resource="config/logging/file-appender.xml"/>
<!-- level configurations-->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
显式调用的日志记录方法会生成 span-id:
Logger log = loggerFactory().getLogger(this.class);
public void method(){ log.info("test"); }
解决方案
首先创建一个 Rest Api 并向其发出 api 请求(如果尚未完成)。如果您使用的是 Restemplate,请尝试创建一个 RestTemplate bean。
还将日志记录级别设置为调试
logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
推荐阅读
- python - 如何创建一个循环模块,为每个 SQL 行结果一次创建一个窗口?
- javascript - 无法在使用 axios 的反应中设置不安全的标头“主机”
- node.js - Electron 和 NodeJS 无法将日志写入文件
- syncfusion - 如何在syncfusion React DataGrid中使用“模板”和“rowTemplate”字段?
- c# - “远程服务器返回错误:(407) 需要代理身份验证”应用程序在 C# 中命中 Rest API 时出现错误
- sql - 按表中的日期聚合表值 [SQL]
- postgresql - Postgres - 将一个元素作为数组重复 N 次
- python - 为 pandas DataFrame 中的每一行选择非空列
- java - 如何理解 Java 语言规范中的 volatile 示例?
- javascript - 如何将选定产品的行及其数量保存到 MySQL 数据库?