diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationPropertyEnabled.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationPropertyEnabled.java index 419c749761..87687f668b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationPropertyEnabled.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationPropertyEnabled.java @@ -22,7 +22,16 @@ public class InstrumentationPropertyEnabled implements Condition { metadata.getAnnotationAttributes(ConditionalOnEnabledInstrumentation.class.getName()); String name = String.format("otel.instrumentation.%s.enabled", attributes.get("module")); + Boolean explicit = context.getEnvironment().getProperty(name, Boolean.class); + if (explicit != null) { + return explicit; + } boolean defaultValue = (boolean) attributes.get("enabledByDefault"); - return context.getEnvironment().getProperty(name, Boolean.class, defaultValue); + if (!defaultValue) { + return false; + } + return context + .getEnvironment() + .getProperty("otel.instrumentation.common.default-enabled", Boolean.class, true); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfigurationTest.java index 5dd0b973a3..9091047c84 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfigurationTest.java @@ -41,6 +41,7 @@ class SpringWebInstrumentationAutoConfigurationTest { void instrumentationEnabled() { contextRunner .withPropertyValues("otel.instrumentation.spring-web.enabled=true") + .withPropertyValues("otel.instrumentation.common.default-enabled=false") .run( context -> { assertThat( @@ -69,6 +70,25 @@ class SpringWebInstrumentationAutoConfigurationTest { assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse()); } + @Test + void instrumentationDisabledButAllEnabled() { + contextRunner + .withPropertyValues("otel.instrumentation.spring-web.enabled=false") + .withPropertyValues("otel.instrumentation.common.default-enabled=true") + .run( + context -> + assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse()); + } + + @Test + void allInstrumentationDisabled() { + contextRunner + .withPropertyValues("otel.instrumentation.common.default-enabled=false") + .run( + context -> + assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse()); + } + @Test void defaultConfiguration() { contextRunner.run(