diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParser.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParser.java index a834d06361ce..44658f6e5672 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParser.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParser.java @@ -18,18 +18,10 @@ public final class MethodsConfigurationParser { private static final Logger logger = Logger.getLogger(MethodsConfigurationParser.class.getName()); - static final String PACKAGE_CLASS_NAME_REGEX = "[\\w.$]+"; - private static final String METHOD_LIST_REGEX = "\\s*(?:\\w+\\s*,)*\\s*(?:\\w+\\s*,?)\\s*"; + private static final String PACKAGE_CLASS_NAME_REGEX = "[\\w.$]+"; + private static final String METHOD_LIST_REGEX = "(?:\\s*\\w+\\s*,)*+(?:\\s*\\w+)?\\s*"; private static final String CONFIG_FORMAT = - "(?:\\s*" - + PACKAGE_CLASS_NAME_REGEX - + "\\[" - + METHOD_LIST_REGEX - + "]\\s*;)*\\s*" - + PACKAGE_CLASS_NAME_REGEX - + "\\[" - + METHOD_LIST_REGEX - + "]"; + PACKAGE_CLASS_NAME_REGEX + "(?:\\[" + METHOD_LIST_REGEX + "])?"; /** * This method takes a string in a form of {@code @@ -54,6 +46,10 @@ public static Map> parse(String configString) { if (classMethod.trim().isEmpty()) { continue; } + if (!classMethod.contains("[")) { + toTrace.put(classMethod.trim(), Collections.emptySet()); + continue; + } String[] splitClassMethod = classMethod.split("\\[", -1); String className = splitClassMethod[0]; String method = splitClassMethod[1].trim(); diff --git a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParserTest.groovy b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParserTest.groovy index 3f8cbf4c9bca..1fe11b29b7f4 100644 --- a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParserTest.groovy +++ b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/config/MethodsConfigurationParserTest.groovy @@ -8,6 +8,8 @@ package io.opentelemetry.javaagent.tooling.config import spock.lang.Specification +import static java.util.Collections.emptySet + class MethodsConfigurationParserTest extends Specification { def "test configuration #value"() { @@ -18,7 +20,7 @@ class MethodsConfigurationParserTest extends Specification { value | expected null | [:] " " | [:] - "some.package.ClassName" | [:] + "some.package.ClassName" | ["some.package.ClassName":emptySet()] "some.package.ClassName[ , ]" | [:] "some.package.ClassName[ , method]" | [:] "some.package.Class\$Name[ method , ]" | ["some.package.Class\$Name": ["method"].toSet()]