Skip to content

Commit 727a7e3

Browse files
authored
support otel.instrumentation.common.default-enabled in spring starter (#11746)
1 parent bfeca08 commit 727a7e3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/InstrumentationPropertyEnabled.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)
2222
metadata.getAnnotationAttributes(ConditionalOnEnabledInstrumentation.class.getName());
2323

2424
String name = String.format("otel.instrumentation.%s.enabled", attributes.get("module"));
25+
Boolean explicit = context.getEnvironment().getProperty(name, Boolean.class);
26+
if (explicit != null) {
27+
return explicit;
28+
}
2529
boolean defaultValue = (boolean) attributes.get("enabledByDefault");
26-
return context.getEnvironment().getProperty(name, Boolean.class, defaultValue);
30+
if (!defaultValue) {
31+
return false;
32+
}
33+
return context
34+
.getEnvironment()
35+
.getProperty("otel.instrumentation.common.default-enabled", Boolean.class, true);
2736
}
2837
}

instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/web/SpringWebInstrumentationAutoConfigurationTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class SpringWebInstrumentationAutoConfigurationTest {
4141
void instrumentationEnabled() {
4242
contextRunner
4343
.withPropertyValues("otel.instrumentation.spring-web.enabled=true")
44+
.withPropertyValues("otel.instrumentation.common.default-enabled=false")
4445
.run(
4546
context -> {
4647
assertThat(
@@ -69,6 +70,25 @@ void instrumentationDisabled() {
6970
assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse());
7071
}
7172

73+
@Test
74+
void instrumentationDisabledButAllEnabled() {
75+
contextRunner
76+
.withPropertyValues("otel.instrumentation.spring-web.enabled=false")
77+
.withPropertyValues("otel.instrumentation.common.default-enabled=true")
78+
.run(
79+
context ->
80+
assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse());
81+
}
82+
83+
@Test
84+
void allInstrumentationDisabled() {
85+
contextRunner
86+
.withPropertyValues("otel.instrumentation.common.default-enabled=false")
87+
.run(
88+
context ->
89+
assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse());
90+
}
91+
7292
@Test
7393
void defaultConfiguration() {
7494
contextRunner.run(

0 commit comments

Comments
 (0)