From a630baf32abb558f1b4b8e896ab8ea0dbea924b8 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 4 Oct 2023 10:24:56 +0100 Subject: [PATCH] Start building against Micrometer Tracing 1.2.0 snapshots See gh-37704 --- .../spring-boot-actuator-autoconfigure/build.gradle | 1 + .../opentelemetry/OpenTelemetryAutoConfiguration.java | 7 ++++--- .../OpenTelemetryAutoConfigurationTests.java | 11 +++++------ .../tracing/OpenTelemetryAutoConfigurationTests.java | 6 ++---- .../spring-boot-dependencies/build.gradle | 2 +- src/checkstyle/checkstyle.xml | 2 ++ 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index a55874e629..38cfeca464 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -68,6 +68,7 @@ dependencies { optional("io.micrometer:micrometer-registry-signalfx") optional("io.micrometer:micrometer-registry-statsd") optional("io.micrometer:micrometer-registry-wavefront") + optional("io.zipkin.reporter2:zipkin-reporter-brave") optional("io.zipkin.reporter2:zipkin-sender-urlconnection") optional("io.opentelemetry:opentelemetry-exporter-zipkin") optional("io.opentelemetry:opentelemetry-exporter-otlp") diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfiguration.java index b0874f7791..3ffe4d0bb3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure.opentelemetry; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.context.propagation.ContextPropagators; import io.opentelemetry.sdk.OpenTelemetrySdk; @@ -52,6 +53,8 @@ public class OpenTelemetryAutoConfiguration { */ private static final String DEFAULT_APPLICATION_NAME = "application"; + static final AttributeKey ATTRIBUTE_KEY_SERVICE_NAME = AttributeKey.stringKey("service.name"); + @Bean @ConditionalOnMissingBean(OpenTelemetry.class) OpenTelemetrySdk openTelemetry(ObjectProvider tracerProvider, @@ -67,12 +70,10 @@ public class OpenTelemetryAutoConfiguration { @Bean @ConditionalOnMissingBean - @SuppressWarnings("deprecation") Resource openTelemetryResource(Environment environment, OpenTelemetryProperties properties) { String applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME); return Resource.getDefault() - .merge(Resource.create(Attributes - .of(io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME, applicationName))) + .merge(Resource.create(Attributes.of(ATTRIBUTE_KEY_SERVICE_NAME, applicationName))) .merge(toResource(properties)); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfigurationTests.java index 6a75705631..167be648bf 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/opentelemetry/OpenTelemetryAutoConfigurationTests.java @@ -24,6 +24,7 @@ import io.opentelemetry.sdk.logs.SdkLoggerProvider; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.semconv.ResourceAttributes; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfiguration; @@ -81,22 +82,20 @@ class OpenTelemetryAutoConfigurationTests { } @Test - @SuppressWarnings("deprecation") void shouldApplySpringApplicationNameToResource() { this.runner.withPropertyValues("spring.application.name=my-application").run((context) -> { Resource resource = context.getBean(Resource.class); - assertThat(resource.getAttributes().asMap()).contains(entry( - io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME, "my-application")); + assertThat(resource.getAttributes().asMap()) + .contains(entry(ResourceAttributes.SERVICE_NAME, "my-application")); }); } @Test - @SuppressWarnings("deprecation") void shouldFallbackToDefaultApplicationNameIfSpringApplicationNameIsNotSet() { this.runner.run((context) -> { Resource resource = context.getBean(Resource.class); - assertThat(resource.getAttributes().asMap()).contains( - entry(io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME, "application")); + assertThat(resource.getAttributes().asMap()) + .contains(entry(ResourceAttributes.SERVICE_NAME, "application")); }); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java index 2d02df024c..64bb185713 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfigurationTests.java @@ -50,6 +50,7 @@ import io.opentelemetry.sdk.trace.SpanProcessor; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.export.SpanExporter; import io.opentelemetry.sdk.trace.samplers.Sampler; +import io.opentelemetry.semconv.ResourceAttributes; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -169,7 +170,6 @@ class OpenTelemetryAutoConfigurationTests { } @Test - @SuppressWarnings("deprecation") void shouldSetupDefaultResourceAttributes() { this.contextRunner .withConfiguration( @@ -182,9 +182,7 @@ class OpenTelemetryAutoConfigurationTests { exporter.await(Duration.ofSeconds(10)); SpanData spanData = exporter.getExportedSpans().get(0); Map, Object> expectedAttributes = Resource.getDefault() - .merge(Resource.create( - Attributes.of(io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME, - "application"))) + .merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "application"))) .getAttributes() .asMap(); assertThat(spanData.getResource().getAttributes().asMap()).isEqualTo(expectedAttributes); diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index e1c0fe2321..32391033f4 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1011,7 +1011,7 @@ bom { ] } } - library("Micrometer Tracing", "1.2.0-M3") { + library("Micrometer Tracing", "1.2.0-SNAPSHOT") { considerSnapshots() calendarName = "Tracing" group("io.micrometer") { diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 9292568972..2d54032563 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -24,6 +24,8 @@ +