support otel.instrumentation.common.default-enabled in spring starter (#11746)
This commit is contained in:
parent
bfeca08188
commit
727a7e3548
|
@ -22,7 +22,16 @@ public class InstrumentationPropertyEnabled implements Condition {
|
||||||
metadata.getAnnotationAttributes(ConditionalOnEnabledInstrumentation.class.getName());
|
metadata.getAnnotationAttributes(ConditionalOnEnabledInstrumentation.class.getName());
|
||||||
|
|
||||||
String name = String.format("otel.instrumentation.%s.enabled", attributes.get("module"));
|
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");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ class SpringWebInstrumentationAutoConfigurationTest {
|
||||||
void instrumentationEnabled() {
|
void instrumentationEnabled() {
|
||||||
contextRunner
|
contextRunner
|
||||||
.withPropertyValues("otel.instrumentation.spring-web.enabled=true")
|
.withPropertyValues("otel.instrumentation.spring-web.enabled=true")
|
||||||
|
.withPropertyValues("otel.instrumentation.common.default-enabled=false")
|
||||||
.run(
|
.run(
|
||||||
context -> {
|
context -> {
|
||||||
assertThat(
|
assertThat(
|
||||||
|
@ -69,6 +70,25 @@ class SpringWebInstrumentationAutoConfigurationTest {
|
||||||
assertThat(context.containsBean("otelRestTemplateBeanPostProcessor")).isFalse());
|
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
|
@Test
|
||||||
void defaultConfiguration() {
|
void defaultConfiguration() {
|
||||||
contextRunner.run(
|
contextRunner.run(
|
||||||
|
|
Loading…
Reference in New Issue