【问题标题】:spring cloud sleuth cannot geerate spanIDspring cloud sleuth 无法生成 spanID
【发布时间】:2019-03-13 10:07:56
【问题描述】:

有必要为所有进入控制台日志的内容生成一个 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: [/*]

application.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"); }

【问题讨论】:

    标签: spring spring-boot spring-cloud-sleuth spring-logback


    【解决方案1】:

    不必为所有进入控制台日志的内容生成 span-id。点击您的 API,然后您可以在控制台的日志中看到 span-idtrace-id

    【讨论】:

    • 然后在什么情况下生成span-id和trace-id
    • 编辑了控制台输出和文件 application.yml。并且在任何地方 span-id= 和 trace-id= 都是空的
    • 它用于跟踪进程或应用程序的入口/出口,即命中 API
    【解决方案2】:

    首先创建一个 Rest Api 并向其发出 api 请求(如果尚未完成)。 如果您使用的是 Restemplate,请尝试创建一个 RestTemplate bean。

    还将日志记录级别设置为调试

    logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-23
      • 2017-09-13
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 2022-12-12
      相关资源
      最近更新 更多