Skip to content

Commit 9919997

Browse files
committed
don't fail spring application startup if sdk is disabled
1 parent c885982 commit 9919997

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ private ExporterConfigEvaluator() {}
1919
public static boolean isExporterEnabled(
2020
Environment environment, String exportersKey, String wantExporter, boolean defaultValue) {
2121

22+
if (environment.getProperty("otel.sdk.disabled", Boolean.class, false)) {
23+
return false;
24+
}
25+
2226
String exporter = environment.getProperty(exportersKey);
2327
if (exporter != null) {
2428
return Arrays.asList(exporter.split(",")).contains(wantExporter);

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfiguration.java

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.beans.factory.BeanFactory;
1616
import org.springframework.beans.factory.ObjectProvider;
1717
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
18+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
1819
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
1920
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2021
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -26,6 +27,7 @@
2627
@EnableConfigurationProperties(PropagationProperties.class)
2728
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class)
2829
@ConditionalOnProperty(prefix = "otel.propagation", name = "enabled", matchIfMissing = true)
30+
@ConditionalOnBean(ConfigProperties.class)
2931
public class PropagationAutoConfiguration {
3032

3133
private static final List<String> DEFAULT_PROPAGATORS = Arrays.asList("tracecontext", "baggage");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.smoketest;
7+
8+
import io.opentelemetry.spring.smoketest.OtelSpringStarterSmokeTestApplication;
9+
import org.junit.jupiter.api.Test;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
12+
@SpringBootTest(
13+
classes = {
14+
OtelSpringStarterSmokeTestApplication.class,
15+
OtelSpringStarterSmokeTest.TestConfiguration.class
16+
},
17+
properties = {"otel.sdk.disabled=true"})
18+
class OtelSpringStarterDisabledSmokeTest {
19+
20+
@Test
21+
void shouldStartApplication() {
22+
// make sure we can still start the application with the disabled property
23+
}
24+
}

0 commit comments

Comments
 (0)