简体   繁体   English

Spring Boot 3 中的@NewSpan 和@ContinueSpan 支持

[英]@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我创建了一个演示应用程序,我想在其中查看如何在 Spring Boot 2 和 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.该演示对 Spring Boot 3 项目使用以下跟踪依赖项。

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根据 Micrometer Tracing 存储库中的迁移指南,似乎只需要将 Spring Cloud Sleuth 包名称更改为 Micrometer Tracing 名称即可: https ://github.com/micrometer-metrics/tracing/wiki/Spring -Cloud-Sleuth-3.1-迁移指南#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.但是,在 Spring Boot 3 中演示 @NewSpan 和 @ContinueSpan 注释时,我没有看到任何新的子跨度或对现有跨度的修改。 This leaves me wondering if the "old" Sleuth annotations are even supported.这让我想知道是否甚至支持“旧的”Sleuth 注释。 Because the micrometer-tracing documentation does not mention the existence of the @NewSpan and @ContinueSpan annotations: https://micrometer.io/docs/tracing .因为 micrometer-tracing 文档没有提到 @NewSpan 和 @ContinueSpan 注释的存在: 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.此外,我没有在 Spring Boot 3 文档中找到任何暗示支持“旧”注释的提示。

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但是,在千分尺跟踪存储库中存在注释: 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.所以理论上,有人可以提供一个使@NewSpan 和@ContinueSpan 注释起作用的实现。

This leaves me with the following assumptions:这给我留下了以下假设:

  • Spring Boot 3 does not officially support the old annotations Spring Boot 3 不正式支持旧注解
  • If someone wants to, they can make the old annotations work by implementing an instrumentation/AOP Aspect manually for the old annotations如果有人愿意,他们可以通过为旧注释手动实现检测/AOP 方面来使旧注释工作
  • Micrometer's observation API is the preferred approach for the future Micrometer 的观察 API 是未来的首选方法

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:我在以下存储库中搜索了@NewSpan 或@ContinueSpan 支持的任何提示:

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...)我查看了以下文档中是否提到了@NewSpan 和@ContinueSpan:(我无法在此处提供链接,因为这是一个没有声誉的新帐户......)

  • Micrometer Docs - Micrometer Tracing千分尺文档 - 千分尺追踪
  • Spring Boot 3 - Production-ready Features - Metrics Spring Boot 3 - 生产就绪特性 - 指标
  • Spring Boot 3 - Production-ready Features - Tracing Spring Boot 3 - 生产就绪特性 - 跟踪

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.第一种是复制Sleuth项目代码并修改,另一种是手动实现。

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).总的来说,我鼓励任何人使用新的@Observed注释,因为据我所知,旧注释不是 Spring Boot 3 的重点(基于 Spring Boot 3 文档中没有提及)。

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.它们都不适用于 Spring Reactive。
  • The manual implementation does not support @SpanName .手动实现不支持@SpanName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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