Repository: apache/dubbo
File: dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java (Java)

Code before:
    io.opentelemetry.api.OpenTelemetry openTelemetry(
            io.opentelemetry.sdk.trace.SdkTracerProvider sdkTracerProvider,
            io.opentelemetry.context.propagation.ContextPropagators contextPropagators) {
        return io.opentelemetry.sdk.OpenTelemetrySdk.builder()
                .setTracerProvider(sdkTracerProvider)
                .setPropagators(contextPropagators)
                .build();
    }

    @Bean
    @ConditionalOnMissingBean
    io.opentelemetry.sdk.trace.SdkTracerProvider otelSdkTracerProvider(
            ObjectProvider<io.opentelemetry.sdk.trace.SpanProcessor> spanProcessors,
            io.opentelemetry.sdk.trace.samplers.Sampler sampler) {
        String applicationName = moduleModel
                .getApplicationModel()
                .getApplicationConfigManager()
                .getApplication()
                .map(ApplicationConfig::getName)
                .orElse(DEFAULT_APPLICATION_NAME);
        // Due to https://github.com/micrometer-metrics/tracing/issues/343
        boolean isLowVersion = false;
        AttributeKey<String> attributeKey = null;
        String SERVICE_NAME = "SERVICE_NAME";
        try {
            attributeKey = (AttributeKey<String>) ClassUtils.forName("io.opentelemetry.semconv.ResourceAttributes")
                    .getDeclaredField(SERVICE_NAME)
                    .get(null);
        } catch (Throwable t) {
            isLowVersion = true;
        }
        if (isLowVersion) {
            try {
                attributeKey = (AttributeKey<String>)
                        ClassUtils.forName("io.opentelemetry.semconv.resource.attributes.ResourceAttributes")
                                .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(attributeKey, applicationName)));
        spanProcessors.orderedStream().forEach(builder::addSpanProcessor);
        return builder.build();
    }

    @Bean
    @ConditionalOnMissingBean

Review comment (suggestion):
please use `ClassUtils.isPresent(className, classLoader)` replace ClassUtils.forName

Code after:
    io.opentelemetry.api.OpenTelemetry openTelemetry(
            io.opentelemetry.sdk.trace.SdkTracerProvider sdkTracerProvider,
            io.opentelemetry.context.propagation.ContextPropagators contextPropagators) {
        return io.opentelemetry.sdk.OpenTelemetrySdk.builder()
                .setTracerProvider(sdkTracerProvider)
                .setPropagators(contextPropagators)
                .build();
    }

    @Bean
    @ConditionalOnMissingBean
    io.opentelemetry.sdk.trace.SdkTracerProvider otelSdkTracerProvider(
            ObjectProvider<io.opentelemetry.sdk.trace.SpanProcessor> spanProcessors,
            io.opentelemetry.sdk.trace.samplers.Sampler sampler) {
        String applicationName = moduleModel
                .getApplicationModel()
                .getApplicationConfigManager()
                .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> 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<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(serviceNameAttributeKey, applicationName)));
        spanProcessors.orderedStream().forEach(builder::addSpanProcessor);
        return builder.build();
    }

    @Bean
    @ConditionalOnMissingBean
    io.opentelemetry.context.propagation.ContextPropagators otelContextPropagators(
            ObjectProvider<io.opentelemetry.context.propagation.TextMapPropagator> textMapPropagators) {