conghuhu commented on code in PR #13397:
URL: https://github.com/apache/dubbo/pull/13397#discussion_r1401590599
##########
dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java:
##########
@@ -93,13 +95,29 @@ io.opentelemetry.sdk.trace.SdkTracerProvider
otelSdkTracerProvider(
.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<String> attributeKey = null;
+ String SERVICE_NAME = "SERVICE_NAME";
+
+ if (isLowVersion) {
+ RESOURCE_ATTRIBUTES_CLASS_NAME =
"io.opentelemetry.semconv.resource.attributes.ResourceAttributes";
+ }
+ try {
+ attributeKey = (AttributeKey<String>) 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(attributeKey, applicationName)));
Review Comment:
Assigned a default value
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]