Skip to content

Spring starter declarative config #14062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 66 commits into
base: main
Choose a base branch
from

Conversation

zeitlinger
Copy link
Member

@zeitlinger zeitlinger commented Jun 18, 2025

Based on #14184

Fixes #14048

Todo:

  • the distro resource provider and customizers are missing
Subject: [PATCH] add docs
---
Index: smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java
--- a/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java	(revision 07f537fbb250c00b5f195ac421eb0aabf4f1cea2)
+++ b/smoke-tests-otel-starter/spring-boot-2/src/testDeclarativeConfig/java/io/opentelemetry/spring/smoketest/OtelSpringStarterSmokeTest.java	(date 1752759689238)
@@ -5,8 +5,13 @@
 
 package io.opentelemetry.spring.smoketest;
 
+import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
+
 import io.opentelemetry.api.trace.SpanKind;
 import io.opentelemetry.semconv.HttpAttributes;
+import io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes;
+import io.opentelemetry.semconv.incubating.TelemetryIncubatingAttributes;
+import org.assertj.core.api.AbstractCharSequenceAssert;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -44,7 +49,21 @@
             traceAssert.hasSpansSatisfyingExactly(
                 span -> HttpSpanDataAssert.create(span).assertClientGetRequest("/ping"),
                 span ->
-                    span.hasKind(SpanKind.SERVER).hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"),
+                    span.hasKind(SpanKind.SERVER)
+                        .hasResourceSatisfying(
+                            r ->
+                                r.hasAttribute(
+                                        TelemetryIncubatingAttributes.TELEMETRY_DISTRO_NAME,
+                                        "opentelemetry-spring-boot-starter")
+                                    .hasAttribute(
+                                        satisfies(
+                                            TelemetryIncubatingAttributes.TELEMETRY_DISTRO_VERSION,
+                                            AbstractCharSequenceAssert::isNotBlank))
+                                    .hasAttribute(
+                                        satisfies(
+                                            ServiceIncubatingAttributes.SERVICE_INSTANCE_ID,
+                                            AbstractCharSequenceAssert::isNotBlank)))
+                        .hasAttribute(HttpAttributes.HTTP_ROUTE, "/ping"),
                 AbstractSpringStarterSmokeTest::withSpanAssert));
   }
 }
Index: instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java
--- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java	(revision 07f537fbb250c00b5f195ac421eb0aabf4f1cea2)
+++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryAutoConfiguration.java	(date 1752760335777)
@@ -73,16 +73,8 @@
   @Configuration
   @Conditional(OtelEnabled.class)
   @ConditionalOnMissingBean(OpenTelemetry.class)
+  @SuppressWarnings("OtelPrivateConstructorForUtilityClass")
   static class OpenTelemetrySdkConfig {
-    @Bean
-    public ResourceProvider otelSpringResourceProvider(Optional<BuildProperties> buildProperties) {
-      return new SpringResourceProvider(buildProperties);
-    }
-
-    @Bean
-    public ResourceProvider otelDistroVersionResourceProvider() {
-      return new DistroVersionResourceProvider();
-    }
 
     @Configuration
     @EnableConfigurationProperties({
@@ -93,6 +85,17 @@
     @Conditional(DeclarativeConfigDisabled.class)
     static class PropertiesConfig {
 
+      @Bean
+      public ResourceProvider otelSpringResourceProvider(
+          Optional<BuildProperties> buildProperties) {
+        return new SpringResourceProvider(buildProperties);
+      }
+
+      @Bean
+      public ResourceProvider otelDistroVersionResourceProvider() {
+        return new DistroVersionResourceProvider();
+      }
+
       @Bean
       @ConfigurationPropertiesBinding
       OtelMapConverter otelMapConverter() {

@zeitlinger zeitlinger self-assigned this Jun 18, 2025
@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Jun 18, 2025
@otelbot-java-instrumentation
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

@zeitlinger zeitlinger marked this pull request as ready for review June 19, 2025 16:09
@zeitlinger zeitlinger requested a review from a team as a code owner June 19, 2025 16:09
@zeitlinger zeitlinger force-pushed the spring-starter-declarative-config branch 2 times, most recently from 17d949a to f81444f Compare June 19, 2025 16:57
@zeitlinger
Copy link
Member Author

@laurit can you help me figure out what the problem is?

AgentInstrumentationTest > classPathSetUp() FAILED	
    java.lang.NoClassDefFoundError: io/opentelemetry/sdk/autoconfigure/spi/ConfigProperties	
        at java.lang.Class.forName0(Native Method)	
        at java.lang.Class.forName(Class.java:348)	
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:328)	
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)	
        at java.lang.Class.forName0(Native Method)	
        at java.lang.Class.forName(Class.java:264)	
        at instrumentation.AgentInstrumentationTest.classPathSetUp(AgentInstrumentationTest.java:53)

@zeitlinger
Copy link
Member Author

@laurit can you help me figure out what the problem is?

AgentInstrumentationTest > classPathSetUp() FAILED	
    java.lang.NoClassDefFoundError: io/opentelemetry/sdk/autoconfigure/spi/ConfigProperties	
        at java.lang.Class.forName0(Native Method)	
        at java.lang.Class.forName(Class.java:348)	
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:328)	
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)	
        at java.lang.Class.forName0(Native Method)	
        at java.lang.Class.forName(Class.java:264)	
        at instrumentation.AgentInstrumentationTest.classPathSetUp(AgentInstrumentationTest.java:53)

tried to fix that with cbb070b

@laurit
Copy link
Contributor

laurit commented Jun 20, 2025

@laurit can you help me figure out what the problem is?

AgentInstrumentationTest > classPathSetUp() FAILED	
    java.lang.NoClassDefFoundError: io/opentelemetry/sdk/autoconfigure/spi/ConfigProperties	
        at java.lang.Class.forName0(Native Method)	
        at java.lang.Class.forName(Class.java:348)	
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:328)	
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)	
        at java.lang.Class.forName0(Native Method)	
        at java.lang.Class.forName(Class.java:264)	
        at instrumentation.AgentInstrumentationTest.classPathSetUp(AgentInstrumentationTest.java:53)

tried to fix that with cbb070b

DeclarativeConfigPropertiesBridge is in boot loader but it depends on io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties that is not in boot loader

@zeitlinger
Copy link
Member Author

DeclarativeConfigPropertiesBridge is in boot loader but it depends on io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties that is not in boot loader

I can't figure out what change could have caused that.

Is the solution to not used ConfigProperties in the agent config?

@zeitlinger
Copy link
Member Author

DeclarativeConfigPropertiesBridge is in boot loader but it depends on io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties that is not in boot loader

I can't figure out what change could have caused that.

Is the solution to not used ConfigProperties in the agent config?

Let's see if it's 7116de1

@laurit
Copy link
Contributor

laurit commented Jun 20, 2025

Let's see if it's 7116de1

I don't think this is going to help. javaagent-extension-api belongs to boot loader, any class you are going to use there also needs to be in boot loader. Since based on that DeclarativeConfigPropertiesBridge needs to be in boot loader, it implements io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties that is not in boot loader, and shouldn't be there. Based on that I'd say the design is broken and needs to be rethought.

@zeitlinger
Copy link
Member Author

Let's see if it's 7116de1

I don't think this is going to help. javaagent-extension-api belongs to boot loader, any class you are going to use there also needs to be in boot loader. Since based on that DeclarativeConfigPropertiesBridge needs to be in boot loader, it implements io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties that is not in boot loader, and shouldn't be there. Based on that I'd say the design is broken and needs to be rethought.

Why is it not failing on main? DeclarativeConfigPropertiesBridge is not changed (unless I miss something)

@laurit
Copy link
Contributor

laurit commented Jun 20, 2025

Why is it not failing on main? DeclarativeConfigPropertiesBridge is not changed (unless I miss something)

Because on main you don't have it in boot loader. Actually I was wrong about javaagent-extension-api belonging to boot loader. During agent packaging some of it is moved to boot loader and other parts are moved to agent loader. See

bootstrapLibs(project(":javaagent-extension-api")) {
and
// exclude the agent part of the javaagent-extension-api; these classes will be added in relocate tasks
and
// exclude the bootstrap part of the javaagent-extension-api
I'd try excluding the bridge in
exclude("io.opentelemetry", "opentelemetry-sdk-extension-autoconfigure-spi")

@zeitlinger
Copy link
Member Author

I'd try excluding the bridge in

exclude("io.opentelemetry", "opentelemetry-sdk-extension-autoconfigure-spi")

That worked - thanks a lot!

@zeitlinger zeitlinger marked this pull request as draft June 25, 2025 07:07
@zeitlinger zeitlinger force-pushed the spring-starter-declarative-config branch from bf6b7f8 to 9427fe6 Compare June 30, 2025 09:31
@otelbot-java-instrumentation
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

@zeitlinger zeitlinger marked this pull request as ready for review June 30, 2025 10:42
@zeitlinger zeitlinger marked this pull request as draft June 30, 2025 10:48
@zeitlinger zeitlinger moved this from Blocked to In Progress in Declarative Configuration: Java Jul 4, 2025
@zeitlinger zeitlinger force-pushed the spring-starter-declarative-config branch from 482c0be to 5fcca3f Compare July 7, 2025 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test native This label can be applied to PRs to trigger them to run native tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support declarative config for spring starter
2 participants