Skip to content
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

Allow dynamic import for io.opentelemetry when matching #10385

Merged
merged 1 commit into from
Feb 3, 2024
Merged
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 @@ -23,7 +23,8 @@
*
* <p>Any side-effect of the ClassLoaderMatcher's call to ClassLoader.getResource() is generally
* undesirable, and so this instrumentation patches the behavior and suppresses the "dynamic import"
* of the missing package/bundle when the call is originating from ClassLoaderMatcher..
* of the missing package/bundle when the call is originating from ClassLoaderMatcher, unless the
* request is for a package for which we explicitly allow the dynamic imports.
*/
class EclipseOsgiInstrumentation implements TypeInstrumentation {

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

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
Expand Down
Loading