Remove deprecated spring properties (#10454)

This commit is contained in:
Gregor Zeitlinger 2024-02-16 17:27:26 +01:00 committed by GitHub
parent 51aa39be79
commit d8aa0f5b48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 139 additions and 515 deletions

View File

@ -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")

View File

@ -15,6 +15,7 @@ import io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp.Otlp
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 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
@EnableConfigurationProperties({
SamplerProperties.class,
OtlpExporterProperties.class,
OtelResourceProperties.class,
PropagationProperties.class
})
public class OpenTelemetryAutoConfiguration {
@ -103,9 +105,14 @@ public class OpenTelemetryAutoConfiguration {
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

View File

@ -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;
}
}

View File

@ -35,12 +35,7 @@ public class LoggingMetricExporterAutoConfiguration {
@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);
}
}
}

View File

@ -35,12 +35,7 @@ public class LoggingSpanExporterAutoConfiguration {
@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);
}
}
}

View File

@ -35,12 +35,7 @@ public class SystemOutLogRecordExporterAutoConfiguration {
@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);
}
}
}

View File

@ -36,12 +36,7 @@ public class OtlpLogRecordExporterAutoConfiguration {
@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);
}
}
}

View File

@ -38,12 +38,7 @@ public class OtlpMetricExporterAutoConfiguration {
@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);
}
}
}

View File

@ -43,12 +43,7 @@ public class OtlpSpanExporterAutoConfiguration {
@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);
}
}
}

View File

@ -47,12 +47,7 @@ public class ZipkinSpanExporterAutoConfiguration {
@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);
}
}
}

View File

@ -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<String> types) {

View File

@ -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<String> type = Arrays.asList("tracecontext", "baggage");
public List<String> getType() {
return type;
}
public void setType(List<String> type) {
this.type = type;
}
}

View File

@ -9,6 +9,7 @@ import io.opentelemetry.context.propagation.ContextPropagators;
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 @@ import org.springframework.context.annotation.Configuration;
/** 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<String> DEFAULT_PROPAGATORS = Arrays.asList("tracecontext", "baggage");
@Bean
@ConditionalOnMissingBean
ContextPropagators contextPropagators(ObjectProvider<List<TextMapPropagator>> propagators) {
@ -43,11 +45,9 @@ public class PropagationAutoConfiguration {
@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));
}
}
}

View File

@ -16,6 +16,7 @@ import io.opentelemetry.instrumentation.resources.ProcessResourceProvider;
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.Bean;
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

View File

@ -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<String, String> attributes = Collections.emptyMap();
public Map<String, String> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
}

View File

@ -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 class SpringConfigProperties implements ConfigProperties {
if (name.equals("otel.propagators")) {
return propagationProperties.getPropagators();
}
List<String> value = environment.getProperty(name, List.class);
return value == null ? Collections.emptyList() : value;
}
@ -98,6 +102,8 @@ public class SpringConfigProperties implements ConfigProperties {
public Map<String, String> 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":

View File

@ -14,16 +14,6 @@ import io.opentelemetry.semconv.ResourceAttributes;
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 class SpringResourceProvider implements ResourceProvider {
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());
}
}

View File

@ -140,7 +140,7 @@ class OpenTelemetryAutoConfigurationTest {
.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 @@ class OpenTelemetryAutoConfigurationTest {
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);

View File

@ -42,7 +42,7 @@ class MetricExporterAutoConfigurationTest {
@Test
void loggingEnabledByConfiguration() {
contextRunner
.withPropertyValues("otel.exporter.logging.enabled=true")
.withPropertyValues("otel.metrics.exporter=logging,otlp")
.run(
context -> {
assertThat(context.getBean("otelOtlpMetricExporter", OtlpHttpMetricExporter.class))

View File

@ -42,7 +42,7 @@ class SpanExporterAutoConfigurationTest {
@Test
void loggingEnabledByConfiguration() {
contextRunner
.withPropertyValues("otel.exporter.logging.enabled=true")
.withPropertyValues("otel.traces.exporter=logging,otlp")
.run(
context -> {
assertThat(context.getBean("otelOtlpSpanExporter", OtlpHttpSpanExporter.class))

View File

@ -23,7 +23,7 @@ class LoggingMetricExporterAutoConfigurationTest {
LoggingMetricExporterAutoConfiguration.class));
@Test
void loggingEnabledNew() {
void enabled() {
runner
.withPropertyValues("otel.metrics.exporter=logging")
.run(
@ -34,39 +34,10 @@ class LoggingMetricExporterAutoConfigurationTest {
}
@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

View File

@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat;
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 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
/** 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 @@ class LoggingSpanExporterAutoConfigurationTest {
}
@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());
void disabled() {
runner
.withPropertyValues("otel.traces.exporter=none")
.run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse());
}
@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());
}
@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());
}
}

View File

@ -9,7 +9,6 @@ import static org.assertj.core.api.Assertions.assertThat;
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 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
/** 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 @@ class SystemOutLogRecordExporterAutoConfigurationTest {
}
@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());
void disabled() {
runner
.withPropertyValues("otel.logs.exporter=none")
.run(context -> assertThat(context.containsBean("otelOtlpMetricExporter")).isFalse());
}
@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());
}
@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());
}
}

View File

@ -11,6 +11,7 @@ import static org.assertj.core.api.Assertions.entry;
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 @@ class OtlpExporterPropertiesTest {
context.getBean("environment", Environment.class),
new SpelExpressionParser(),
context.getBean(OtlpExporterProperties.class),
new OtelResourceProperties(),
new PropagationProperties());
}
}

View File

@ -8,7 +8,6 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp;
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());

View File

@ -7,7 +7,6 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp;
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());

View File

@ -7,9 +7,7 @@ package io.opentelemetry.instrumentation.spring.autoconfigure.exporters.otlp;
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());
}
}

View File

@ -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 @@ class ZipkinSpanExporterAutoConfigurationTest {
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 @@ class ZipkinSpanExporterAutoConfigurationTest {
});
}
@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() {

View File

@ -64,7 +64,7 @@ class PropagationAutoConfigurationTest {
@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 @@ class PropagationAutoConfigurationTest {
void shouldCreateNoop() {
this.contextRunner
.withPropertyValues("otel.propagation.type=invalid")
.withPropertyValues("otel.propagators=invalid")
.run(
context -> {
TextMapPropagator compositePropagator =
@ -92,11 +92,10 @@ class PropagationAutoConfigurationTest {
}
@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 =

View File

@ -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"));
}
}

View File

@ -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 @@ public class OtelResourceAutoConfigurationTest {
"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 @@ public class OtelResourceAutoConfigurationTest {
void shouldNotInitAutoConfiguration() {
this.contextRunner
.withPropertyValues("otel.springboot.resource.enabled=false")
.run(context -> assertThat(context.containsBean("otelResourceProvider")).isFalse());
.run(context -> assertThat(context.containsBean("otelSpringResourceProvider")).isFalse());
}
}

View File

@ -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());
}
}

View File

@ -33,6 +33,7 @@ class SpringConfigPropertiesTest {
env,
new SpelExpressionParser(),
new OtlpExporterProperties(),
new OtelResourceProperties(),
new PropagationProperties());
assertThat(config.getMap("otel.springboot.test.map"))

View File

@ -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());
}
}

View File

@ -42,8 +42,7 @@ import org.springframework.context.annotation.Configuration;
"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 {