From e63d275eb61db8eaac00f7474e6e76e19ac805d0 Mon Sep 17 00:00:00 2001 From: conghuhu <56248584+conghuhu@users.noreply.github.com> Date: Sat, 25 Nov 2023 01:53:00 -0600 Subject: [PATCH] Bump io.micrometer:micrometer-tracing-bom from 1.1.6 to 1.2.0 (#13397) chore: compatibility between two versions through the existence of classes --- dubbo-dependencies-bom/pom.xml | 2 +- .../otel/OpenTelemetryAutoConfiguration.java | 24 ++++++++++++++++--- .../observability/pom.xml | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index f36b781520..0c5b2cc94d 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -134,7 +134,7 @@ 0.1.35 1.12.0 - 1.1.6 + 1.2.0 3.3 0.16.0 1.0.4 diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java index de77636e39..4eba4950dc 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java @@ -17,6 +17,7 @@ package org.apache.dubbo.spring.boot.observability.autoconfigure.otel; import org.apache.dubbo.common.Version; +import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties; @@ -28,6 +29,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import io.opentelemetry.api.common.AttributeKey; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -93,13 +95,29 @@ public class OpenTelemetryAutoConfiguration { .getApplication() .map(ApplicationConfig::getName) .orElse(DEFAULT_APPLICATION_NAME); + // Due to https://github.com/micrometer-metrics/tracing/issues/343 + String RESOURCE_ATTRIBUTES_CLASS_NAME = "io.opentelemetry.semconv.ResourceAttributes"; + boolean isLowVersion = !ClassUtils.isPresent( + RESOURCE_ATTRIBUTES_CLASS_NAME, Thread.currentThread().getContextClassLoader()); + AttributeKey serviceNameAttributeKey = AttributeKey.stringKey("service.name"); + String SERVICE_NAME = "SERVICE_NAME"; + + if (isLowVersion) { + RESOURCE_ATTRIBUTES_CLASS_NAME = "io.opentelemetry.semconv.resource.attributes.ResourceAttributes"; + } + try { + serviceNameAttributeKey = (AttributeKey) ClassUtils.resolveClass( + RESOURCE_ATTRIBUTES_CLASS_NAME, + Thread.currentThread().getContextClassLoader()) + .getDeclaredField(SERVICE_NAME) + .get(null); + } catch (Throwable ignored) { + } io.opentelemetry.sdk.trace.SdkTracerProviderBuilder builder = io.opentelemetry.sdk.trace.SdkTracerProvider.builder() .setSampler(sampler) .setResource(io.opentelemetry.sdk.resources.Resource.create( - io.opentelemetry.api.common.Attributes.of( - io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME, - applicationName))); + io.opentelemetry.api.common.Attributes.of(serviceNameAttributeKey, applicationName))); spanProcessors.orderedStream().forEach(builder::addSpanProcessor); return builder.build(); } diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml index be7d48a152..d37f4ca1f0 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml @@ -37,7 +37,7 @@ 1.12.0 - 1.1.6 + 1.2.0 1.32.0 2.16.4 0.16.0