traceId和spanId在整个记录器中都是相同的



使用具有低于gradle依赖项的Spring引导来获取Sleuth的跟踪&span,尽管我得到了trace&span id在我的日志中,但它们都是相同的,甚至在controller&服务等级他们是一样的。

gradle.build:

compile('org.springframework.boot:spring-boot-starter:2.1.4.RELEASE')
compile 'org.springframework.cloud:spring-cloud-starter-sleuth:2.1.4.RELEASE'

logback.xml:

<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level  trace=%X{X-B3-TraceId} span=%X{X-B3-SpanId} MSG=%m%n"/>

方面类别:

@Around("execution(*  com.test.common.controller.*.*(..))")
public Object controllerAspect(ProceedingJoinPoint joinPoint) throws Throwable {
Long startTime = System.currentTimeMillis();
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes == null) {
return joinPoint.proceed();
}
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
myLoggingServices(joinPoint, requestAttributes, httpServletRequest, startTime);
return joinPoint.proceed();
}

控制台日志:

2021-07-16 13:41:56.008 [qtp1043203786-34] INFO   trace=474376a508632a04 span=474376a508632a04 qualifiedClass=com.test.common.controller.MyController time=14
2021-07-16 13:41:56.009 [qtp1043203786-34] INFO   trace=474376a508632a04 span=474376a508632a04 qualifiedClass=com.test.common.controller.MyController time=1
2021-07-16 13:41:56.291 [qtp1043203786-34] INFO   trace=474376a508632a04 span=474376a508632a04 qualifiedClass=com.test.common.service.impl.MyServiceImpl time=0
2021-07-16 13:41:56.292 [qtp1043203786-34] INFO   trace=474376a508632a04 span=474376a508632a04 qualifiedClass=com.test.common.service.impl.MyServiceImpl time=0

我应该补充什么吗?请注意,由于应用程序依赖性,Spring启动版本已修复。

您没有遗漏任何内容,因为这反映了您通过Spring Cloud Sleuth的默认检测所获得的行为。一旦您在跟踪中打开自己的跨度,您将看到跨度ID将有所不同:

@Autowired
private Tracer tracer;
[...]
Span span = this.tracer.nextSpan().name("customSpan");
try (Tracer.SpanInScope ws = this.tracer.withSpan(span.start())) {
[...]
log.info("Should log custom span");
[...]
}
finally {
span.end();
}

相关内容

  • 没有找到相关文章

最新更新