Remove JAR checker cause we have a graceful exception
DELETE
dd-java-agent/src/main/java/io/opentracing/contrib/agent/JarVersionsChecker.java
-package io.opentracing.contrib.agent;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import com.datadoghq.trace.resolver.FactoryUtils;
-
-
-/**
- * Utility class to check the validity of the classpath concerning the java automated instrumentations
- */
-public class JarVersionsChecker {
-
- private static Logger log = Logger.getLogger(JarVersionsChecker.class.getName());
-
- public static String AUTHORIZED_VERSIONS_CONFIG ="dd-trace-authorized-versions.yaml";
-
- /**
- * Retrieves all the jars from the classpath
- */
- private static List<File> getJarsFromClasspath() {
- return JarVersionsChecker.getJarFiles(System.getProperty("java.class.path"));
- }
-
- /**
- * list files in the given directory and subdirs (with recursion)
- * @param paths
- * @return
- */
- public static List<File> getJarFiles(String paths) {
- List<File> filesList = new ArrayList<File>();
- for (final String path : paths.split(File.pathSeparator)) {
- final File file = new File(path);
- if( file.isDirectory()) {
- recurse(filesList, file);
- }
- else {
- if(file.getName().endsWith(".jar")){
- filesList.add(file);
- }
- }
- }
- return filesList;
- }
-
- private static void recurse(List<File> filesList, File f) {
- File list[] = f.listFiles();
- for (File file : list) {
- getJarFiles(file.getPath());
- }
- }
-
- public static Pattern versionPattern = Pattern.compile("-(\\d+\\..+)\\.jar");
- public static String extractJarVersion(String jarName){
- Matcher matcher = versionPattern.matcher(jarName);
- if (matcher.find())
- return matcher.group(1);
- else
- return null;
-
- }
-
-
- public static void main(String args[]) throws Exception {
- checkJarVersions();
- }
-
- /**
- * Check all Jar versions in the classpath
- *
- * @return the list of jar keys that have been detected as potential issues
- */
- @SuppressWarnings("unchecked")
- public static List<String> checkJarVersions() {
- List<String> potentialIssues = new ArrayList<>();
-
- //Load instrumentations versions
- Map<String, Map<String,String>> versions = FactoryUtils.loadConfigFromResource(AUTHORIZED_VERSIONS_CONFIG, Map.class);
- if(versions==null){
- log.log(Level.WARNING, "DD agent: Authorized versions configuration file {} not found in classpath. Cannot proceed to the Jar versions check.",AUTHORIZED_VERSIONS_CONFIG);
- return potentialIssues;
- }
-
- //Scan classpath provided jars
- List<File> jars = getJarsFromClasspath();
- for (File file: jars) {
- String jarName = file.getName();
- String versionRestrictions = extractJarVersion(jarName);
-
- if(versionRestrictions!=null){
- //Extract artifactId
- String artifactId = file.getName().substring(0, jarName.indexOf(versionRestrictions)-1);
- Map<String,String> restrictions = versions.get(artifactId);
- if(restrictions!=null){
- String versionPattern = restrictions.get("valid_versions");
- if(versionPattern!=null){
- if(!Pattern.matches(versionPattern, versionRestrictions)){
- String key = restrictions.get("key");
- if(key!=null){
- potentialIssues.add(key);
- }
- log.log(Level.WARNING, "DD agent: The JAR {0} has been found in the classpath. It may create some intrumentation issue, some rules are about to get disabled.",jarName);
- }
- }
- }
- }
- }
- return potentialIssues;
- }
-
-
-}
\ No newline at end of file

MODIFY
dd-java-agent/src/main/java/io/opentracing/contrib/agent/TraceAnnotationsManager.java
dd-java-agent/src/main/java/io/opentracing/contrib/agent/TraceAnnotationsManager.java
package io.opentracing.contrib.agent;
+import com.datadoghq.trace.resolver.AgentTracerConfig;
+import com.datadoghq.trace.resolver.DDTracerFactory;
+import com.datadoghq.trace.resolver.FactoryUtils;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.bytecode.Descriptor;
+import org.jboss.byteman.agent.Location;
+import org.jboss.byteman.agent.LocationType;
+import org.jboss.byteman.agent.Retransformer;
+import org.jboss.byteman.agent.RuleScript;
+import org.reflections.Reflections;
+import org.reflections.scanners.MethodAnnotationsScanner;
+import org.reflections.util.ConfigurationBuilder;
+import org.reflections.util.FilterBuilder;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
@@ -8,35 +24,12 @@ import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.jboss.byteman.agent.Location;
-import org.jboss.byteman.agent.LocationType;
-import org.jboss.byteman.agent.Retransformer;
-import org.jboss.byteman.agent.RuleScript;
-import org.reflections.Reflections;
-import org.reflections.scanners.MethodAnnotationsScanner;
-import org.reflections.util.ConfigurationBuilder;
-import org.reflections.util.FilterBuilder;
-
-import com.datadoghq.trace.resolver.AgentTracerConfig;
-import com.datadoghq.trace.resolver.DDTracerFactory;
-import com.datadoghq.trace.resolver.FactoryUtils;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtMethod;
-import javassist.bytecode.Descriptor;
-
/**
* This manager is loaded at pre-main.
*
@@ -63,7 +56,7 @@ public class TraceAnnotationsManager {
List<String> loadedScripts = loadRules(ClassLoader.getSystemClassLoader());
//Check if some rules have to be uninstalled
- List<String> uninstallScripts = JarVersionsChecker.checkJarVersions();
+ List<String> uninstallScripts = new ArrayList<>();
if(agentTracerConfig != null){
List<String> disabledInstrumentations = agentTracerConfig.getDisabledInstrumentations();
if(disabledInstrumentations!=null && !disabledInstrumentations.isEmpty()){
@@ -270,7 +263,7 @@ public class TraceAnnotationsManager {
log.log(Level.WARNING, "Error when building injection rule on method " + javassistMethod + ". Fallback on default value.", e);
}
return BUILD_SPAN+javassistMethod.getName()+CLOSE_PARENTHESIS;
- };
+ }
private static String buildWithTags(CtMethod javassistMethod){
try {
@@ -292,5 +285,5 @@ public class TraceAnnotationsManager {
log.log(Level.WARNING, "Error when building injection rule on method " + javassistMethod + ". Fallback on default value.", e);
}
return "";
- };
+ }
}

DELETE
dd-java-agent/src/main/resources/dd-trace-authorized-versions.yaml
-okhttp:
- key: okhttp
- valid_versions: 3\..*
-httpclient:
- key: apache http
- valid_versions: 4\.[3|4|5]\..*
-commons-httpclient:
- key: apache http
- valid_versions: none
-aws-java-sdk:
- key: aws
- valid_versions: 1\.11\..*
-jetty-server:
- key: jetty
- valid_versions: (8\.|9\.).*
-tomcat-embed-core:
- key: tomcat
- valid_versions: (8\.|9\.).*
-tomcat_catalina:
- key: tomcat
- valid_versions: (8\.|9\.).*
-spring_jdbc:
- key: jdbc
- valid_versions: 4\..*
-hibernate-core:
- key: jdbc
- valid_versions: 5\..*
-mongo-java-driver:
- key: mongo
- valid_versions: 3\..*
-opentracing-api:
- key: opentracing-api
- valid_versions: 0\.2.*
-cassandra-driver-core:
- key: cassandra
- valid_versions: 3\.2.*
-
-
\ No newline at end of file

Remove JAR checker cause we have a graceful exception