[英]traceId and spanId are coming as same throughout the loggers
Using a Spring boot with below gradle dependency to get the Sleuth's trace & span, although I am getting trace & span id's in my logs but they both are same, like even in controller & service class they are same.使用具有以下 gradle 依赖项的 Spring boot 来获取 Sleuth 的跟踪和跨度,虽然我在我的日志中获得了跟踪和跨度 ID,但它们都是相同的,就像即使在控制器和服务类中一样。
gradle.build : 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: 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"/>
Aspect class :方面类:
@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();
}
console logs :控制台日志:
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
Is there anything missing that I should add, please see that Spring boot version is fixed due to app dependency.有没有我应该添加的东西,请查看 Spring boot 版本由于应用程序依赖性而被修复。
You are missing nothing as this reflects the behavior you get by the default instrumentation by Spring Cloud Sleuth.您没有遗漏任何东西,因为这反映了您通过 Spring Cloud Sleuth 的默认检测获得的行为。 Once you open your own span within a trace, you will see that the span ID will be different:
在跟踪中打开自己的跨度后,您将看到跨度 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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.