I have these two dependencies in my POM file:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gcp-starter-trace</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gcp-starter-logging</artifactId> </dependency>
I’d like to disable these GCP features in certain profiles. I need to test my app locally but GCP keeps getting in the way.
Advertisement
Answer
Spring depends on auto-configuration when setting up the application. In many cases, it scans the classpath for certain dependencies, and if they are present, auto-configuration is performed. Most of the times the auto-configuration can be bypassed by providing a certain conditional.
While traversing the Spring cloud gcp modules I came across the StackdriverLoggingAutoConfiguration
class (source) and StackdriverTraceAutoConfiguration
(source).
StackdriverLoggingAutoConfiguration has the conditional ConditionalOnProperty(value="spring.cloud.gcp.logging.enabled", matchIfMissing=true)
, while StackdriverTraceAutoConfiguration has the conditional @ConditionalOnProperty(value="spring.cloud.gcp.trace.enabled", matchIfMissing=true)
I’m not entirely sure if the properties are related to the auto-configuration of the modules you use, but you migh be able to disable the logging by adding the following to your application-{localprofile}.properties:
spring.cloud.gcp.logging.enabled=false spring.cloud.gcp.trace.enabled=false