Skip to content

Commit

Permalink
Allow excluding all methods of a class (open-telemetry#10753)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Mar 8, 2024
1 parent 4fc3bab commit 52dcd30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,6 +46,10 @@ public static Map<String, Set<String>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {
Expand All @@ -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()]
Expand Down

0 comments on commit 52dcd30

Please sign in to comment.