Small ReferenceCreator cleanup (#972)

This commit is contained in:
Trask Stalnaker 2020-08-16 10:13:10 -07:00 committed by GitHub
parent 5b43e328f5
commit 88eef8934e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 13 deletions

View File

@ -48,8 +48,10 @@ public class ReferenceCreator extends ClassVisitor {
* <p>For now we're hardcoding this to the instrumentation package so we only create references
* from the method advice and helper classes.
*/
private static final String[] REFERENCE_CREATION_PACKAGE = {
"io.opentelemetry.instrumentation.auto.", "io.opentelemetry.instrumentation."
private static final String REFERENCE_CREATION_PACKAGE = "io.opentelemetry.instrumentation.";
private static final String[] REFERENCE_CREATION_PACKAGE_EXCLUDES = {
"io.opentelemetry.instrumentation.api.", "io.opentelemetry.instrumentation.auto.api."
};
/**
@ -82,17 +84,8 @@ public class ReferenceCreator extends ClassVisitor {
for (Map.Entry<String, Reference> entry : instrumentationReferences.entrySet()) {
String key = entry.getKey();
// Don't generate references created outside of the instrumentation package.
if (!visitedSources.contains(entry.getKey())) {
for (String pkg : REFERENCE_CREATION_PACKAGE) {
// TODO (trask) clean up during
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/754
if (key.startsWith(pkg)
&& !key.startsWith("io.opentelemetry.instrumentation.auto.api.")
&& !key.startsWith("io.opentelemetry.instrumentation.api.")) {
instrumentationQueue.add(key);
break;
}
}
if (!visitedSources.contains(entry.getKey()) && isInReferenceCreationPackage(key)) {
instrumentationQueue.add(key);
}
if (references.containsKey(key)) {
references.put(key, references.get(key).merge(entry.getValue()));
@ -116,6 +109,18 @@ public class ReferenceCreator extends ClassVisitor {
return references;
}
private static boolean isInReferenceCreationPackage(String className) {
if (!className.startsWith(REFERENCE_CREATION_PACKAGE)) {
return false;
}
for (String exclude : REFERENCE_CREATION_PACKAGE_EXCLUDES) {
if (className.startsWith(exclude)) {
return false;
}
}
return true;
}
/**
* Get the package of an internal class name.
*