Skip to content

Commit

Permalink
support otel.instrumentation.common.default-enabled in spring starter (
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Jul 8, 2024
1 parent bfeca08 commit 727a7e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata)
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -69,6 +70,25 @@ void instrumentationDisabled() {
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(
Expand Down

0 comments on commit 727a7e3

Please sign in to comment.