0
votes

I have Spring cloud sleuth(and also zipkin) configured in my application. I have a controller which calls service, which in turn calls repository and finally database.

The setup works fine, Sleuth is generating span id's and It is visible in zipkin as well. I wanted to try creating span's across multiple internal beans and methods. I came across Managing Spans with Annotations. This does not seem to work.

When I use any of the annotations mentioned here like @NewSpan or @ContinueSpan, Autowiring stops working. My service class which is autowired in Controller is null. If I remove these annotations everything works again.

I am using.

spring-boot 2.2.5.RELEASE

spring-cloud.version Hoxton.SR3 I have these dependencies in my pom

<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-sleuth</artifactId> // This is pulling 2.2.2.RELEASE version
 </dependency>
 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-zipkin</artifactId>
 </dependency>

Here is a sample code

@RestController
class SomeController {

@Autowired
SomeService someService;

    @GetMapping("/init")
    @NewSpan("init")
    private void init()  {
        someService.init();
    }
}

And my Service class is like

@Service
Class SomeService {
  .....

   @ContinueSpan(log = "init")
    public void init() {

    }
}

My guess is, Spring-Aop has something to do with it. Any idea?

1
Can you provide some additional information? Which version of Sleuth are you using? How are you using the annotations? - Marcin Grzejszczak
@MarcinGrzejszczak updated the question with details - pvpkiran

1 Answers

0
votes

Please don't use field injection, use constructor injection. Also new span there doesn't make sense cause you already have a new span created by the framework.