diff --git a/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts b/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts index eede37e60510..4f1a932d59aa 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts +++ b/instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts @@ -47,6 +47,7 @@ dependencies { compileOnly(project(":instrumentation-annotations")) compileOnly(project(":instrumentation:resources:library")) + compileOnly(project(":instrumentation:spring:spring-boot-resources:library")) annotationProcessor("com.google.auto.service:auto-service") compileOnly("com.google.auto.service:auto-service-annotations") @@ -61,6 +62,7 @@ dependencies { testImplementation("io.opentelemetry:opentelemetry-sdk") testImplementation("io.opentelemetry:opentelemetry-sdk-testing") testImplementation(project(":instrumentation:resources:library")) + testImplementation(project(":instrumentation:spring:spring-boot-resources:library")) testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi") testImplementation("io.opentelemetry:opentelemetry-extension-annotations") testImplementation("io.opentelemetry:opentelemetry-extension-trace-propagators") diff --git a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java index 41aab9620db8..5e21b8d8fb0b 100644 --- a/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java +++ b/instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/resources/OtelResourceAutoConfiguration.java @@ -16,6 +16,8 @@ import io.opentelemetry.instrumentation.resources.ProcessRuntimeResource; import io.opentelemetry.instrumentation.resources.ProcessRuntimeResourceProvider; import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; +import io.opentelemetry.instrumentation.spring.resources.SpringBootServiceNameDetector; +import io.opentelemetry.instrumentation.spring.resources.SpringBootServiceVersionDetector; import io.opentelemetry.sdk.autoconfigure.internal.EnvironmentResourceProvider; import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; import org.springframework.boot.autoconfigure.AutoConfigureBefore; @@ -46,6 +48,18 @@ public ResourceProvider otelDistroVersionResourceProvider() { return new DistroVersionResourceProvider(); } + @Bean + @ConditionalOnClass(SpringBootServiceNameDetector.class) + public ResourceProvider otelSpringBootServiceNameResourceProvider() { + return new SpringBootServiceNameDetector(); + } + + @Bean + @ConditionalOnClass(SpringBootServiceVersionDetector.class) + public ResourceProvider otelSpringBootServiceVersionResourceProvider() { + return new SpringBootServiceVersionDetector(); + } + @Bean @ConditionalOnClass(OsResource.class) public ResourceProvider otelOsResourceProvider() { diff --git a/instrumentation/spring/spring-boot-resources/library/src/main/java/io/opentelemetry/instrumentation/spring/resources/SpringBootServiceNameDetector.java b/instrumentation/spring/spring-boot-resources/library/src/main/java/io/opentelemetry/instrumentation/spring/resources/SpringBootServiceNameDetector.java index b0a598846abe..02eb3897ba3c 100644 --- a/instrumentation/spring/spring-boot-resources/library/src/main/java/io/opentelemetry/instrumentation/spring/resources/SpringBootServiceNameDetector.java +++ b/instrumentation/spring/spring-boot-resources/library/src/main/java/io/opentelemetry/instrumentation/spring/resources/SpringBootServiceNameDetector.java @@ -45,6 +45,9 @@ *
  • Check for --spring.application.name program argument (not jvm arg) via ProcessHandle *
  • Check for --spring.application.name program argument via sun.java.command system property * + * + *

    Note: should not be used inside a spring application, where the spring.application.name is + * already available. */ @AutoService(ResourceProvider.class) public class SpringBootServiceNameDetector implements ConditionalResourceProvider { diff --git a/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts b/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts index 268247262975..a58d397eb60a 100644 --- a/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts +++ b/instrumentation/spring/starters/spring-boot-starter/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { api("org.springframework.boot:spring-boot-starter-aop:$springBootVersion") api(project(":instrumentation:spring:spring-boot-autoconfigure")) implementation(project(":instrumentation:resources:library")) + implementation(project(":instrumentation:spring:spring-boot-resources:library")) api("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi") api("io.opentelemetry:opentelemetry-api") api("io.opentelemetry:opentelemetry-exporter-logging")