Allow excluding all methods of a class (#10753)

This commit is contained in:
Lauri Tulmin 2024-03-08 09:37:01 +02:00 committed by GitHub
parent 4fc3bab5d1
commit 52dcd30993
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 12 deletions

View File

@ -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 final class MethodsConfigurationParser {
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();

View File

@ -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()]