0

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 " +);

}}
Daniel Haughton
  • 1,085
  • 5
  • 20
  • 45
  • 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 Aug 12 '19 at 12:42
  • 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 Aug 12 '19 at 12:47
  • Please read the documentation of the Spring Cloud portfolio https://spring.io/projects/spring-cloud – Marcin Grzejszczak Aug 12 '19 at 12:48
  • 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 Aug 12 '19 at 13:36
  • 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 Aug 13 '19 at 09:21
  • Can you please read this document https://stackoverflow.com/help/how-to-ask and improve the questions? Also why did you pick that particular version of sleuth? There are other, more recent. Please read the documentation of the project, portfolio and how to ask proper questions and we'll be more than happy to help you. – Marcin Grzejszczak Aug 13 '19 at 09:23

1 Answers1

0

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