简体   繁体   中英

@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

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:

Note that the above implementations are not complete:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM