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
  • You shouldn't need those annotation afaik, as the instrumentation is now baked into Spring Framework and Spring Boot. So there is no need to do external instrumentation. – M. Deinum Dec 12 '22 at 12:43
  • Yes, for pure instrumentation I don't need the annotations. However, the focus of my question is more on the annotations themself than on instrumentation. In Spring Boot 2 you could still use `@NewSpan` and `@ContinueSpan` additionally to the spans created by Sleuth's instrumentation (which are now in Spring Boot 3). In Spring Boot 3 I am not able to create a new child span of an instrumented span with `@NewSpan` and I can not find any documentation that tells me that `@NewSpan` and `@ContinueSpan` in micrometer-tracing are not supported by Spring Boot 3. – Compile-Time Dec 12 '22 at 14:56
  • That was my bad, as I didn't check your code (I would suggest adding that to your question instead of having people go through your repository). According to the documentation the Spring Cloud Sleuth instrumentation will be moved to micrometer. I suspect not everything has been moved yet. However you should be able to get the Aspect from Sleuth 3.1 slightly modify it so it will be used. At least for now. – M. Deinum Dec 13 '22 at 07:16
  • 1
    Okay, so far that would be my conclusion as well. I added a code snippet based on your suggestion. I guess I will leave this question open until there is definite answer somewhere in the Spring/Micrometer documentation or I figured out how to manually create the aspect (or if someone else wants to try, feel free to do so). – Compile-Time Dec 13 '22 at 08:22

2 Answers2

1

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

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.

daltonfury42
  • 3,103
  • 2
  • 30
  • 47
  • Thats right, you can either directly read through the Micrometer docs to implement it or follow this [blog](https://medium.com/@amithkumarg/micrometer-tracing-in-spring-boot-context-propagation-for-async-scheduled-newspan-b80f4f4b2c9f) which guides you with the minimum setup required to enable these Micrometer annotations. – Amith Kumar Jun 12 '23 at 20:39