0
votes

When I I print the traceId I get 514775860170850477 however in the logs the trace id is 724d9eadc6e00ad. Any idea what could be happening here?

My pom

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencyManagement> 
  <dependencies>
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-dependencies</artifactId>
          <version>Brixton.RELEASE</version>
          <type>pom</type>
          <scope>import</scope>
      </dependency>
  </dependencies>
 </dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>

How I print the traceId

     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
   import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.cloud.sleuth.Tracer;
   import org.springframework.stereotype.Service;

@Service
public class ValidationService{

private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private Tracer tracer;

public void someMethod(){

         System.out.println(tracer.getCurrentSpan().getTraceId());
    logger.info("ValidationService someMethodEntered " +);

}}
1
You're using an ancient version of Spring Cloud Sleuth. Please upgrade to the latest version and read the documentation on how to print the trace id. - Marcin Grzejszczak
Unfortunately we are on 1.5.2.RELEASE spring and cant upgrade at the minute, what is the newest Sleuth I can get with that? - Daniel Haughton
Please read the documentation of the Spring Cloud portfolio spring.io/projects/spring-cloud - Marcin Grzejszczak
So it seems like even if I use edgwar which is compatibale with spring boot 1.5x then my slueth version is 1.3.6.RELEASE. So it seems like I need to set spring.sleuth.http.legacy.enabled to true. However I dont see how I can get the current trace id using the legacy version? - Daniel Haughton
I have updated spring cloud to edgwar and sleuth is now version 1.3.0, Now I no llonger get a traceId in the logs at all? - Daniel Haughton

1 Answers

0
votes

tracer.currentSpan().context().traceIdString()