简体   繁体   English

运行集成测试时禁用 Spring Cloud Sleuth?

[英]Disable Spring Cloud Sleuth when running Integration Tests?

When using org.springframework.cloud:spring-cloud-gcp-starter-trace:1.0.0.RELEASE and running my integration tests locally I get this error message:当使用org.springframework.cloud:spring-cloud-gcp-starter-trace:1.0.0.RELEASE并在本地运行我的集成测试时,我收到此错误消息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stackdriverSender' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/trace/StackdriverTraceAutoConfiguration.class]: Bean instantiation via factory method failed; org.springframework.beans.factory.BeanCreationException:在 class 路径资源 [org/springframework/cloud/gcp/autoconfigure/trace/StackdriverTraceAutoConfiguration.class] 中定义名称为“stackdriverSender”的 bean 创建时出错:通过工厂方法的 Bean 实例化失败; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [zipkin2.reporter.Sender]: Factory method 'stackdriverSender' threw exception;嵌套的异常是 org.springframework.beans.BeanInstantiationException: Failed to instantiate [zipkin2.reporter.Sender]: Factory method 'stackdriverSender' throw exception; nested exception is java.io.IOException: The Application Default Credentials are not available.嵌套异常是 java.io.IOException:应用程序默认凭据不可用。 They are available if running in Google Compute Engine.如果在 Google Compute Engine 中运行,它们就可用。 Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.否则,环境变量 GOOGLE_APPLICATION_CREDENTIALS 必须定义为指向定义凭据的文件。 See https://developers.google.com/accounts/docs/application-default-credentials for more information.有关详细信息,请参阅https://developers.google.com/accounts/docs/application-default-credentials

This is totally understandable since this environment variable is not present locally and I don't want to use Sleuth/Stackdriver tracing when running the tests.这是完全可以理解的,因为这个环境变量在本地不存在,而且我不想在运行测试时使用 Sleuth/Stackdriver 跟踪。 I've looked in the reference documentation but I can only seem to find information on how to disable Sleuth for specific integration points such as RxJava, RestTemplate etc. But how can I disable Sleuth entirely?我查看了参考文档,但似乎只能找到有关如何为特定集成点(例如 RxJava、RestTemplate 等)禁用 Sleuth 的信息。但是如何才能完全禁用 Sleuth?

I've tried setting spring.sleuth.enabled=false but this doesn't seem to make any difference.我试过设置spring.sleuth.enabled=false但这似乎没有任何区别。

I actually found the answer by looking at the source for the StackdriverTraceAutoConfiguration class.我实际上是通过查看StackdriverTraceAutoConfiguration类的源代码找到了答案。 The way to solve it if using GCP is to set spring.cloud.gcp.trace.enabled=false .如果使用 GCP 解决它的方法是设置spring.cloud.gcp.trace.enabled=false This disables tracing for all integration points.这将禁用对所有集成点的跟踪。

HowTo: Disable all tests for a Webflux Sleuth implementation with Zipkin方法:使用 Zipkin 禁用 Webflux Sleuth 实施的所有测试

If, you have these dependencies:如果,你有这些依赖:

implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
implementation 'org.springframework.cloud:spring-cloud-sleuth-zipkin'

Then, fully disable Sleuth/Zipkin for your integration tests by adding an application.yml to your test/resources folder with:然后,通过将 application.yml 添加到您的 test/resources 文件夹中,完全禁用 Sleuth/Zipkin 以进行集成测试:

spring:
  sleuth: # All sleuth features disabled for integration tests
    enabled: false
    reactor:
      enabled: false
    web:
      enabled: false
    async:
      enabled: false
      client:
        template:
          enabled: false
  zipkin: # All zipkin features disabled for integration tests
    enabled: false

You can disable tracing, logging and set a fake project id as follow:您可以禁用跟踪、日志记录并设置一个虚假的项目 ID,如下所示:

spring.cloud.gcp.project-id=fake-project-id
spring.cloud.gcp.logging.enabled=false
spring.cloud.gcp.trace.enabled=false

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

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