Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,16 @@ public void registerHelperResources(HelperResourceBuilder helperResourceBuilder)
// this line will make OpenTelemetryMeterRegistryAutoConfiguration available to all
// classloaders, so that the bean class loader (different from the instrumented class loader)
// can load it
if (!isIndyModule()) {
// For indy module the proxy-bytecode will be injected as resource by injectClasses()
helperResourceBuilder.registerForAllClassLoaders(
"io/opentelemetry/javaagent/instrumentation/spring/actuator/v2_0/OpenTelemetryMeterRegistryAutoConfiguration.class");
}
helperResourceBuilder.registerForAllClassLoaders(
"io/opentelemetry/javaagent/instrumentation/spring/actuator/v2_0/OpenTelemetryMeterRegistryAutoConfiguration.class");
}

@Override
public void injectClasses(ClassInjector injector) {
injector
.proxyBuilder(
"io.opentelemetry.javaagent.instrumentation.spring.actuator.v2_0.OpenTelemetryMeterRegistryAutoConfiguration")
.inject(InjectionMode.CLASS_AND_RESOURCE);
.inject(InjectionMode.CLASS_ONLY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,12 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {

@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");
}
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,12 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {

@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");
}
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean isHelperClass(String className) {
public void injectClasses(ClassInjector injector) {
injector
.proxyBuilder("org.springframework.web.servlet.v3_1.OpenTelemetryHandlerMappingFilter")
.inject(InjectionMode.CLASS_AND_RESOURCE);
.inject(InjectionMode.CLASS_ONLY);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this means that the helperResourceBuilder.register(...) call in registerHelperResources is now used to inject the class as a resource and thus we can use CLASS_ONLY ?

If so, does it means that if we promote the injectClasses method later with #16975 we will thus do the opposite change and use only injectClasses to inject the class as class (proxy) and as a resource ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this means that the helperResourceBuilder.register(...) call in registerHelperResources is now used to inject the class as a resource and thus we can use CLASS_ONLY ?

yes, now the resource is registered the same way for indy and non-indy instrumentation

If so, does it means that if we promote the injectClasses method later with #16975 we will thus do the opposite change and use only injectClasses to inject the class as class (proxy) and as a resource ?

I want to try out whether we can replace proxy injection with something simpler.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
package io.opentelemetry.javaagent.instrumentation.spring.webmvc.v3_1.boot;

import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION;
import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.collect.ImmutableMap;
import io.opentelemetry.instrumentation.spring.webmvc.boot.AbstractSpringBootBasedTest;
import io.opentelemetry.instrumentation.spring.webmvc.boot.AppConfig;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
Expand Down Expand Up @@ -66,4 +68,14 @@ protected boolean shouldTestDeferredResult() {
// resulting in a separate trace instead of a single trace
return Boolean.getBoolean("testLatestDeps");
}

@Test
void handlerMappingFilterResourceAvailable() {
assertThat(
getClass()
.getClassLoader()
.getResource(
"org/springframework/web/servlet/v3_1/OpenTelemetryHandlerMappingFilter.class"))
.isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean isHelperClass(String className) {
public void injectClasses(ClassInjector injector) {
injector
.proxyBuilder("org.springframework.web.servlet.v6_0.OpenTelemetryHandlerMappingFilter")
.inject(InjectionMode.CLASS_AND_RESOURCE);
.inject(InjectionMode.CLASS_ONLY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.spring.webmvc.boot.AbstractSpringBootBasedTest;
Expand All @@ -24,6 +25,7 @@
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.StatusData;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
Expand Down Expand Up @@ -111,4 +113,14 @@ protected void configure(HttpServerTestOptions options) {
options.setResponseCodeOnNonStandardHttpMethod(400);
options.setExpectedException(new RuntimeException(EXCEPTION.getBody()));
}

@Test
void handlerMappingFilterResourceAvailable() {
assertThat(
getClass()
.getClassLoader()
.getResource(
"org/springframework/web/servlet/v6_0/OpenTelemetryHandlerMappingFilter.class"))
.isNotNull();
}
}
Loading