Skip to content

Commit bb12290

Browse files
authored
Allow dynamic import for io.opentelemetry when matching (#10385)
1 parent 19dc10d commit bb12290

File tree

1 file changed

+6
-3
lines changed
  • instrumentation/internal/internal-eclipse-osgi-3.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/osgi

1 file changed

+6
-3
lines changed

instrumentation/internal/internal-eclipse-osgi-3.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/osgi/EclipseOsgiInstrumentation.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
*
2424
* <p>Any side-effect of the ClassLoaderMatcher's call to ClassLoader.getResource() is generally
2525
* undesirable, and so this instrumentation patches the behavior and suppresses the "dynamic import"
26-
* of the missing package/bundle when the call is originating from ClassLoaderMatcher..
26+
* of the missing package/bundle when the call is originating from ClassLoaderMatcher, unless the
27+
* request is for a package for which we explicitly allow the dynamic imports.
2728
*/
2829
class EclipseOsgiInstrumentation implements TypeInstrumentation {
2930

@@ -45,8 +46,10 @@ public static class IsDynamicallyImportedAdvice {
4546
// "skipOn" is used to skip execution of the instrumented method when a ClassLoaderMatcher is
4647
// currently executing, since we will be returning false regardless in onExit below
4748
@Advice.OnMethodEnter(skipOn = Advice.OnNonDefaultValue.class, suppress = Throwable.class)
48-
public static boolean onEnter() {
49-
return InClassLoaderMatcher.get();
49+
public static boolean onEnter(@Advice.Argument(0) String packageName) {
50+
// disable dynamic imports for everything except io.opentelemetry classes to allow dynamic
51+
// import of @WithSpan etc.
52+
return InClassLoaderMatcher.get() && !packageName.startsWith("io.opentelemetry.");
5053
}
5154

5255
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)

0 commit comments

Comments
 (0)