diff --git a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java index c4d0d360fa4..5ae7f7d0e9d 100644 --- a/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java +++ b/sdk/all/src/main/java/io/opentelemetry/sdk/OpenTelemetrySdk.java @@ -219,10 +219,6 @@ public OpenTelemetrySdk build() { private TracerSdkProvider buildTracerProvider() { TracerProvider tracerProvider = super.tracerProvider; if (tracerProvider != null) { - if (!(tracerProvider instanceof TracerSdkProvider)) { - throw new IllegalStateException( - "The OpenTelemetrySdk can only be configured with a TracerSdkProvider"); - } return (TracerSdkProvider) tracerProvider; } TracerSdkProvider.Builder tracerProviderBuilder = TracerSdkProvider.builder(); diff --git a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java index 64473248c4f..1476683a40c 100644 --- a/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java +++ b/sdk/all/src/test/java/io/opentelemetry/sdk/OpenTelemetrySdkTest.java @@ -6,6 +6,8 @@ package io.opentelemetry.sdk; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.InstanceOfAssertFactories.type; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; @@ -37,6 +39,24 @@ class OpenTelemetrySdkTest { @Mock private ContextPropagators propagators; @Mock private Clock clock; + @Test + void testGetGlobal() { + assertThat(OpenTelemetrySdk.get()).isSameAs(OpenTelemetry.get()); + } + + @Test + void testGetTracerManagementWhenNotTracerSdk() { + OpenTelemetry previous = OpenTelemetry.get(); + assertThatCode(OpenTelemetrySdk::getGlobalTracerManagement).doesNotThrowAnyException(); + try { + OpenTelemetry.set(OpenTelemetry.builder().setTracerProvider(tracerProvider).build()); + assertThatThrownBy(OpenTelemetrySdk::getGlobalTracerManagement) + .isInstanceOf(IllegalStateException.class); + } finally { + OpenTelemetry.set(previous); + } + } + @Test void testGlobalDefault() { assertThat(((TracerSdkProvider) OpenTelemetrySdk.getGlobalTracerManagement()).get(""))