Skip to content

Commit

Permalink
don't fail spring application startup if sdk is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Feb 19, 2024
1 parent c885982 commit 17f07ca
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ private ExporterConfigEvaluator() {}
public static boolean isExporterEnabled(
Environment environment, String exportersKey, String wantExporter, boolean defaultValue) {

if (environment.getProperty("otel.sdk.disabled", Boolean.class, false)) {
return false;
}

String exporter = environment.getProperty(exportersKey);
if (exporter != null) {
return Arrays.asList(exporter.split(",")).contains(wantExporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,33 @@
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/** Configures {@link ContextPropagators} bean for propagation. */
@Configuration
@EnableConfigurationProperties(PropagationProperties.class)
@AutoConfigureBefore(OpenTelemetryAutoConfiguration.class)
@ConditionalOnProperty(prefix = "otel.propagation", name = "enabled", matchIfMissing = true)
@Conditional(PropagationAutoConfiguration.Condition.class)
public class PropagationAutoConfiguration {

static final class Condition extends AllNestedConditions {
public Condition() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}

@ConditionalOnProperty(prefix = "otel.propagation", name = "enabled", matchIfMissing = true)
static class Propagation {}

@ConditionalOnProperty(name = "otel.sdk.disabled", havingValue = "false", matchIfMissing = true)
static class SdkEnabled {}
}

private static final List<String> DEFAULT_PROPAGATORS = Arrays.asList("tracecontext", "baggage");

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.smoketest;

import io.opentelemetry.spring.smoketest.OtelSpringStarterSmokeTestApplication;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(
classes = {
OtelSpringStarterSmokeTestApplication.class,
OtelSpringStarterSmokeTest.TestConfiguration.class
},
properties = {"otel.sdk.disabled=true"})
class OtelSpringStarterDisabledSmokeTest {

@Test
void shouldStartApplication() {
// make sure we can still start the application with the disabled property
}
}

0 comments on commit 17f07ca

Please sign in to comment.