From 33a2c41a0c0d452074f04a08a89fbe50c6c07600 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 6 Feb 2024 11:56:28 +0100 Subject: [PATCH] remove all spring starter features where a standard property can be used --- .../build.gradle.kts | 2 +- .../OpenTelemetryAutoConfiguration.java | 9 ++- .../internal/ExporterConfigEvaluator.java | 18 +---- ...oggingMetricExporterAutoConfiguration.java | 7 +- .../LoggingSpanExporterAutoConfiguration.java | 7 +- ...OutLogRecordExporterAutoConfiguration.java | 7 +- ...tlpLogRecordExporterAutoConfiguration.java | 7 +- .../OtlpMetricExporterAutoConfiguration.java | 7 +- .../OtlpSpanExporterAutoConfiguration.java | 7 +- .../ZipkinSpanExporterAutoConfiguration.java | 7 +- .../CompositeTextMapPropagatorFactory.java | 1 - .../DeprecatedPropagationProperties.java | 26 ------- .../PropagationAutoConfiguration.java | 12 ++-- .../OtelResourceAutoConfiguration.java | 14 ++-- .../OtelSpringResourceProperties.java | 23 ------ .../resources/SpringConfigProperties.java | 6 ++ .../resources/SpringResourceProvider.java | 16 ----- .../OpenTelemetryAutoConfigurationTest.java | 8 +-- .../MetricExporterAutoConfigurationTest.java | 2 +- .../SpanExporterAutoConfigurationTest.java | 2 +- ...ngMetricExporterAutoConfigurationTest.java | 37 ++-------- ...gingSpanExporterAutoConfigurationTest.java | 52 +++----------- ...ogRecordExporterAutoConfigurationTest.java | 60 +++------------- .../otlp/OtlpExporterPropertiesTest.java | 2 + .../OtlpLogExporterAutoConfigurationTest.java | 35 ---------- ...lpMetricExporterAutoConfigurationTest.java | 35 ---------- ...OtlpSpanExporterAutoConfigurationTest.java | 35 +--------- ...pkinSpanExporterAutoConfigurationTest.java | 12 +--- .../PropagationAutoConfigurationTest.java | 11 ++- .../PropagationPropertiesTest.java | 50 ------------- .../OtelResourceAutoConfigurationTest.java | 6 +- .../resources/OtelResourcePropertiesTest.java | 70 ------------------- .../resources/SpringConfigPropertiesTest.java | 1 + .../resources/SpringResourceProviderTest.java | 57 +++++++++++++++ .../smoketest/OtelSpringStarterSmokeTest.java | 3 +- 35 files changed, 139 insertions(+), 515 deletions(-) delete mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/DeprecatedPropagationProperties.java delete mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelSpringResourceProperties.java delete mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java delete mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java create mode 100644 instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProviderTest.java diff --git a/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts b/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts index 642075518c24..eede37e60510 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts +++ b/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts @@ -37,7 +37,7 @@ dependencies { library("org.springframework.boot:spring-boot-starter-web:$springBootVersion") library("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion") - compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi") + implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") compileOnly("io.opentelemetry:opentelemetry-extension-annotations") compileOnly("io.opentelemetry:opentelemetry-extension-trace-propagators") compileOnly("io.opentelemetry.contrib:opentelemetry-aws-xray-propagator") diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java index a0e84875ae0d..a5745ce83450 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java @@ -15,6 +15,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.internal.MapConverter; import io.opentelemetry.instrumentation.spring.autoconfigure.propagators.PropagationProperties; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration; +import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceProperties; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringConfigProperties; import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; @@ -61,6 +62,7 @@ @EnableConfigurationProperties({ SamplerProperties.class, OtlpExporterProperties.class, + OtelResourceProperties.class, PropagationProperties.class }) public class OpenTelemetryAutoConfiguration { @@ -103,9 +105,14 @@ static class Metric {} ConfigProperties configProperties( Environment env, OtlpExporterProperties otlpExporterProperties, + OtelResourceProperties resourceProperties, PropagationProperties propagationProperties) { return new SpringConfigProperties( - env, new SpelExpressionParser(), otlpExporterProperties, propagationProperties); + env, + new SpelExpressionParser(), + otlpExporterProperties, + resourceProperties, + propagationProperties); } @Bean(destroyMethod = "") // SDK components are shutdown from the OpenTelemetry instance diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/internal/ExporterConfigEvaluator.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/internal/ExporterConfigEvaluator.java index 51cf5ec75aae..afffc5a70806 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/internal/ExporterConfigEvaluator.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/internal/ExporterConfigEvaluator.java @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.internal; import java.util.Arrays; -import javax.annotation.Nullable; import org.springframework.core.env.Environment; /** @@ -18,28 +17,13 @@ public final class ExporterConfigEvaluator { private ExporterConfigEvaluator() {} public static boolean isExporterEnabled( - Environment environment, - @Nullable String oldAllKey, - String oldKey, - String exportersKey, - String wantExporter, - boolean defaultValue) { + Environment environment, String exportersKey, String wantExporter, boolean defaultValue) { String exporter = environment.getProperty(exportersKey); if (exporter != null) { return Arrays.asList(exporter.split(",")).contains(wantExporter); } - String old = environment.getProperty(oldKey); - if (old != null) { - return "true".equals(old); - } - if (oldAllKey != null) { - String oldAll = environment.getProperty(oldAllKey); - if (oldAll != null) { - return "true".equals(oldAll); - } - } return defaultValue; } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfiguration.java index 968bff6e5347..b8f5550c755d 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfiguration.java @@ -35,12 +35,7 @@ static final class CustomCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return ExporterConfigEvaluator.isExporterEnabled( - context.getEnvironment(), - "otel.exporter.logging.enabled", - "otel.exporter.logging.metrics.enabled", - "otel.metrics.exporter", - "logging", - false); + context.getEnvironment(), "otel.metrics.exporter", "logging", false); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfiguration.java index a31ee6ce78c9..bf34540a986e 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfiguration.java @@ -35,12 +35,7 @@ static final class CustomCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return ExporterConfigEvaluator.isExporterEnabled( - context.getEnvironment(), - "otel.exporter.logging.enabled", - "otel.exporter.logging.traces.enabled", - "otel.traces.exporter", - "logging", - false); + context.getEnvironment(), "otel.traces.exporter", "logging", false); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfiguration.java index 18ad43096076..2f213374c144 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfiguration.java @@ -35,12 +35,7 @@ static final class CustomCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return ExporterConfigEvaluator.isExporterEnabled( - context.getEnvironment(), - "otel.exporter.logging.enabled", - "otel.exporter.logging.logs.enabled", - "otel.logs.exporter", - "logging", - false); + context.getEnvironment(), "otel.logs.exporter", "logging", false); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogRecordExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogRecordExporterAutoConfiguration.java index f3a0c1a2695d..44de7993df3b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogRecordExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogRecordExporterAutoConfiguration.java @@ -36,12 +36,7 @@ static final class CustomCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return ExporterConfigEvaluator.isExporterEnabled( - context.getEnvironment(), - "otel.exporter.otlp.enabled", - "otel.exporter.otlp.logs.enabled", - "otel.logs.exporter", - "otlp", - true); + context.getEnvironment(), "otel.logs.exporter", "otlp", true); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfiguration.java index 3abfd071113c..8a558f696168 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfiguration.java @@ -38,12 +38,7 @@ static final class CustomCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return ExporterConfigEvaluator.isExporterEnabled( - context.getEnvironment(), - "otel.exporter.otlp.enabled", - "otel.exporter.otlp.metrics.enabled", - "otel.metrics.exporter", - "otlp", - true); + context.getEnvironment(), "otel.metrics.exporter", "otlp", true); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfiguration.java index 18c5e6f5702c..bd59378384eb 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfiguration.java @@ -43,12 +43,7 @@ static final class CustomCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return ExporterConfigEvaluator.isExporterEnabled( - context.getEnvironment(), - "otel.exporter.otlp.enabled", - "otel.exporter.otlp.traces.enabled", - "otel.traces.exporter", - "otlp", - true); + context.getEnvironment(), "otel.traces.exporter", "otlp", true); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfiguration.java index 7f9355b96e63..b0dc29ad689e 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfiguration.java @@ -47,12 +47,7 @@ static final class CustomCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return ExporterConfigEvaluator.isExporterEnabled( - context.getEnvironment(), - null, - "otel.exporter.zipkin.enabled", - "otel.traces.exporter", - "zipkin", - true); + context.getEnvironment(), "otel.traces.exporter", "zipkin", true); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/CompositeTextMapPropagatorFactory.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/CompositeTextMapPropagatorFactory.java index 634bfe29da25..38c9f7ac3f3c 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/CompositeTextMapPropagatorFactory.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/CompositeTextMapPropagatorFactory.java @@ -26,7 +26,6 @@ public final class CompositeTextMapPropagatorFactory { private static final Logger logger = Logger.getLogger(CompositeTextMapPropagatorFactory.class.getName()); - @SuppressWarnings("deprecation") // deprecated class to be updated once published in new location static TextMapPropagator getCompositeTextMapPropagator( BeanFactory beanFactory, List types) { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/DeprecatedPropagationProperties.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/DeprecatedPropagationProperties.java deleted file mode 100644 index 0645e1d5a336..000000000000 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/DeprecatedPropagationProperties.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.autoconfigure.propagators; - -import java.util.Arrays; -import java.util.List; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** Configuration for propagators. */ -@ConfigurationProperties(prefix = "otel.propagation") -@Deprecated // use otel.propagators instead -public final class DeprecatedPropagationProperties { - - private List type = Arrays.asList("tracecontext", "baggage"); - - public List getType() { - return type; - } - - public void setType(List type) { - this.type = type; - } -} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfiguration.java index 42a59349343e..6523ad695594 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfiguration.java @@ -9,6 +9,7 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import java.util.Arrays; import java.util.Collections; import java.util.List; import org.springframework.beans.factory.BeanFactory; @@ -22,12 +23,13 @@ /** Configures {@link ContextPropagators} bean for propagation. */ @Configuration -@EnableConfigurationProperties(DeprecatedPropagationProperties.class) +@EnableConfigurationProperties(PropagationProperties.class) @AutoConfigureBefore(OpenTelemetryAutoConfiguration.class) @ConditionalOnProperty(prefix = "otel.propagation", name = "enabled", matchIfMissing = true) -@SuppressWarnings("deprecation") public class PropagationAutoConfiguration { + private static final List DEFAULT_PROPAGATORS = Arrays.asList("tracecontext", "baggage"); + @Bean @ConditionalOnMissingBean ContextPropagators contextPropagators(ObjectProvider> propagators) { @@ -43,11 +45,9 @@ static class PropagatorsConfiguration { @Bean TextMapPropagator compositeTextMapPropagator( - BeanFactory beanFactory, - DeprecatedPropagationProperties properties, - ConfigProperties configProperties) { + BeanFactory beanFactory, ConfigProperties configProperties) { return CompositeTextMapPropagatorFactory.getCompositeTextMapPropagator( - beanFactory, configProperties.getList("otel.propagators", properties.getType())); + beanFactory, configProperties.getList("otel.propagators", DEFAULT_PROPAGATORS)); } } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java index d9abc775b12e..41aab9620db8 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java @@ -16,6 +16,7 @@ import io.opentelemetry.instrumentation.resources.ProcessRuntimeResource; import io.opentelemetry.instrumentation.resources.ProcessRuntimeResourceProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -25,16 +26,19 @@ import org.springframework.context.annotation.Configuration; @Configuration -@EnableConfigurationProperties({OtelSpringResourceProperties.class, OtelResourceProperties.class}) +@EnableConfigurationProperties({OtelResourceProperties.class}) @AutoConfigureBefore(OpenTelemetryAutoConfiguration.class) @ConditionalOnProperty(prefix = "otel.springboot.resource", name = "enabled", matchIfMissing = true) public class OtelResourceAutoConfiguration { @Bean - public ResourceProvider otelResourceProvider( - OtelSpringResourceProperties otelSpringResourceProperties, - OtelResourceProperties otelResourceProperties) { - return new SpringResourceProvider(otelSpringResourceProperties, otelResourceProperties); + public ResourceProvider otelEnvironmentResourceProvider() { + return new EnvironmentResourceProvider(); + } + + @Bean + public ResourceProvider otelSpringResourceProvider() { + return new SpringResourceProvider(); } @Bean diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelSpringResourceProperties.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelSpringResourceProperties.java deleted file mode 100644 index 6c01e6e5ce0a..000000000000 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelSpringResourceProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.autoconfigure.resources; - -import java.util.Collections; -import java.util.Map; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@ConfigurationProperties(prefix = "otel.springboot.resource") -public class OtelSpringResourceProperties { - private Map attributes = Collections.emptyMap(); - - public Map getAttributes() { - return attributes; - } - - public void setAttributes(Map attributes) { - this.attributes = attributes; - } -} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigProperties.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigProperties.java index 42a137f892fe..75b3a487a357 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigProperties.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigProperties.java @@ -23,16 +23,19 @@ public class SpringConfigProperties implements ConfigProperties { private final ExpressionParser parser; private final OtlpExporterProperties otlpExporterProperties; + private final OtelResourceProperties resourceProperties; private final PropagationProperties propagationProperties; public SpringConfigProperties( Environment environment, ExpressionParser parser, OtlpExporterProperties otlpExporterProperties, + OtelResourceProperties resourceProperties, PropagationProperties propagationProperties) { this.environment = environment; this.parser = parser; this.otlpExporterProperties = otlpExporterProperties; + this.resourceProperties = resourceProperties; this.propagationProperties = propagationProperties; } @@ -78,6 +81,7 @@ public List getList(String name) { if (name.equals("otel.propagators")) { return propagationProperties.getPropagators(); } + List value = environment.getProperty(name, List.class); return value == null ? Collections.emptyList() : value; } @@ -98,6 +102,8 @@ public Duration getDuration(String name) { public Map getMap(String name) { // maps from config properties are not supported by Environment, so we have to fake it switch (name) { + case "otel.resource.attributes": + return resourceProperties.getAttributes(); case "otel.exporter.otlp.headers": return otlpExporterProperties.getHeaders(); case "otel.exporter.otlp.logs.headers": diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProvider.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProvider.java index 86f8c7b83728..756d227f818e 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProvider.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProvider.java @@ -14,16 +14,6 @@ public class SpringResourceProvider implements ResourceProvider { - private final OtelSpringResourceProperties otelSpringResourceProperties; - private final OtelResourceProperties otelResourceProperties; - - public SpringResourceProvider( - OtelSpringResourceProperties otelSpringResourceProperties, - OtelResourceProperties otelResourceProperties) { - this.otelSpringResourceProperties = otelSpringResourceProperties; - this.otelResourceProperties = otelResourceProperties; - } - @Override public Resource createResource(ConfigProperties configProperties) { AttributesBuilder attributesBuilder = Attributes.builder(); @@ -31,12 +21,6 @@ public Resource createResource(ConfigProperties configProperties) { if (springApplicationName != null) { attributesBuilder.put(ResourceAttributes.SERVICE_NAME, springApplicationName); } - otelSpringResourceProperties.getAttributes().forEach(attributesBuilder::put); - otelResourceProperties.getAttributes().forEach(attributesBuilder::put); - String applicationName = configProperties.getString("otel.service.name"); - if (applicationName != null) { - attributesBuilder.put(ResourceAttributes.SERVICE_NAME, applicationName); - } return Resource.create(attributesBuilder.build()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java index 690300485a4f..e0bf3f98f849 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfigurationTest.java @@ -140,7 +140,7 @@ void shouldDetermineServiceNameByOtelServiceName() { .withConfiguration( AutoConfigurations.of( OtelResourceAutoConfiguration.class, OpenTelemetryAutoConfiguration.class)) - .withPropertyValues("otel.springboot.resource.attributes.service.name=otel-name-backend") + .withPropertyValues("otel.resource.attributes.service.name=otel-name-backend") .run( context -> { Resource otelResource = context.getBean("otelResource", Resource.class); @@ -157,9 +157,9 @@ void shouldInitializeAttributes() { AutoConfigurations.of( OtelResourceAutoConfiguration.class, OpenTelemetryAutoConfiguration.class)) .withPropertyValues( - "otel.springboot.resource.attributes.xyz=foo", - "otel.springboot.resource.attributes.environment=dev", - "otel.springboot.resource.attributes.service.instance.id=id-example") + "otel.resource.attributes.xyz=foo", + "otel.resource.attributes.environment=dev", + "otel.resource.attributes.service.instance.id=id-example") .run( context -> { Resource otelResource = context.getBean("otelResource", Resource.class); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/MetricExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/MetricExporterAutoConfigurationTest.java index 88519549b725..dba88212ef97 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/MetricExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/MetricExporterAutoConfigurationTest.java @@ -42,7 +42,7 @@ void defaultConfiguration() { @Test void loggingEnabledByConfiguration() { contextRunner - .withPropertyValues("otel.exporter.logging.enabled=true") + .withPropertyValues("otel.metrics.exporter=logging,otlp") .run( context -> { assertThat(context.getBean("otelOtlpMetricExporter", OtlpHttpMetricExporter.class)) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/SpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/SpanExporterAutoConfigurationTest.java index 084694823be3..2cfd63d80a51 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/SpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/SpanExporterAutoConfigurationTest.java @@ -42,7 +42,7 @@ void defaultConfiguration() { @Test void loggingEnabledByConfiguration() { contextRunner - .withPropertyValues("otel.exporter.logging.enabled=true") + .withPropertyValues("otel.traces.exporter=logging,otlp") .run( context -> { assertThat(context.getBean("otelOtlpSpanExporter", OtlpHttpSpanExporter.class)) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java index 9ae40188d63e..25849a6be309 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingMetricExporterAutoConfigurationTest.java @@ -23,7 +23,7 @@ class LoggingMetricExporterAutoConfigurationTest { LoggingMetricExporterAutoConfiguration.class)); @Test - void loggingEnabledNew() { + void enabled() { runner .withPropertyValues("otel.metrics.exporter=logging") .run( @@ -34,39 +34,10 @@ void loggingEnabledNew() { } @Test - void loggingEnabled() { + void disabled() { runner - .withPropertyValues("otel.exporter.logging.enabled=true") - .run( - context -> - assertThat( - context.getBean("otelLoggingMetricExporter", LoggingMetricExporter.class)) - .isNotNull()); - } - - @Test - void loggingMetricsEnabled() { - runner - .withPropertyValues("otel.exporter.logging.metrics.enabled=true") - .run( - context -> - assertThat( - context.getBean("otelLoggingMetricExporter", LoggingMetricExporter.class)) - .isNotNull()); - } - - @Test - void loggingDisabled() { - runner - .withPropertyValues("otel.exporter.logging.enabled=false") - .run(context -> assertThat(context.containsBean("otelLoggingMetricExporter")).isFalse()); - } - - @Test - void loggingMetricsDisabled() { - runner - .withPropertyValues("otel.exporter.logging.metrics.enabled=false") - .run(context -> assertThat(context.containsBean("otelLoggingMetricExporter")).isFalse()); + .withPropertyValues("otel.metrics.exporter=none") + .run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse()); } @Test diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java index 26409fad1865..e4a69116b870 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/LoggingSpanExporterAutoConfigurationTest.java @@ -9,7 +9,6 @@ import io.opentelemetry.exporter.logging.LoggingSpanExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; -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; @@ -17,7 +16,7 @@ /** Spring Boot auto configuration test for {@link LoggingSpanExporter}. */ class LoggingSpanExporterAutoConfigurationTest { - private final ApplicationContextRunner contextRunner = + private final ApplicationContextRunner runner = new ApplicationContextRunner() .withConfiguration( AutoConfigurations.of( @@ -25,8 +24,8 @@ class LoggingSpanExporterAutoConfigurationTest { LoggingSpanExporterAutoConfiguration.class)); @Test - void loggingEnabledNew() { - contextRunner + void enabled() { + runner .withPropertyValues("otel.traces.exporter=logging") .run( context -> @@ -35,47 +34,14 @@ void loggingEnabledNew() { } @Test - @DisplayName("when exporters are ENABLED should initialize LoggingSpanExporter bean") - void loggingEnabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.enabled=true") - .run( - context -> - assertThat(context.getBean("otelLoggingSpanExporter", LoggingSpanExporter.class)) - .isNotNull()); - } - - @Test - void loggingTracesEnabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.traces.enabled=true") - .run( - context -> - assertThat(context.getBean("otelLoggingSpanExporter", LoggingSpanExporter.class)) - .isNotNull()); - } - - @Test - @DisplayName("when exporters are DISABLED should NOT initialize LoggingSpanExporter bean") - void loggingDisabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.enabled=false") - .run(context -> assertThat(context.containsBean("otelLoggingSpanExporter")).isFalse()); - } - - @Test - @DisplayName("when exporters are DISABLED should NOT initialize LoggingSpanExporter bean") - void loggingTracesDisabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.traces.enabled=false") - .run(context -> assertThat(context.containsBean("otelLoggingSpanExporter")).isFalse()); + void disabled() { + runner + .withPropertyValues("otel.traces.exporter=none") + .run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse()); } @Test - @DisplayName( - "when exporter enabled property is MISSING should initialize LoggingSpanExporter bean") - void exporterPresentByDefault() { - contextRunner.run( - context -> assertThat(context.containsBean("otelLoggingSpanExporter")).isFalse()); + void noProperties() { + runner.run(context -> assertThat(context.containsBean("otelLoggingSpanExporter")).isFalse()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfigurationTest.java index 58082f2f871b..d139cef3e762 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/logging/SystemOutLogRecordExporterAutoConfigurationTest.java @@ -9,7 +9,6 @@ import io.opentelemetry.exporter.logging.SystemOutLogRecordExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; -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; @@ -17,7 +16,7 @@ /** Spring Boot auto configuration test for {@link SystemOutLogRecordExporter}. */ class SystemOutLogRecordExporterAutoConfigurationTest { - private final ApplicationContextRunner contextRunner = + private final ApplicationContextRunner runner = new ApplicationContextRunner() .withConfiguration( AutoConfigurations.of( @@ -25,8 +24,8 @@ class SystemOutLogRecordExporterAutoConfigurationTest { SystemOutLogRecordExporterAutoConfiguration.class)); @Test - void loggingEnabledNew() { - contextRunner + void enabled() { + runner .withPropertyValues("otel.logs.exporter=logging") .run( context -> @@ -37,55 +36,14 @@ void loggingEnabledNew() { } @Test - @DisplayName("when exporters are ENABLED should initialize SystemOutLogRecordExporter bean") - void loggingEnabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.enabled=true") - .run( - context -> - assertThat( - context.getBean( - "otelSystemOutLogRecordExporter", SystemOutLogRecordExporter.class)) - .isNotNull()); - } - - @Test - void loggingLogsEnabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.logs.enabled=true") - .run( - context -> - assertThat( - context.getBean( - "otelSystemOutLogRecordExporter", SystemOutLogRecordExporter.class)) - .isNotNull()); - } - - @Test - @DisplayName("when exporters are DISABLED should NOT initialize SystemOutLogRecordExporter bean") - void loggingDisabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.enabled=false") - .run( - context -> - assertThat(context.containsBean("otelSystemOutLogRecordExporter")).isFalse()); - } - - @Test - @DisplayName("when exporters are DISABLED should NOT initialize SystemOutLogRecordExporter bean") - void loggingLogsDisabled() { - contextRunner - .withPropertyValues("otel.exporter.logging.logs.enabled=false") - .run( - context -> - assertThat(context.containsBean("otelSystemOutLogRecordExporter")).isFalse()); + void disabled() { + runner + .withPropertyValues("otel.logs.exporter=none") + .run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse()); } @Test - @DisplayName( - "when exporter enabled property is MISSING should initialize SystemOutLogRecordExporter bean") - void exporterPresentByDefault() { - contextRunner.run( - context -> assertThat(context.containsBean("otelSystemOutLogRecordExporter")).isFalse()); + void noProperties() { + runner.run(context -> assertThat(context.containsBean("otelLoggingSpanExporter")).isFalse()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterPropertiesTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterPropertiesTest.java index 32bd23f56478..980e69ad768c 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterPropertiesTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpExporterPropertiesTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; import io.opentelemetry.instrumentation.spring.autoconfigure.propagators.PropagationProperties; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceAutoConfiguration; +import io.opentelemetry.instrumentation.spring.autoconfigure.resources.OtelResourceProperties; import io.opentelemetry.instrumentation.spring.autoconfigure.resources.SpringConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import java.util.Arrays; @@ -92,6 +93,7 @@ private static ConfigProperties getConfig(AssertableApplicationContext context) context.getBean("environment", Environment.class), new SpelExpressionParser(), context.getBean(OtlpExporterProperties.class), + new OtelResourceProperties(), new PropagationProperties()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java index 644193d8933d..27b3687379b6 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpLogExporterAutoConfigurationTest.java @@ -8,7 +8,6 @@ import static org.assertj.core.api.Assertions.assertThat; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; -import io.opentelemetry.sdk.logs.export.LogRecordExporter; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; @@ -22,42 +21,8 @@ class OtlpLogExporterAutoConfigurationTest { OpenTelemetryAutoConfiguration.class, OtlpLogRecordExporterAutoConfiguration.class)); - @Test - void otlpEnabled() { - runner - .withPropertyValues("otel.exporter.otlp.enabled=true") - .run( - context -> - assertThat(context.getBean("otelOtlpLogRecordExporter", LogRecordExporter.class)) - .isNotNull()); - } - - @Test - void otlpLogsEnabled() { - runner - .withPropertyValues("otel.exporter.otlp.logs.enabled=true") - .run( - context -> - assertThat(context.getBean("otelOtlpLogRecordExporter", LogRecordExporter.class)) - .isNotNull()); - } - @Test void otlpDisabled() { - runner - .withPropertyValues("otel.exporter.otlp.enabled=false") - .run(context -> assertThat(context.containsBean("otelOtlpLogRecordExporter")).isFalse()); - } - - @Test - void otlpLogsDisabledOld() { - runner - .withPropertyValues("otel.exporter.otlp.logs.enabled=false") - .run(context -> assertThat(context.containsBean("otelOtlpLogRecordExporter")).isFalse()); - } - - @Test - void otlpLogsDisabled() { runner .withPropertyValues("otel.logs.exporter=none") .run(context -> assertThat(context.containsBean("otelOtlpLogRecordExporter")).isFalse()); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java index b9a017d38613..822026f3550d 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpMetricExporterAutoConfigurationTest.java @@ -7,7 +7,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -21,42 +20,8 @@ class OtlpMetricExporterAutoConfigurationTest { AutoConfigurations.of( OpenTelemetryAutoConfiguration.class, OtlpMetricExporterAutoConfiguration.class)); - @Test - void otlpEnabled() { - runner - .withPropertyValues("otel.exporter.otlp.enabled=true") - .run( - context -> - assertThat(context.getBean("otelOtlpMetricExporter", OtlpHttpMetricExporter.class)) - .isNotNull()); - } - - @Test - void otlpMetricsEnabled() { - runner - .withPropertyValues("otel.exporter.otlp.metrics.enabled=true") - .run( - context -> - assertThat(context.getBean("otelOtlpMetricExporter", OtlpHttpMetricExporter.class)) - .isNotNull()); - } - @Test void otlpDisabled() { - runner - .withPropertyValues("otel.exporter.otlp.enabled=false") - .run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse()); - } - - @Test - void otlpMetricsDisabledOld() { - runner - .withPropertyValues("otel.exporter.otlp.metrics.enabled=false") - .run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse()); - } - - @Test - void otlpMetricsDisabled() { runner .withPropertyValues("otel.metrics.exporter=none") .run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse()); diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java index c98d9817161d..63a2cc2af347 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/otlp/OtlpSpanExporterAutoConfigurationTest.java @@ -7,9 +7,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; -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; @@ -24,38 +22,9 @@ class OtlpSpanExporterAutoConfigurationTest { OpenTelemetryAutoConfiguration.class, OtlpSpanExporterAutoConfiguration.class)); @Test - @DisplayName("when exporters are ENABLED should initialize OtlpHttpSpanExporter bean") - void otlpEnabled() { - this.contextRunner - .withPropertyValues("otel.exporter.otlp.enabled=true") - .run( - context -> - assertThat(context.getBean("otelOtlpSpanExporter", OtlpHttpSpanExporter.class)) - .isNotNull()); - } - - @Test - void otlpTracesEnabled() { - this.contextRunner - .withPropertyValues("otel.exporter.otlp.traces.enabled=true") - .run( - context -> - assertThat(context.getBean("otelOtlpSpanExporter", OtlpHttpSpanExporter.class)) - .isNotNull()); - } - - @Test - @DisplayName("when exporters are DISABLED should NOT initialize OtlpGrpcSpanExporter bean") void otlpDisabled() { - this.contextRunner - .withPropertyValues("otel.exporter.otlp.enabled=false") - .run(context -> assertThat(context.containsBean("otelOtlpSpanExporter")).isFalse()); - } - - @Test - void otlpTracesDisabledOld() { - this.contextRunner - .withPropertyValues("otel.exporter.otlp.traces.enabled=false") + contextRunner + .withPropertyValues("otel.traces.exporter=none") .run(context -> assertThat(context.containsBean("otelOtlpSpanExporter")).isFalse()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java index c7e96794a01a..eec9ebad4a0f 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/exporters/zipkin/ZipkinSpanExporterAutoConfigurationTest.java @@ -27,7 +27,7 @@ class ZipkinSpanExporterAutoConfigurationTest { @DisplayName("when exporters are ENABLED should initialize ZipkinSpanExporter bean") void exportersEnabled() { this.contextRunner - .withPropertyValues("otel.exporter.zipkin.enabled=true") + .withPropertyValues("otel.traces.exporter=zipkin") .run( context -> assertThat(context.getBean("otelZipkinSpanExporter", ZipkinSpanExporter.class)) @@ -40,7 +40,7 @@ void exportersEnabled() { void handlesProperties() { this.contextRunner .withPropertyValues( - "otel.exporter.zipkin.enabled=true", + "otel.traces.exporter=zipkin", "otel.exporter.zipkin.endpoint=http://localhost:8080/test") .run( context -> { @@ -51,14 +51,6 @@ void handlesProperties() { }); } - @Test - @DisplayName("when exporters are DISABLED should NOT initialize ZipkinSpanExporter bean") - void disabledPropertyOld() { - this.contextRunner - .withPropertyValues("otel.exporter.zipkin.enabled=false") - .run(context -> assertThat(context.containsBean("otelZipkinSpanExporter")).isFalse()); - } - @Test @DisplayName("when exporters are DISABLED should NOT initialize ZipkinSpanExporter bean") void disabledProperty() { diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java index 94c7fa3a8304..93a01df65cc4 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationAutoConfigurationTest.java @@ -64,7 +64,7 @@ void shouldContainDefaults() { @DisplayName("when propagation is set to b3 should contain only b3 propagator") void shouldContainB3() { this.contextRunner - .withPropertyValues("otel.propagation.type=b3") + .withPropertyValues("otel.propagators=b3") .run( context -> { TextMapPropagator compositePropagator = @@ -81,7 +81,7 @@ void shouldContainB3() { void shouldCreateNoop() { this.contextRunner - .withPropertyValues("otel.propagation.type=invalid") + .withPropertyValues("otel.propagators=invalid") .run( context -> { TextMapPropagator compositePropagator = @@ -92,11 +92,10 @@ void shouldCreateNoop() { } @Test - @DisplayName( - "when propagation is set to some values should contain only supported values - deprecated") - void shouldContainOnlySupportedDeprecated() { + @DisplayName("when propagation is set to some values should contain only supported values - List") + void shouldContainOnlySupportedList() { this.contextRunner - .withPropertyValues("otel.propagation.type=invalid,b3") + .withPropertyValues("otel.propagators=invalid,b3") .run( context -> { TextMapPropagator compositePropagator = diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java deleted file mode 100644 index 78176f7a1395..000000000000 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/propagators/PropagationPropertiesTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.autoconfigure.propagators; - -import static org.assertj.core.api.Assertions.assertThat; - -import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; -import java.util.Arrays; -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; - -@SuppressWarnings("deprecation") // test for deprecated code -public class PropagationPropertiesTest { - - private final ApplicationContextRunner contextRunner = - new ApplicationContextRunner() - .withConfiguration( - AutoConfigurations.of( - OpenTelemetryAutoConfiguration.class, PropagationAutoConfiguration.class)); - - @Test - @DisplayName("when propagation is SET should set PropagationProperties with given propagators") - void hasType() { - - this.contextRunner - .withPropertyValues("otel.propagation.type=xray,b3") - .run( - context -> { - DeprecatedPropagationProperties propertiesBean = - context.getBean(DeprecatedPropagationProperties.class); - - assertThat(propertiesBean.getType()).isEqualTo(Arrays.asList("xray", "b3")); - }); - } - - @Test - @DisplayName("when propagation is DEFAULT should set PropagationProperties to default values") - void hasDefaultTypes() { - - this.contextRunner.run( - context -> - assertThat(context.getBean(DeprecatedPropagationProperties.class).getType()) - .containsExactly("tracecontext", "baggage")); - } -} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java index 17506fffe3ed..297d7dac5530 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfigurationTest.java @@ -26,7 +26,7 @@ public class OtelResourceAutoConfigurationTest { void shouldDetermineServiceNameByOtelServiceName() { this.contextRunner .withPropertyValues("otel.springboot.resource.enabled=true") - .run(context -> assertThat(context.containsBean("otelResourceProvider")).isTrue()); + .run(context -> assertThat(context.containsBean("otelSpringResourceProvider")).isTrue()); } @Test @@ -34,7 +34,7 @@ void shouldDetermineServiceNameByOtelServiceName() { "when otel.springboot.resource.enabled is not specified configuration should be initialized") void shouldInitAutoConfigurationByDefault() { this.contextRunner.run( - context -> assertThat(context.containsBean("otelResourceProvider")).isTrue()); + context -> assertThat(context.containsBean("otelSpringResourceProvider")).isTrue()); } @Test @@ -43,6 +43,6 @@ void shouldInitAutoConfigurationByDefault() { void shouldNotInitAutoConfiguration() { this.contextRunner .withPropertyValues("otel.springboot.resource.enabled=false") - .run(context -> assertThat(context.containsBean("otelResourceProvider")).isFalse()); + .run(context -> assertThat(context.containsBean("otelSpringResourceProvider")).isFalse()); } } diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java deleted file mode 100644 index 06faf120cc33..000000000000 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourcePropertiesTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.spring.autoconfigure.resources; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - -import com.google.common.collect.ImmutableMap; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; -import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; -import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; -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; - -public class OtelResourcePropertiesTest { - private final ApplicationContextRunner contextRunner = - new ApplicationContextRunner() - .withPropertyValues("otel.springboot.resource.enabled=true") - .withConfiguration( - AutoConfigurations.of( - OtelResourceAutoConfiguration.class, OpenTelemetryAutoConfiguration.class)); - - @Test - @DisplayName("when attributes are SET should set OtelResourceProperties with given attributes") - void hasAttributes() { - - this.contextRunner - .withPropertyValues( - "otel.resource.attributes=foo=bar,environment=dev,service.name=hidden2", - "otel.springboot.resource.attributes.foo=baz", // hidden by otel.resource.attributes - "otel.springboot.resource.attributes.service.name=hidden1", - "otel.springboot.resource.attributes.service.instance.id=id-example") - .run( - context -> { - ResourceProvider resource = - context.getBean("otelResourceProvider", ResourceProvider.class); - - assertThat( - resource - .createResource( - DefaultConfigProperties.createFromMap( - ImmutableMap.of( - "spring.application.name", "hidden0", - "otel.service.name", "backend"))) - .getAttributes() - .asMap()) - .contains( - entry(AttributeKey.stringKey("foo"), "bar"), - entry(AttributeKey.stringKey("environment"), "dev"), - entry(AttributeKey.stringKey("service.name"), "backend"), - entry(AttributeKey.stringKey("service.instance.id"), "id-example")); - }); - } - - @Test - @DisplayName("when attributes are DEFAULT should set OtelResourceProperties to default values") - void hasDefaultTypes() { - - this.contextRunner.run( - context -> - assertThat(context.getBean(OtelSpringResourceProperties.class).getAttributes()) - .isEmpty()); - } -} diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigPropertiesTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigPropertiesTest.java index 40cef893c54f..598dd94fa5e0 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigPropertiesTest.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringConfigPropertiesTest.java @@ -33,6 +33,7 @@ void shouldInitializeAttributesByMapInArow() { env, new SpelExpressionParser(), new OtlpExporterProperties(), + new OtelResourceProperties(), new PropagationProperties()); assertThat(config.getMap("otel.springboot.test.map")) diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProviderTest.java b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProviderTest.java new file mode 100644 index 000000000000..e896b0a96123 --- /dev/null +++ b/instrumentation/spring/spring-boot-autoconfigure/src/test/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/SpringResourceProviderTest.java @@ -0,0 +1,57 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.spring.autoconfigure.resources; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +import com.google.common.collect.ImmutableMap; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; +import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; +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; + +public class SpringResourceProviderTest { + private final ApplicationContextRunner contextRunner = + new ApplicationContextRunner() + .withPropertyValues("otel.springboot.resource.enabled=true") + .withConfiguration( + AutoConfigurations.of( + OtelResourceAutoConfiguration.class, OpenTelemetryAutoConfiguration.class)); + + @Test + @DisplayName("when attributes are SET should set OtelResourceProperties with given attributes") + void hasAttributes() { + + this.contextRunner.run( + context -> { + ResourceProvider resource = + context.getBean("otelSpringResourceProvider", ResourceProvider.class); + + assertThat( + resource + .createResource( + DefaultConfigProperties.createFromMap( + ImmutableMap.of("spring.application.name", "backend"))) + .getAttributes() + .asMap()) + .contains(entry(AttributeKey.stringKey("service.name"), "backend")); + }); + } + + @Test + @DisplayName("when attributes are DEFAULT should set OtelResourceProperties to default values") + void hasDefaultTypes() { + + this.contextRunner.run( + context -> + assertThat(context.getBean(OtelResourceProperties.class).getAttributes()).isEmpty()); + } +} diff --git a/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java index 814b6aeb3040..5bfffb1f6f4f 100644 --- a/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/src/test/java/io/opentelemetry/smoketest/OtelSpringStarterSmokeTest.java @@ -42,8 +42,7 @@ "otel.metric.export.interval=100", "otel.exporter.otlp.headers=a=1,b=2", // We set the export interval of the metrics to 100 ms. The default value is 1 minute. - // the headers are simply set here to make sure that headers can be parsed, even with - // otel.exporter.otlp.enabled=false + // the headers are simply set here to make sure that headers can be parsed }) class OtelSpringStarterSmokeTest {