简体   繁体   中英

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.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; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [zipkin2.reporter.Sender]: Factory method 'stackdriverSender' threw exception; nested exception is java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

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

I've tried setting spring.sleuth.enabled=false but this doesn't seem to make any difference.

I actually found the answer by looking at the source for the StackdriverTraceAutoConfiguration class. The way to solve it if using GCP is to set spring.cloud.gcp.trace.enabled=false . This disables tracing for all integration points.

HowTo: Disable all tests for a Webflux Sleuth implementation with Zipkin

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:

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:

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

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