Search code examples
spring-bootmicrometer-tracing

@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:

  • Spring Boot 3 does not officially support the old annotations
  • If someone wants to, they can make the old annotations work by implementing an instrumentation/AOP Aspect manually for the old annotations
  • Micrometer's observation API is the preferred approach for the future

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 ...)

  • Micrometer Docs - Micrometer Tracing
  • Spring Boot 3 - Production-ready Features - Metrics
  • Spring Boot 3 - Production-ready Features - Tracing

Solution

  • 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.