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 @@ -17,9 +17,11 @@
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import io.opentelemetry.javaagent.bootstrap.BootstrapPackagePrefixesHolder;
import io.opentelemetry.javaagent.bootstrap.CallDepth;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.util.List;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.description.method.MethodDescription;
Expand Down Expand Up @@ -68,7 +70,13 @@ public void transform(TypeTransformer transformer) {
public static class LoadClassAdvice {

@Advice.OnMethodEnter(skipOn = Advice.OnNonDefaultValue.class)
public static Class<?> onEnter(@Advice.Argument(0) String name) {
public static Class<?> onEnter(
@Advice.This ClassLoader classLoader, @Advice.Argument(0) String name) {
// must be read before call depth is incremented as setting the call depth prevents the class
// loader of the instrumented class from loading BootstrapPackagePrefixesHolder itself
List<String> bootstrapPackagePrefixes =
BootstrapPackagePrefixesHolder.getBootstrapPackagePrefixes();

// need to use call depth here to prevent re-entry from call to Class.forName() below
// because on some JVMs (e.g. IBM's, though IBM bootstrap loader is explicitly excluded above)
// Class.forName() ends up calling loadClass() on the bootstrap loader which would then come
Expand All @@ -80,7 +88,7 @@ public static Class<?> onEnter(@Advice.Argument(0) String name) {
}

try {
for (String prefix : BootstrapPackagesHelper.bootstrapPackagesPrefixes) {
for (String prefix : bootstrapPackagePrefixes) {
if (name.startsWith(prefix)) {
try {
return Class.forName(name, false, null);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.util.Arrays;
import java.util.List;

@AutoService(InstrumentationModule.class)
Expand All @@ -28,13 +27,6 @@ public boolean defaultEnabled(ConfigProperties config) {
return true;
}

@Override
public List<String> getAdditionalHelperClassNames() {
return Arrays.asList(
"io.opentelemetry.javaagent.instrumentation.internal.classloader.BootstrapPackagesHelper",
"io.opentelemetry.javaagent.tooling.Constants");
}

@Override
public List<String> injectedClassNames() {
return getAdditionalHelperClassNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class BootstrapPackagePrefixesHolder {

private static volatile List<String> bootstrapPackagePrefixes;

public static List<String> getBoostrapPackagePrefixes() {
public static List<String> getBootstrapPackagePrefixes() {
return bootstrapPackagePrefixes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AgentInstrumentationTest {

private static final ClassLoader BOOTSTRAP_CLASSLOADER = null;
private static final List<String> BOOTSTRAP_PACKAGE_PREFIXES =
BootstrapPackagePrefixesHolder.getBoostrapPackagePrefixes();
BootstrapPackagePrefixesHolder.getBootstrapPackagePrefixes();

@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
Expand Down