Skip to content

Commit 9de5154

Browse files
committed
cleaned up and added ignores
1 parent 65e5458 commit 9de5154

39 files changed

+1550
-428
lines changed

Kotlin-Coroutines_1.2/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ jar {
2222
}
2323

2424
verifyInstrumentation {
25-
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.2.0,)'
25+
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core:[1.2.0,1.4.0)'
26+
passes 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:[1.3.9,1.4.0)'
2627
excludeRegex '.*SNAPSHOT'
2728
excludeRegex '.*alpha'
2829
excludeRegex '.*-eap-.*'
2930
excludeRegex '.*-native-.*'
30-
}
31+
excludeRegex '.*-M[0-9]'
32+
excludeRegex '.*-rc'
33+
}

Kotlin-Coroutines_1.2/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/NRContinuationWrapper.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.newrelic.agent.bridge.AgentBridge;
44
import com.newrelic.api.agent.NewRelic;
5+
import com.newrelic.api.agent.Token;
56
import com.newrelic.api.agent.Trace;
67

78
import kotlin.coroutines.Continuation;
@@ -10,10 +11,12 @@
1011
public class NRContinuationWrapper<T> implements Continuation<T> {
1112

1213
private Continuation<T> delegate = null;
14+
private String name = null;
1315
private static boolean isTransformed = false;
1416

15-
public NRContinuationWrapper(Continuation<T> d) {
17+
public NRContinuationWrapper(Continuation<T> d, String n) {
1618
delegate = d;
19+
name = n;
1720
if(!isTransformed) {
1821
AgentBridge.instrumentation.retransformUninstrumentedClass(getClass());
1922
isTransformed = true;
@@ -26,9 +29,14 @@ public CoroutineContext getContext() {
2629
}
2730

2831
@Override
29-
@Trace(dispatcher=true)
32+
@Trace(async=true)
3033
public void resumeWith(Object p0) {
31-
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","ContinuationWrapper","resumeWith",delegate.getClass().getSimpleName());
34+
35+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","ContinuationWrapper","resumeWith",name != null ? name : Utils.getCoroutineName(getContext(), delegate.getClass()));
36+
Token token = Utils.getToken(getContext());
37+
if(token != null) {
38+
token.link();
39+
}
3240
delegate.resumeWith(p0);
3341
}
3442

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.newrelic.instrumentation.kotlin.coroutines;
2+
3+
import com.newrelic.api.agent.Token;
4+
5+
import kotlin.coroutines.AbstractCoroutineContextElement;
6+
import kotlin.coroutines.CoroutineContext;
7+
8+
public class NRCoroutineToken extends AbstractCoroutineContextElement
9+
{
10+
public static Key key = new Key();
11+
12+
public NRCoroutineToken(Token t) {
13+
super(key);
14+
token = t;
15+
}
16+
17+
private Token token = null;
18+
19+
public static final class Key implements CoroutineContext.Key<NRCoroutineToken> {
20+
private Key() {}
21+
}
22+
23+
public Token getToken() {
24+
return token;
25+
}
26+
27+
@Override
28+
public int hashCode() {
29+
return token.hashCode();
30+
}
31+
32+
@Override
33+
public boolean equals(Object obj) {
34+
if(this != obj ) {
35+
if(obj instanceof NRCoroutineToken) {
36+
NRCoroutineToken t = (NRCoroutineToken)obj;
37+
return t.token == token;
38+
}
39+
} else {
40+
return true;
41+
}
42+
return false;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "NRCoroutineToken";
48+
}
49+
50+
51+
}

Kotlin-Coroutines_1.2/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/NRFunction1Wrapper.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.newrelic.instrumentation.kotlin.coroutines;
22

3-
import java.util.logging.Level;
4-
53
import com.newrelic.agent.bridge.AgentBridge;
64
import com.newrelic.api.agent.NewRelic;
75
import com.newrelic.api.agent.Trace;
@@ -15,7 +13,6 @@ public class NRFunction1Wrapper<P1,R> implements Function1<P1, R> {
1513
private static boolean isTransformed = false;
1614

1715
public NRFunction1Wrapper(Function1<P1, R> d, String n) {
18-
NewRelic.getAgent().getLogger().log(Level.FINE, "Wrapping Function1: {0} using name: {1}", d,n);
1916
delegate = d;
2017
name = n;
2118
if(!isTransformed) {

Kotlin-Coroutines_1.2/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/NRFunction2Wrapper.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package com.newrelic.instrumentation.kotlin.coroutines;
22

3-
import java.util.logging.Level;
4-
53
import com.newrelic.agent.bridge.AgentBridge;
64
import com.newrelic.api.agent.NewRelic;
5+
import com.newrelic.api.agent.Token;
76
import com.newrelic.api.agent.Trace;
87

98
import kotlin.coroutines.Continuation;
10-
import kotlin.coroutines.jvm.internal.BaseContinuationImpl;
119
import kotlin.jvm.functions.Function2;
1210

1311
public class NRFunction2Wrapper<P1, P2, R> implements Function2<P1, P2, R> {
1412

1513
private Function2<P1, P2, R> delegate = null;
1614
private String name = null;
1715
private static boolean isTransformed = false;
16+
public Token token = null;
1817

1918
public NRFunction2Wrapper(Function2<P1, P2, R> d,String n) {
20-
NewRelic.getAgent().getLogger().log(Level.FINE, "Wrapping Function2: {0} - {1} using name: {2}", d, d.getClass().getName(),n);
2119
delegate = d;
2220
name = n;
2321
if(!isTransformed) {
@@ -26,14 +24,22 @@ public NRFunction2Wrapper(Function2<P1, P2, R> d,String n) {
2624
}
2725
}
2826

27+
@SuppressWarnings({ "rawtypes", "unchecked" })
2928
@Override
30-
@Trace(dispatcher=true)
29+
@Trace(async=true)
3130
public R invoke(P1 p1, P2 p2) {
31+
if(token != null) {
32+
token.linkAndExpire();
33+
token = null;
34+
}
3235
String nameStr = null;
3336
if(p2 instanceof Continuation) {
3437
Continuation continuation = (Continuation)p2;
35-
NRContinuationWrapper wrapper = new NRContinuationWrapper(continuation);
36-
p2 = (P2) wrapper;
38+
39+
if (!Utils.ignoreContinuation(name) && !Utils.ignoreContinuation(continuation.getClass(), continuation.getContext())) {
40+
NRContinuationWrapper wrapper = new NRContinuationWrapper(continuation, name);
41+
p2 = (P2) wrapper;
42+
}
3743
}
3844
if(nameStr == null) {
3945
nameStr = name;

Kotlin-Coroutines_1.2/src/main/java/com/newrelic/instrumentation/kotlin/coroutines/NRRunnable.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)