简体   繁体   English

traceId 和 spanId 在整个记录器中都是一样的

[英]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.

相关问题 Sleuth traceId 和 spanId 不会传播到 parallelStream 工作线程 - Sleuth traceId and spanId are not propagated to parallelStream worker threads 在 Sleuth 的日志中看不到 traceId 和 spanId - Can't see traceId and spanId in log for Sleuth 迁移到 Spring Boot 3 后 TraceId 和 SpanId 不可用 - TraceId and SpanId not available after migrating to Spring Boot 3 哪个记录 X-B3-SpanId 或 SpanId? X-B3-TraceId 还是 TraceId? (春天的侦探) - Which to log X-B3-SpanId or SpanId? X-B3-TraceId or TraceId? (Spring sleuth) Spring 云侦探 3.0.1 使用 logback 在日志中生成 traceid 和 spanid - Spring cloud sleuth 3.0.1 generate traceid & spanid in logs using logback Sleuth 不会在 Spring Boot 应用程序中打印 spanId、traceId - Sleuth doesnt print spanId,traceId in spring boot application TraceId 和 SpanId 在 WebFilter 中是 null,即使它是在 TraceWebFilter 之后注册的 - TraceId and SpanId are null in WebFilter even when it is registered after TraceWebFilter 如何获取 log4j2 中的 trace id 和 span id,格式为 [traceId, spanId ]? - How to get trace id and span id in the log4j2, in the format [traceId, spanId ]? 在使用带有新关键字的 resttemplate 进行 API 调用时,无法将 Sleuth traceid 和 spanid 传递给下游服务 - Not able to pass Sleuth traceid and spanid to downstream services while making API calls using resttemplate with new keyword 使用相同的 appender 回退多个记录器 - Logback several loggers with same appender
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM