From a5806c600bb35e202a191543631d32bf334b421f Mon Sep 17 00:00:00 2001 From: Sylvain Juge <763082+SylvainJuge@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:49:54 +0100 Subject: [PATCH] keep registerHelperResources for inlined --- .../v3_1/SpringWebInstrumentationModule.java | 16 ++++++++++++++++ .../web/v6_0/SpringWebInstrumentationModule.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/instrumentation/spring/spring-web/spring-web-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springweb/v3_1/SpringWebInstrumentationModule.java b/instrumentation/spring/spring-web/spring-web-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springweb/v3_1/SpringWebInstrumentationModule.java index bafcb24794cf..f257f527177a 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springweb/v3_1/SpringWebInstrumentationModule.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springweb/v3_1/SpringWebInstrumentationModule.java @@ -10,6 +10,7 @@ import static net.bytebuddy.matcher.ElementMatchers.not; import com.google.auto.service.AutoService; +import io.opentelemetry.javaagent.extension.instrumentation.HelperResourceBuilder; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule; @@ -31,6 +32,21 @@ public ElementMatcher.Junction classLoaderMatcher() { .and(not(hasClassesNamed("org.springframework.web.ErrorResponse"))); } + @Override + public void registerHelperResources(HelperResourceBuilder helperResourceBuilder) { + if (!isIndyModule()) { + // make the filter class file loadable by ClassPathResource - in some cases (e.g. + // spring-guice, + // see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7428) + // Spring + // might want to read the class file metadata; this line will make the filter class file + // visible + // to the bean class loader + helperResourceBuilder.register( + "org/springframework/web/servlet/v3_1/OpenTelemetryHandlerMappingFilter.class"); + } + } + @Override public String getModuleGroup() { // depends on OpenTelemetryHandlerMappingFilter diff --git a/instrumentation/spring/spring-web/spring-web-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/web/v6_0/SpringWebInstrumentationModule.java b/instrumentation/spring/spring-web/spring-web-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/web/v6_0/SpringWebInstrumentationModule.java index 756c9a1f23e6..6a66e70cd866 100644 --- a/instrumentation/spring/spring-web/spring-web-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/web/v6_0/SpringWebInstrumentationModule.java +++ b/instrumentation/spring/spring-web/spring-web-6.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/spring/web/v6_0/SpringWebInstrumentationModule.java @@ -9,6 +9,7 @@ import static java.util.Collections.singletonList; import com.google.auto.service.AutoService; +import io.opentelemetry.javaagent.extension.instrumentation.HelperResourceBuilder; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule; @@ -29,6 +30,21 @@ public ElementMatcher.Junction classLoaderMatcher() { return hasClassesNamed("org.springframework.web.ErrorResponse"); } + @Override + public void registerHelperResources(HelperResourceBuilder helperResourceBuilder) { + if (!isIndyModule()) { + // make the filter class file loadable by ClassPathResource - in some cases (e.g. + // spring-guice, + // see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7428) + // Spring + // might want to read the class file metadata; this line will make the filter class file + // visible + // to the bean class loader + helperResourceBuilder.register( + "org/springframework/web/servlet/v6_0/OpenTelemetryHandlerMappingFilter.class"); + } + } + @Override public String getModuleGroup() { // depends on OpenTelemetryHandlerMappingFilter