Spring Cloud Sleuth - 在分布式系统中禁用采样

Spring Cloud Sleuth - disable sampling in distributed system

根据 Spring Cloud Sleuth 跨度 Sampling,我们可以控制采样率。

Samplers do not stop span (correlation) ids from being generated, but they do prevent the tags and events being attached and exported. By default you get a strategy that continues to trace if a span is already active, but new ones are always marked as non-exportable.

为了减少性能瓶颈,我们可以在运行时禁用部署实例中的 span id 生成而不重新启动应用程序吗?

在 Edgware 中,采样器 bean 使用 @RefreshScope 因此您可以在运行时更改采样百分比。但是,我不知道这是否正是您所要求的。您很可能会询问有关在运行时完全禁用 Sleuth 的问题。不幸的是,默认情况下这是不可能的。但是,您可以做的是注册一个自定义 Random bean,它可以是 @RefreshScoped 并且会在需要时生成固定 ID。