Skip to content

Commit

Permalink
Merge pull request #2245 from DataDog/mcculls/avoidBootstrapPrefixInj…
Browse files Browse the repository at this point in the history
…ection

Move Constants#BOOTSTRAP_PACKAGE_PREFIXES to bootstrap
so we can avoid bootstrap injection in ClassloadingInstrumentation
  • Loading branch information
mcculls authored Jan 5, 2021
2 parents 9638117 + c1b2bb0 commit 6b96665
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package datadog.trace.bootstrap;

/**
* Some useful constants.
*
* <p>The idea here is to keep this class safe to inject into client's class loader.
*/
public final class Constants {

/**
* packages which will be loaded on the bootstrap classloader
*
* <p>Updates should be mirrored in
* datadog.trace.agent.test.SpockRunner#BOOTSTRAP_PACKAGE_PREFIXES_COPY
*/
public static final String[] BOOTSTRAP_PACKAGE_PREFIXES = {
"datadog.slf4j",
"datadog.trace.api",
"datadog.trace.bootstrap",
"datadog.trace.context",
"datadog.trace.instrumentation.api",
"datadog.trace.logging",
"datadog.trace.util",
};

private Constants() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public DynamicType.Builder<?> transform(
}

/**
* Note: the value here has to be inside on of the prefixes in
* datadog.trace.agent.tooling.Constants#BOOTSTRAP_PACKAGE_PREFIXES. This ensures that 'isolating'
* (or 'module') classloaders like jboss and osgi see injected classes. This works because we
* Note: the value here has to be inside one of the prefixes in
* datadog.trace.bootstrap.Constants#BOOTSTRAP_PACKAGE_PREFIXES. This ensures that 'isolating' (or
* 'module') classloaders like jboss and osgi see injected classes. This works because we
* instrument those classloaders to load everything inside bootstrap packages.
*/
private static final String DYNAMIC_CLASSES_PACKAGE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Constants;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
import datadog.trace.bootstrap.Constants;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
Expand Down Expand Up @@ -46,11 +46,6 @@ public ElementMatcher<TypeDescription> typeMatcher() {
.and(extendsClass(named("java.lang.ClassLoader")));
}

@Override
public String[] helperClassNames() {
return new String[] {Constants.class.getName()};
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Constants;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.Constants;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
Expand All @@ -31,11 +31,6 @@ public GlassFishInstrumentation() {
super("glassfish");
}

@Override
public String[] helperClassNames() {
return new String[] {Constants.class.getName()};
}

@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return named("com.sun.enterprise.v3.server.APIClassLoaderServiceImpl$APIClassLoader");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,11 @@ public static String getResourceName(final String className) {
public static String[] getBootstrapPackagePrefixes() throws Exception {
final Field f =
getAgentClassLoader()
.loadClass("datadog.trace.agent.tooling.Constants")
.loadClass("datadog.trace.bootstrap.Constants")
.getField("BOOTSTRAP_PACKAGE_PREFIXES");
return (String[]) f.get(null);
}

public static String[] getAgentPackagePrefixes() throws Exception {
final Field f =
getAgentClassLoader()
.loadClass("datadog.trace.agent.tooling.Constants")
.getField("AGENT_PACKAGE_PREFIXES");
return (String[]) f.get(null);
}

private static String getAgentArgument() {
final RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
for (final String arg : runtimeMxBean.getInputArguments()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class SpockRunner extends Sputnik {
/**
* An exact copy of {@link datadog.trace.agent.tooling.Constants#BOOTSTRAP_PACKAGE_PREFIXES}.
* An exact copy of {@link datadog.trace.bootstrap.Constants#BOOTSTRAP_PACKAGE_PREFIXES}.
*
* <p>This list is needed to initialize the bootstrap classpath because Utils' static initializer
* references bootstrap classes (e.g. DatadogClassLoader).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import com.google.common.reflect.ClassPath
import datadog.trace.agent.test.AgentTestRunner
import datadog.trace.agent.test.SpockRunner
import datadog.trace.agent.test.utils.ClasspathUtils
import datadog.trace.agent.tooling.Constants
import datadog.trace.api.GlobalTracer
import datadog.trace.bootstrap.Constants
import datadog.trace.bootstrap.instrumentation.api.AgentScope
import datadog.trace.bootstrap.instrumentation.api.AgentSpan
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
Expand Down

0 comments on commit 6b96665

Please sign in to comment.