Tests for spring-boot-autoconfigure
MODIFY
instrumentation-core/spring/spring-boot-autoconfigure/spring-boot-autoconfigure.gradle
instrumentation-core/spring/spring-boot-autoconfigure/spring-boot-autoconfigure.gradle
@@ -14,10 +14,6 @@ dependencies {
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-autoconfigure-processor', version: versions.springboot
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
- testImplementation(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.springboot) {
- exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
- }
-
implementation(project(':instrumentation-core:spring:spring-webmvc-3.1')) {
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
@@ -35,7 +31,17 @@ dependencies {
compileOnly deps.opentelemetryZipkin
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: versions.springboot
+ testImplementation(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: versions.springboot) {
+ exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
+ }
+
testImplementation deps.opentelemetrySdk
+ testImplementation group: 'io.grpc', name: 'grpc-api', version: '1.24.0'
+ testImplementation group: "io.grpc", name: "grpc-netty-shaded", version: "1.24.0"
+ testImplementation deps.opentelemetryLogging
+ testImplementation deps.opentelemetryJaeger
+ testImplementation deps.opentelemetryOtlp
+ testImplementation deps.opentelemetryZipkin
}
test {

MODIFY
instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpGrpcSpanExporterProperties.java
instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpGrpcSpanExporterProperties.java
@@ -20,7 +20,7 @@ import java.time.Duration;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
- * Configuration for {@link OTLPGrpcSpanExporter}
+ * Configuration for {@link OtlpGrpcSpanExporter}
*
* <p>Get Exporter Service Name
*

MODIFY
instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfiguration.java
instrumentation-core/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfiguration.java
@@ -43,7 +43,7 @@ public class ZipkinSpanExporterAutoConfiguration {
@Bean
@ConditionalOnMissingBean
- public ZipkinSpanExporter otelZipKinSpanExporter(
+ public ZipkinSpanExporter otelZipkinSpanExporter(
ZipkinSpanExporterProperties zipkinSpanExporterProperties) {
return ZipkinSpanExporter.newBuilder()

ADD
instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/JaegerSpanExporterAutoConfigurationTest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opentelemetry.instrumentation.spring.autoconfigure.exporters;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.opentelemetry.exporters.jaeger.JaegerGrpcSpanExporter;
+import io.opentelemetry.instrumentation.spring.autoconfigure.TracerAutoConfiguration;
+import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.jaeger.JaegerSpanExporterAutoConfiguration;
+import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.jaeger.JaegerSpanExporterProperties;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+/** Spring Boot auto configuration test for {@link JaegerGrpcSpanExporter}. */
+class JaegerSpanExporterAutoConfigurationTest {
+
+ private final ApplicationContextRunner contextRunner =
+ new ApplicationContextRunner()
+ .withConfiguration(
+ AutoConfigurations.of(
+ TracerAutoConfiguration.class, JaegerSpanExporterAutoConfiguration.class));
+
+ @Test
+ @DisplayName("when exporters are ENABLED should initialize JaegerGrpcSpanExporter bean")
+ void exportersEnabled() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporters.jaeger.enabled=true")
+ .run(
+ (context) -> {
+ assertThat(context.getBean("otelJaegerSpanExporter", JaegerGrpcSpanExporter.class))
+ .isNotNull();
+ });
+ }
+
+ @Test
+ @DisplayName(
+ "when opentelemetry.trace.exporter.jaeger properties are set should initialize JaegerSpanExporterProperties")
+ void handlesProperties() {
+ this.contextRunner
+ .withPropertyValues(
+ "opentelemetry.trace.exporter.jaeger.enabled=true",
+ "opentelemetry.trace.exporter.jaeger.servicename=test",
+ "opentelemetry.trace.exporter.jaeger.endpoint=localhost:8080/test",
+ "opentelemetry.trace.exporter.jaeger.spantimeout=420ms")
+ .run(
+ (context) -> {
+ JaegerSpanExporterProperties jaegerSpanExporterProperties =
+ context.getBean(JaegerSpanExporterProperties.class);
+ assertThat(jaegerSpanExporterProperties.getServiceName()).isEqualTo("test");
+ assertThat(jaegerSpanExporterProperties.getEndpoint())
+ .isEqualTo("localhost:8080/test");
+ assertThat(jaegerSpanExporterProperties.getSpanTimeout()).hasMillis(420);
+ });
+ }
+
+ @Test
+ @DisplayName("when exporters are DISABLED should NOT initialize JaegerGrpcSpanExporter bean")
+ void disabledProperty() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporter.jaeger.enabled=false")
+ .run(
+ (context) -> {
+ assertThat(context.containsBean("otelJaegerSpanExporter")).isFalse();
+ });
+ }
+
+ @Test
+ @DisplayName(
+ "when jaeger enabled property is MISSING should initialize JaegerGrpcSpanExporter bean")
+ void noProperty() {
+ this.contextRunner.run(
+ (context) -> {
+ assertThat(context.getBean("otelJaegerSpanExporter", JaegerGrpcSpanExporter.class))
+ .isNotNull();
+ });
+ }
+}

ADD
instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/LoggingSpanExporterAutoConfigurationTest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opentelemetry.instrumentation.spring.autoconfigure.exporters;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.opentelemetry.exporters.logging.LoggingSpanExporter;
+import io.opentelemetry.instrumentation.spring.autoconfigure.TracerAutoConfiguration;
+import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.logging.LoggingSpanExporterAutoConfiguration;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+/** Spring Boot auto configuration test for {@link LoggingSpanExporter}. */
+class LoggingSpanExporterAutoConfigurationTest {
+
+ private final ApplicationContextRunner contextRunner =
+ new ApplicationContextRunner()
+ .withConfiguration(
+ AutoConfigurations.of(
+ TracerAutoConfiguration.class, LoggingSpanExporterAutoConfiguration.class));
+
+ @Test
+ @DisplayName("when exporters are ENABLED should initialize LoggingSpanExporter bean")
+ void exportersEnabled() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporters.logging.enabled=true")
+ .run(
+ (context) -> {
+ assertThat(context.getBean("otelLoggingSpanExporter", LoggingSpanExporter.class))
+ .isNotNull();
+ });
+ }
+
+ @Test
+ @DisplayName("when exporters are DISABLED should NOT initialize LoggingSpanExporter bean")
+ void disabledProperty() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporter.logging.enabled=false")
+ .run(
+ (context) -> {
+ assertThat(context.containsBean("otelLoggingSpanExporter")).isFalse();
+ });
+ }
+
+ @Test
+ @DisplayName(
+ "when exporter enabled property is MISSING should initialize LoggingSpanExporter bean")
+ void noProperty() {
+ this.contextRunner.run(
+ (context) -> {
+ assertThat(context.getBean("otelLoggingSpanExporter", LoggingSpanExporter.class))
+ .isNotNull();
+ });
+ }
+}

ADD
instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/OtlpGrpcSpanExporterAutoConfigurationTest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opentelemetry.instrumentation.spring.autoconfigure.exporters;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.opentelemetry.exporters.otlp.OtlpGrpcSpanExporter;
+import io.opentelemetry.instrumentation.spring.autoconfigure.TracerAutoConfiguration;
+import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpGrpcSpanExporterAutoConfiguration;
+import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.OtlpGrpcSpanExporterProperties;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+/** Spring Boot auto configuration test for {@link OtlpGrpcSpanExporterAutoConfiguration}. */
+class OtlpGrpcSpanExporterAutoConfigurationTest {
+
+ private final ApplicationContextRunner contextRunner =
+ new ApplicationContextRunner()
+ .withConfiguration(
+ AutoConfigurations.of(
+ TracerAutoConfiguration.class, OtlpGrpcSpanExporterAutoConfiguration.class));
+
+ @Test
+ @DisplayName("when exporters are ENABLED should initialize OtlpGrpcSpanExporter bean")
+ void exportersEnabled() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporters.otlp.enabled=true")
+ .run(
+ (context) -> {
+ assertThat(context.getBean("otelOtlpGrpcSpanExporter", OtlpGrpcSpanExporter.class))
+ .isNotNull();
+ });
+ }
+
+ @Test
+ @DisplayName(
+ "when opentelemetry.trace.exporter.otlp properties are set should initialize OtlpGrpcSpanExporterProperties")
+ void handlesProperties() {
+ this.contextRunner
+ .withPropertyValues(
+ "opentelemetry.trace.exporter.otlp.enabled=true",
+ "opentelemetry.trace.exporter.otlp.servicename=test",
+ "opentelemetry.trace.exporter.otlp.endpoint=localhost:8080/test",
+ "opentelemetry.trace.exporter.otlp.spantimeout=69ms")
+ .run(
+ (context) -> {
+ OtlpGrpcSpanExporterProperties otlpSpanExporterProperties =
+ context.getBean(OtlpGrpcSpanExporterProperties.class);
+ assertThat(otlpSpanExporterProperties.getServiceName()).isEqualTo("test");
+ assertThat(otlpSpanExporterProperties.getEndpoint()).isEqualTo("localhost:8080/test");
+ assertThat(otlpSpanExporterProperties.getSpanTimeout()).hasMillis(69);
+ });
+ }
+
+ @Test
+ @DisplayName("when exporters are DISABLED should NOT initialize OtlpGrpcSpanExporter bean")
+ void disabledProperty() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporter.otlp.enabled=false")
+ .run(
+ (context) -> {
+ assertThat(context.containsBean("otelOtlpGrpcSpanExporter")).isFalse();
+ });
+ }
+
+ @Test
+ @DisplayName("when otlp enabled property is MISSING should initialize OtlpGrpcSpanExporter bean")
+ void noProperty() {
+ this.contextRunner.run(
+ (context) -> {
+ assertThat(context.getBean("otelOtlpGrpcSpanExporter", OtlpGrpcSpanExporter.class))
+ .isNotNull();
+ });
+ }
+}

ADD
instrumentation-core/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/ZipkinSpanExporterAutoConfigurationTest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.opentelemetry.instrumentation.spring.autoconfigure.exporters;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.opentelemetry.exporters.zipkin.ZipkinSpanExporter;
+import io.opentelemetry.instrumentation.spring.autoconfigure.TracerAutoConfiguration;
+import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.zipkin.ZipkinSpanExporterAutoConfiguration;
+import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.zipkin.ZipkinSpanExporterProperties;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+/** Spring Boot auto configuration test for {@link ZipkinSpanExporter}. */
+class ZipkinSpanExporterAutoConfigurationTest {
+
+ private final ApplicationContextRunner contextRunner =
+ new ApplicationContextRunner()
+ .withConfiguration(
+ AutoConfigurations.of(
+ TracerAutoConfiguration.class, ZipkinSpanExporterAutoConfiguration.class));
+
+ @Test
+ @DisplayName("when exporters are ENABLED should initialize ZipkinSpanExporter bean")
+ void exportersEnabled() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporters.zipkin.enabled=true")
+ .run(
+ (context) -> {
+ assertThat(context.getBean("otelZipkinSpanExporter", ZipkinSpanExporter.class))
+ .isNotNull();
+ });
+ }
+
+ @Test
+ @DisplayName(
+ "when opentelemetry.trace.exporter.zipkin properties are set should initialize ZipkinSpanExporterProperties with property values")
+ void handlesProperties() {
+ this.contextRunner
+ .withPropertyValues(
+ "opentelemetry.trace.exporter.zipkin.enabled=true",
+ "opentelemetry.trace.exporter.zipkin.servicename=test",
+ "opentelemetry.trace.exporter.zipkin.endpoint=http://localhost:8080/test")
+ .run(
+ (context) -> {
+ ZipkinSpanExporterProperties zipkinSpanExporterProperties =
+ context.getBean(ZipkinSpanExporterProperties.class);
+ assertThat(zipkinSpanExporterProperties.getServiceName()).isEqualTo("test");
+ assertThat(zipkinSpanExporterProperties.getEndpoint())
+ .isEqualTo("http://localhost:8080/test");
+ });
+ }
+
+ @Test
+ @DisplayName("when exporters are DISABLED should NOT initialize ZipkinSpanExporter bean")
+ void disabledProperty() {
+ this.contextRunner
+ .withPropertyValues("opentelemetry.trace.exporter.zipkin.enabled=false")
+ .run(
+ (context) -> {
+ assertThat(context.containsBean("otelZipkinSpanExporter")).isFalse();
+ });
+ }
+
+ @Test
+ @DisplayName("when zipkin enabled property is MISSING should initialize ZipkinSpanExporter bean")
+ void noProperty() {
+ this.contextRunner.run(
+ (context) -> {
+ assertThat(context.getBean("otelZipkinSpanExporter", ZipkinSpanExporter.class))
+ .isNotNull();
+ });
+ }
+}

Tests for spring-boot-autoconfigure (#825)