Skip to content

Commit fae7fae

Browse files
committed
add test
1 parent 377df3b commit fae7fae

File tree

2 files changed

+37
-1
lines changed
  • instrumentation/spring/spring-boot-autoconfigure/src

2 files changed

+37
-1
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/logging/LogbackAppenderInstaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static boolean isLogbackAppenderAddable(
3737
applicationEnvironmentPreparedEvent,
3838
"otel.instrumentation.logback-appender.enabled",
3939
true);
40-
return !otelSdkDisableProperty || logbackInstrumentationEnabledProperty;
40+
return !otelSdkDisableProperty && logbackInstrumentationEnabledProperty;
4141
}
4242

4343
private static void reInitializeOpenTelemetryAppender(

instrumentation/spring/spring-boot-autoconfigure/src/testLogbackAppender/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/logging/LogbackAppenderTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,40 @@ void shouldNotInitializeAppenderWhenDisabled() {
110110

111111
assertThat(testing.logRecords()).isEmpty();
112112
}
113+
114+
@Test
115+
void shouldNotInitializeAppenderWhenSdkDisabled() {
116+
Map<String, Object> properties = new HashMap<>();
117+
properties.put("logging.config", "classpath:logback-test.xml");
118+
properties.put("otel.sdk.disabled", "true");
119+
120+
SpringApplication app =
121+
new SpringApplication(
122+
TestingOpenTelemetryConfiguration.class, OpenTelemetryAppenderAutoConfiguration.class);
123+
app.setDefaultProperties(properties);
124+
ConfigurableApplicationContext context = app.run();
125+
cleanup.deferCleanup(context);
126+
127+
LoggerFactory.getLogger("test").info("test log message");
128+
129+
assertThat(testing.logRecords()).isEmpty();
130+
}
131+
132+
@Test
133+
void shouldNotInitializeAppenderWhenInstrumentationDisabled() {
134+
Map<String, Object> properties = new HashMap<>();
135+
properties.put("logging.config", "classpath:logback-test.xml");
136+
properties.put("otel.instrumentation.logback-appender.enabled", "false");
137+
138+
SpringApplication app =
139+
new SpringApplication(
140+
TestingOpenTelemetryConfiguration.class, OpenTelemetryAppenderAutoConfiguration.class);
141+
app.setDefaultProperties(properties);
142+
ConfigurableApplicationContext context = app.run();
143+
cleanup.deferCleanup(context);
144+
145+
LoggerFactory.getLogger("test").info("test log message");
146+
147+
assertThat(testing.logRecords()).isEmpty();
148+
}
113149
}

0 commit comments

Comments
 (0)