Search code examples
javaspring-cloud-sleuthzipkin

Zipkin & Sleuth, Tracer missing the createSpan method


I am following the tutorial for creating tracing application zipkin and sleuth but I am having some trouble. I cannot create a span. The problem is that the method does not exist. Also I cannot find the import for the tracer.

This is what I am trying to do:

import org.springframework.cloud.sleuth.Tracer;

@Component 
public class  Test {

  @Autowired
  Tracer tracer;

  public void test (){
     Span newSpan = tracer.createSpan("test");
     //business logic
     tracer.close(newSpan);
  }



}

Why is the implementation above not working?


Solution

  • That's an old implementation. Below I have modified your code to work:

    import brave.Tracing;
    import brave.Span;
    
    @Component 
    public class  Test {
    
      @Autowired
      Tracing tracing;
    
      public void test (){
         Span span = tracing.tracer().nextSpan().name("name");
         //business logic
         span.finish();
      }
    }
    

    For more information check this link: https://gist.github.com/marcingrzejszczak/d3c15a0c11dda71970e42c513c9c0e09