Skip to content

Commit 521dffa

Browse files
committed
added regex ignore capabilities
1 parent dfbe1cb commit 521dffa

File tree

9 files changed

+54
-1
lines changed

9 files changed

+54
-1
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
// Build.gradle generated for instrumentation module Kotlin-Coroutines-Core
3+
4+
apply plugin: 'java'
5+
6+
dependencies {
7+
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.4.0'
8+
9+
// New Relic Java Agent dependencies
10+
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.1'
11+
implementation 'com.newrelic.agent.java:newrelic-api:6.4.1'
12+
implementation fileTree(include: ['*.jar'], dir: '../libs')
13+
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
14+
}
15+
16+
jar {
17+
manifest {
18+
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.Kotlin-Coroutines-Suspends'
19+
attributes 'Implementation-Vendor': 'New Relic Labs'
20+
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
21+
attributes 'Implementation-Version': 2.0
22+
attributes 'Agent-Class': 'com.newrelic.instrumentation.kotlin.coroutines.tracing.CoroutinesPreMain'
23+
}
24+
}
25+
26+
verifyInstrumentation {
27+
// Verifier plugin documentation:
28+
// https://github.com/newrelic/newrelic-gradle-verify-instrumentation
29+
// Example:
30+
// passes 'javax.servlet:servlet-api:[2.2,2.5]'
31+
// exclude 'javax.servlet:servlet-api:2.4.public_draft'
32+
}

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.ArrayList;
44
import java.util.List;
55
import java.util.logging.Level;
6+
import java.util.regex.Matcher;
7+
import java.util.regex.Pattern;
68

79
import com.newrelic.api.agent.Config;
810
import com.newrelic.api.agent.NewRelic;
@@ -42,6 +44,25 @@ public static void addIgnore(String s) {
4244
}
4345

4446
public static boolean ignoreSuspend(Object obj) {
45-
return ignoredSuspends.contains(obj.toString()) || ignoredSuspends.contains(obj.getClass().getName());
47+
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+
51+
if(ignoredSuspends.contains(objString) || ignoredSuspends.contains(className)) {
52+
NewRelic.getAgent().getLogger().log(Level.FINE, "Matched classname or objString");
53+
return true;
54+
}
55+
56+
for(String s : ignoredSuspends) {
57+
NewRelic.getAgent().getLogger().log(Level.FINE, "Comparing to regex {0}", s);
58+
Pattern pattern = Pattern.compile(s);
59+
Matcher matcher1 = pattern.matcher(objString);
60+
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");
62+
if(matcher1.matches() || matcher2.matches()) return true;
63+
}
64+
65+
return false;
66+
// return ignoredSuspends.contains(obj.toString()) || ignoredSuspends.contains(obj.getClass().getName());
4667
}
4768
}

0 commit comments

Comments
 (0)