Compile-Time
Compile-Time

Reputation: 73

@NewSpan and @ContinueSpan support in Spring Boot 3

I created a demo application where I wanted to see how to setup tracing in Spring Boot 2 and in Spring Boot 3: https://github.com/Compile-Time/demo-tracing-in-spring-boot-2-and-3

The demo uses the following tracing dependencies for the Spring Boot 3 project.

implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation 'io.zipkin.reporter2:zipkin-reporter-brave'

And the relevant code is this one.

import io.micrometer.tracing.annotation.NewSpan;
import io.micrometer.tracing.annotation.SpanTag;


@Service
@RequiredArgsConstructor
public class NewSpanUserCreationService {

    private final UserCreationService userCreationService;

    @Transactional
    @NewSpan("create new user and group (@NewSpan)")
    public UserGroup create(
            @SpanTag("user.creation.request") final UserCreationRequest creationRequest
    ) {
        return userCreationService.create(creationRequest);
    }

}

Based on the migration guide in the Micrometer Tracing repository, it seems like all that is necessary is to change the Spring Cloud Sleuth package names to the Micrometer Tracing ones: https://github.com/micrometer-metrics/tracing/wiki/Spring-Cloud-Sleuth-3.1-Migration-Guide#async-instrumentation

However, when demoing the @NewSpan and @ContinueSpan annotations in Spring Boot 3 I don't see any new child spans or modifications to existing spans. This leaves me wondering if the "old" Sleuth annotations are even supported. Because the micrometer-tracing documentation does not mention the existence of the @NewSpan and @ContinueSpan annotations: https://micrometer.io/docs/tracing. Additionally, I did not find any hints in the Spring Boot 3 documentation that would suggest support for the "old" annotations.

However, inside the micrometer-tracing repository the annotations are present: https://github.com/micrometer-metrics/tracing/tree/main/micrometer-tracing/src/main/java/io/micrometer/tracing/annotation

So in theory, someone can provide an implementation that makes the @NewSpan and @ContinueSpan annotations work.

This leaves me with the following assumptions:

I would be happy if anyone can confirm or deny some or all of my assumptions. It might just be possible that I missed something somewhere.

I searched the following repositories for any hint of @NewSpan or @ContinueSpan support:

I looked in the following documentations for any mentions of @NewSpan and @ContinueSpan: (I can not provide links here because this is a new account with no reputation ...)

Upvotes: 5

Views: 8952

Answers (3)

Cliffred
Cliffred

Reputation: 156

Set micrometer.observations.annotations.enabled to true, this will cause MicrometerTracingAutoConfiguration to register a SpanAspect. spring-boot-starter-aop needs to be included as a dependency.

This is mentioned in the docs: https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.observability.annotations

Upvotes: 2

daltonfury42
daltonfury42

Reputation: 3742

As per micrometer docs, they have added support for @NewSpan, @ContinueSpan and @SpanTag annotations from Micrometer Tracing 1.1.0.

Micrometer Tracing 1.1.0 is available with Springboot 3.1.0 which is under milestone release at the moment.

Upvotes: 3

Compile-Time
Compile-Time

Reputation: 73

I managed to create two solutions to get the old annotations to work. The first one copies the Sleuth project code and modifies it while the other is a manual implementation.

Overall, I encourage anyone to use the new @Observed annotation since as far as I can tell the old annotations are not a focus for Spring Boot 3 (based on the lack of mention in the Spring Boot 3 documentation).

However, if you are curious or have a good reason to re-implement the old annotations, you can take a look at these two branches on my GitHub:

Note that the above implementations are not complete:

  • Neither of them work for Spring Reactive.
  • The manual implementation does not support @SpanName.

Upvotes: 2

Related Questions