Home > OS >  How to force the duo Spring cloud sleuth - Spring MVC/Spring Rest to handle @SpanTag annotation set
How to force the duo Spring cloud sleuth - Spring MVC/Spring Rest to handle @SpanTag annotation set

Time:11-23

I got a Spring boot application set with Spring REST and Spring cloud sleuth. I am trying to set a custom tag based on the controller's methods' parameters with the @SpanTag annotation, but no luck

Here is an example controller :

@RestController
@RequestMapping("/api/auth")
class ExampleController() {

    @PostMapping("/create")
    fun createToken(
            @SpanTag(key="username",expression = "username") 
            @RequestBody 
            authTokenRequest: Request){
//Some code here
    }
}

Got a zipkin running on the side for retrieving trace and span.

When I launch a request on /api/auth/create, I can see the Trace popping in the zipkin instance. If I has subspan, they show as well. The default tag are also visible on the root span (http.path, mvc.controller.class, etc.) but no tag named username.

So my question, is there a way to force Spring Cloud Sleuth (in this configuration) to acknowledge the @SpanTag annotation ?

CodePudding user response:

In documentation, @SpanTag is only used in combination with a method, annotated @NewSpan or @ContinueSpan. (It would be nice to write it somewhere explicitly, but implicitly it makes no other sense;)

Please try:

@ContinueSpan(log = "createToken") //or a log of your choice
@PostMapping("/create")
fun createToken(@SpanTag ...
  • Related