Do not instrument exporter class loader (#306)

This commit is contained in:
Trask Stalnaker 2020-04-04 09:29:36 -07:00 committed by GitHub
parent 7bc48ead58
commit e0589e18fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -57,6 +57,8 @@ public final class ClassLoaderMatcher {
CacheBuilder.newBuilder().weakKeys().concurrencyLevel(CACHE_CONCURRENCY).build();
private static final String AGENT_CLASSLOADER_NAME =
"io.opentelemetry.auto.bootstrap.AgentClassLoader";
private static final String EXPORTER_CLASSLOADER_NAME =
"io.opentelemetry.auto.tooling.ExporterClassLoader";
private SkipClassLoaderMatcher() {}
@ -92,6 +94,7 @@ public final class ClassLoaderMatcher {
case "org.apache.cxf.common.util.ASMHelper$TypeHelperClassLoader":
case "sun.misc.Launcher$ExtClassLoader":
case AGENT_CLASSLOADER_NAME:
case EXPORTER_CLASSLOADER_NAME:
return true;
}
return false;

View File

@ -17,6 +17,7 @@ package io.opentelemetry.auto.test
import io.opentelemetry.auto.bootstrap.AgentClassLoader
import io.opentelemetry.auto.tooling.ClassLoaderMatcher
import io.opentelemetry.auto.tooling.ExporterClassLoader
import io.opentelemetry.auto.util.test.AgentSpecification
class ClassLoaderMatcherTest extends AgentSpecification {
@ -29,6 +30,13 @@ class ClassLoaderMatcherTest extends AgentSpecification {
ClassLoaderMatcher.skipClassLoader().matches(agentLoader)
}
def "skips exporter classloader"() {
setup:
final URLClassLoader exporterLoader = new ExporterClassLoader(new URL[0], null)
expect:
ClassLoaderMatcher.skipClassLoader().matches(exporterLoader)
}
def "does not skip empty classloader"() {
setup:
final ClassLoader emptyLoader = new ClassLoader() {}
@ -45,4 +53,9 @@ class ClassLoaderMatcherTest extends AgentSpecification {
expect:
AgentClassLoader.name == "io.opentelemetry.auto.bootstrap.AgentClassLoader"
}
def "ExporterClassLoader class name is hardcoded in ClassLoaderMatcher"() {
expect:
ExporterClassLoader.name == "io.opentelemetry.auto.tooling.ExporterClassLoader"
}
}