66import com .newrelic .agent .config .AgentConfigListener ;
77import com .newrelic .agent .service .ServiceFactory ;
88import com .newrelic .agent .tracers .*;
9+ import com .newrelic .api .agent .Config ;
10+ import com .newrelic .api .agent .NewRelic ;
911import kotlin .coroutines .Continuation ;
1012import kotlinx .coroutines .AbstractCoroutine ;
1113
1214import java .util .Arrays ;
1315import java .util .HashSet ;
16+ import java .util .logging .Level ;
17+ import java .util .regex .Pattern ;
1418
1519public class SuspendsUtils implements AgentConfigListener {
1620
1721 private static final HashSet <String > ignoredSuspends = new HashSet <>();
22+ private static final HashSet <Pattern > ignoredRegexSuspends = new HashSet <>();
1823 public static final String CREATE_METHOD1 = "Continuation at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4" ;
1924 public static final String CREATE_METHOD2 = "Continuation at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$3" ;
2025 private static final String CONT_LOC = "Continuation at" ;
2126 public static String sub = "createCoroutineFromSuspendFunction" ;
2227 public static final String KOTLIN_PACKAGE = "kotlin" ;
2328 private static final String SUSPEND_FUNCTION_METRIC_NAME_PREFIX = "Custom/Kotlin/Coroutines/SuspendFunction/" ;
24- private static final String SUSPENDSIGNORECONFIG = "Coroutines.ignores.suspends" ;
29+ private static final String SUSPENDSIGNORECONFIG = "coroutines.suspends.ignore" ;
30+ private static final String SUSPENDSREGEXIGNORECONFIG = "coroutines.suspends.ignoreRegex" ;
2531
2632 static {
2733 ServiceFactory .getConfigService ().addIAgentConfigListener (new SuspendsUtils ());
34+ Config agentConfig = NewRelic .getAgent ().getConfig ();
35+ String value = agentConfig .getValue (SUSPENDSIGNORECONFIG );
36+ NewRelic .getAgent ().getLogger ().log (Level .FINE ,"Value of {0} is {1}" , SUSPENDSIGNORECONFIG , value );
37+ if (value != null ) {
38+ ignoredSuspends .clear ();
39+ String [] split = value .split ("," );
40+ if (split .length > 0 ) {
41+ ignoredSuspends .addAll (Arrays .asList (split ));
42+ }
43+ }
44+ value = agentConfig .getValue (SUSPENDSREGEXIGNORECONFIG );
45+ NewRelic .getAgent ().getLogger ().log (Level .FINE ,"Value of {0} is {1}" , SUSPENDSREGEXIGNORECONFIG , value );
46+ if (value != null ) {
47+ ignoredRegexSuspends .clear ();
48+ String [] split = value .split ("," );
49+ if (split .length > 0 ) {
50+ for (String ignoredRegex : split ) {
51+ NewRelic .getAgent ().getLogger ().log (Level .FINE ,"Will ignore suspends matching {0}" , ignoredRegex );
52+ ignoredRegexSuspends .add (Pattern .compile (ignoredRegex ));
53+ }
54+ }
55+ }
56+
2857 }
2958
3059 private SuspendsUtils () {}
@@ -38,8 +67,10 @@ public static ExitTracer getSuspendTracer(Continuation<?> continuation) {
3867 // ignore if can't determine continuation string
3968 if (continuationString == null || continuationString .isEmpty ()) { return null ; }
4069
41- for (String ignoredSuspend : ignoredSuspends ) {
42- if (continuationString .matches (ignoredSuspend ) || className .matches (ignoredSuspend )) { return null ; }
70+ for (Pattern ignoredSuspend : ignoredRegexSuspends ) {
71+ if (ignoredSuspend .matcher (continuationString ).matches () || ignoredSuspend .matcher (className ).matches ()) {
72+ return null ;
73+ }
4374 }
4475 if (ignoredSuspends .contains (continuationString ) || ignoredSuspends .contains (className )) {
4576 return null ;
@@ -83,11 +114,25 @@ public static <T> String getContinuationString(Continuation<T> continuation) {
83114 @ Override
84115 public void configChanged (String s , AgentConfig agentConfig ) {
85116 String value = agentConfig .getValue (SUSPENDSIGNORECONFIG );
117+ NewRelic .getAgent ().getLogger ().log (Level .FINE ,"Value of {0} is {1}" , SUSPENDSIGNORECONFIG , value );
86118 if (value != null ) {
119+ ignoredSuspends .clear ();
87120 String [] split = value .split ("," );
88121 if (split .length > 0 ) {
89122 ignoredSuspends .addAll (Arrays .asList (split ));
90123 }
91124 }
125+ value = agentConfig .getValue (SUSPENDSREGEXIGNORECONFIG );
126+ NewRelic .getAgent ().getLogger ().log (Level .FINE ,"Value of {0} is {1}" , SUSPENDSREGEXIGNORECONFIG , value );
127+ if (value != null ) {
128+ ignoredRegexSuspends .clear ();
129+ String [] split = value .split ("," );
130+ if (split .length > 0 ) {
131+ for (String ignoredRegex : split ) {
132+ NewRelic .getAgent ().getLogger ().log (Level .FINE ,"Will ignore suspends matching {0}" , ignoredRegex );
133+ ignoredRegexSuspends .add (Pattern .compile (ignoredRegex ));
134+ }
135+ }
136+ }
92137 }
93138}
0 commit comments