Search code examples
springspring-bootspring-cloud-sleuthopen-telemetry

Is there a way to annotate an entire class with @NewSpan? - Spring Boot/Sleuth


Is there a way to annotate just the class and have all the methods in the class create new spans? Basically, I am trying to get sleuth/spring to create new spans for all calls in a given repository class.

spring-boot version: '2.7.0'

Something like -

import org.springframework.cloud.sleuth.annotation.NewSpan;


@Newspan
public class ContactOperations{

  public void doSomething(){
  }

  public void doSomethingElse(){
  }
.....
}

Instead of

public class ContactOperations{


  @Newspan
  public void doSomething(){
  }

  @Newspan
  public void doSomethingElse(){
  }
.....
}

Solution

  • No this is not possible. The annotation NewSpan is only allowed on methods as you can see in the source code:

    @Retention(value=RUNTIME)
    @Inherited
    @Target(value=METHOD)
    public @interface NewSpan