Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow excluding all methods of a class #10753

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading