Skip to content

Commit 03d2ac3

Browse files
committed
added regular expression matching to suspend ignores
1 parent 0fd0008 commit 03d2ac3

File tree

1 file changed

+16
-8
lines changed
  • Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines

1 file changed

+16
-8
lines changed

Kotlin-Coroutines-Suspends/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/SuspendIgnores.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ public class SuspendIgnores {
1313

1414
private static final List<String> ignoredSuspends = new ArrayList<String>();
1515
private static final String SUSPENDSIGNORECONFIG = "Coroutines.ignores.suspends";
16+
private static final List<String> ignoredPackages = new ArrayList<>();
1617

1718
static {
1819
Config config = NewRelic.getAgent().getConfig();
1920
String value = config.getValue(SUSPENDSIGNORECONFIG);
2021
init(value);
21-
22+
ignoredPackages.add("kotlin.coroutines");
23+
ignoredPackages.add("kotlinx.coroutines");
2224
}
2325

2426
private static void init(String value) {
@@ -45,24 +47,30 @@ public static void addIgnore(String s) {
4547

4648
public static boolean ignoreSuspend(Object obj) {
4749
String objString = obj.toString();
48-
String className = obj.getClass().getName();
49-
NewRelic.getAgent().getLogger().log(Level.FINE, "Call to SuspendIgnores.ignoreSuspend, objString = {0}, className = {1}" , objString, className);
50+
Class<?> clazz = obj.getClass();
51+
String className = clazz.getName();
52+
String packageName = clazz.getPackage().getName();
53+
54+
for(String ignored : ignoredPackages) {
55+
if(packageName.startsWith(ignored)) {
56+
return true;
57+
}
58+
}
59+
60+
boolean objStringMatch = ignoredSuspends.contains(objString);
61+
boolean classNameMatch = ignoredSuspends.contains(className);
5062

51-
if(ignoredSuspends.contains(objString) || ignoredSuspends.contains(className)) {
52-
NewRelic.getAgent().getLogger().log(Level.FINE, "Matched classname or objString");
63+
if(objStringMatch || classNameMatch) {
5364
return true;
5465
}
5566

5667
for(String s : ignoredSuspends) {
57-
NewRelic.getAgent().getLogger().log(Level.FINE, "Comparing to regex {0}", s);
5868
Pattern pattern = Pattern.compile(s);
5969
Matcher matcher1 = pattern.matcher(objString);
6070
Matcher matcher2 = pattern.matcher(className);
61-
NewRelic.getAgent().getLogger().log(Level.FINE, matcher1.matches() ? "Matched objString" : matcher2.matches() ? "Matched Classname" : "not a match for object string or classname");
6271
if(matcher1.matches() || matcher2.matches()) return true;
6372
}
6473

6574
return false;
66-
// return ignoredSuspends.contains(obj.toString()) || ignoredSuspends.contains(obj.getClass().getName());
6775
}
6876
}

0 commit comments

Comments
 (0)